使用带有混合命名空间的 E4X 获取第一个节点?
考虑一个带有一些命名空间的 XML 片段:
<meal xmlns="urn:hl7-org:v3">
<veg id="7" />
<lunch id="123">
<veg id="990" />
</lunch>
<dinner id="324">
<veg id="111" />
</dinner>
</meal>
使用 JavaScript E4X,如何显式选择第一个 veg
节点的 id 属性?
显式包含所有命名空间也很重要。这就是我使用下面的 ..*::
语法的原因。我意识到我在这里使用了错误的运算符。
我已经尝试过这个,不幸的是它获取了所有 veg 节点 id 值:
var veg = meal..*::[email protected]()
//currently gets 7990111
How can I get the value of 7
?
Consider an XML snippet with a handful of namespaces:
<meal xmlns="urn:hl7-org:v3">
<veg id="7" />
<lunch id="123">
<veg id="990" />
</lunch>
<dinner id="324">
<veg id="111" />
</dinner>
</meal>
Using JavaScript E4X, how can you explicitly select the first veg
node's id property?
It's important to explicitly include all namespaces as well. This is the reason for my ..*::
syntax below. I realize I'm using the wrong operator here.
I've tried this, which unfortunately gets ALL veg node id values:
var veg = meal..*::[email protected]()
//currently gets 7990111
How can I get the value of 7
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
var veg = 餐..*::veg[0].@id
。var veg = meal..*::veg[0].@id
.试试这个:
var veg = 餐..*::veg[position()=1][ email protected]()
veg[position()=1]
告诉 XPath 您希望 veg 节点位于第一个位置。我刚刚完成你最初的 xpath 表达式。
Try this :
var veg = meal..*::veg[position()=1][email protected]()
veg[position()=1]
tells XPath you want the veg node at the first position.I just complete your initial xpath expression.