Javascript E4X:根据属性值选择节点
考虑以下场景:
使用 Javascript/E4X,在非浏览器使用场景(Javascript HL7 集成引擎)中,有一个变量保存可能具有多个重复节点的 XML 片段。
<pets>
<pet type="dog">Barney</pet>
<pet type="cat">Socks</pet>
</pets>
代码:
var petsXml; // pretend it holds the above xml value
//var cat = petsXml['pet']..... ?
问题:使用E4X,如何选择type
属性包含字符串“cat”值的正确宠物节点?
更新:
使用 E4X 的一些学习:
- 通过属性值选择单个/第一个节点:
vardog = petsXml.(@type == "dog");
- 获取来自一个节点的特定属性的值:
var petType = somePetNode.@type;
Consider this scenario:
Using Javascript/E4X, in a non-browser usage scenario (a Javascript HL7 integration engine), there is a variable holding an XML snippet that could have multiple repeating nodes.
<pets>
<pet type="dog">Barney</pet>
<pet type="cat">Socks</pet>
</pets>
Code:
var petsXml; // pretend it holds the above xml value
//var cat = petsXml['pet']..... ?
Question: using E4X, how can you select the correct pet node with the type
attribute holding the value of string 'cat'?
Update:
Some learnings with E4X:
- to select a single/first node by an attribute value:
var dog = petsXml.(@type == "dog");
- to get a value from one node's specific attribute:
var petType = somePetNode.@type;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅此处的“过滤器”或此处。
See "Filters" here or "parameterized locate" over here.