Rails 3、XML 格式和生成器
我有一个 xml 标签,需要像这样格式化:
<AddDealRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
我似乎无法使用 builder 使其正常工作。我正在尝试在构建器中执行以下代码:
xml.AddDealRequest(:xmlns:xsi => "http://www.w3.org/2001/XMLSchema-instance", :xmlns:xsd => "http://www.w3.org/2001/XMLSchema" ) do
但显然第二个冒号正在丢弃该符号。有什么办法可以逃脱第二个符号吗?或者这个声明是完全必要的吗?
谢谢!
I have an xml tag that needs to be formatted like so:
<AddDealRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
I can't seem to get this to work properly, using builder. I am attempting the following code in builder:
xml.AddDealRequest(:xmlns:xsi => "http://www.w3.org/2001/XMLSchema-instance", :xmlns:xsd => "http://www.w3.org/2001/XMLSchema" ) do
but obviously that second colon is throwing off the symbol. Is there any way to escape that second symbol? Or is this declaration entirely necessary?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试引用您的符号:
您也可以尝试使用字符串而不是符号,
但我不知道构建器是否对此感到满意,但 文档包含类似这样的内容:
因此属性名称的字符串应该有效。
在 irb 中花一点时间可能有助于澄清一些事情:
Try quoting your symbols:
You could also try using strings instead of symbols
but I don't know if builder will be happy with that but the documentation includes things like this:
so strings for the attribute names should work.
A bit of time in
irb
might be help clarify things:我不会期望任何人阅读最早答案中的所有评论,而是将结果发布在这里:
Firefox 不显示
xmlns
属性(至少不显示)当它与默认值匹配时)。如果您查看源代码 (Ctrl+U) 或使用 Chrome 作为浏览器,您将看到缺少的属性出现在 xml 输出中。Rather than expect anyone to read through all the comments in the earliest answer, I'll just post the outcome here:
Firefox doesn't display the
xmlns
attribute (at least not when it matches a default). If you view the source (Ctrl+U) or use Chrome as your browser, you'll see that the missing attributes are appearing in the xml output.