E4X:解析具有命名空间节点和要评估的变量的文档?
我正在尝试解析具有如下所示节点的文档:
<doc>
<results>
<result xmlns="http://www.inktomi.com/">
<title>Senate Panel to Review Election Unit Sale</title>
</result>
</result>
</doc>
但是结果的名称空间和节点名可能不同。如果不是这样,这会起作用:
results..*::title //>Senate Panel to ...
但这样做不行:
var myvar = "title"
results..*::[myvar]
有任何线索吗?
I am trying to parse a document with nodes that look something like this:
<doc>
<results>
<result xmlns="http://www.inktomi.com/">
<title>Senate Panel to Review Election Unit Sale</title>
</result>
</result>
</doc>
However the namespace and the nodename of the result could be different. If it were not so, this would work:
results..*::title //>Senate Panel to ...
but doing this doesnt:
var myvar = "title"
results..*::[myvar]
any clues?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
所以正确的解决方案显然是:
感谢 Twitter 上的 @xtyler 找到了答案
So the correct solution apparently is:
Thanks to @xtyler on Twitter for finding the answer
显然,访问子级的方括号方式和使用 * 选择任何命名空间不能一起工作
VerifyError 类表示当 SWF 格式错误或损坏时发生的错误遇到文件。
Apparently the square bracket way of accessing children and use of * to select any namespace doesn't work together
The VerifyError class represents an error that occurs when a malformed or corrupted SWF file is encountered.
不是 E4X 解决方案,但您可以迭代 xml.namespaceDeclarations() 返回的所有可用命名空间,然后获取第一个子级或使用方括号来访问它。
您也可以只预先解析 xml 并使所有名称空间相同作为快速修复。
Not an E4X solution, but you could iterate through all available namespaces returned by xml.namespaceDeclarations() then either get the first child or use square brackets to access it.
You could also just pre-parse the xml and make all the namespaces the same as a quick fix.