xQuery XMLNodes 集合中的单个 XMLNode
我有一个 XML 文件,其中包含名为 Standplaatsen
的节点。 我可以获得这些节点的集合。然后我想使用 foreach 循环将其钻取到该集合中,并检查节点集合中的每个单独的节点。
foreach (XmlNode XMLNode in XMLNodes)
{
//This will be found nicely
string test1 = XMLNode["bag_LVC:identificatie"].InnerXml.ToString();
//This will cause a NULL reference with or without a leading '//'
string test2 = XMLNode["bag_LVC:gerelateerdeAdressen/bag_LVC:hoofdadres/bag_LVC:identificatie"].InnerXml.ToString();
// This will get the element BUT it will only get the same
// first element whatever node is procesed
string xPathExpression = "//bag_LVC:gerelateerdeAdressen/bag_LVC:hoofdadres/bag_LVC:identificatie";
XmlElement Hoofdadres = (XmlElement)XMLNode.SelectSingleNode(xPathExpression, ns);
}
有谁知道如何获取每个节点的 hoofdadres\identificatie
元素的正确值。
示例 XML:
<xb:antwoord>
<xb:producten>
<product_LVC:LVC-product>
<bag_LVC:Standplaats>
<bag_LVC:gerelateerdeAdressen>
<bag_LVC:hoofdadres>
<bag_LVC:identificatie>1883200000020771</bag_LVC:identificatie>
</bag_LVC:hoofdadres>
</bag_LVC:gerelateerdeAdressen>
<bag_LVC:identificatie>1883030000000010</bag_LVC:identificatie>
</bag_LVC:Standplaats>
<bag_LVC:Standplaats>
<bag_LVC:gerelateerdeAdressen>
<bag_LVC:hoofdadres>
<bag_LVC:identificatie>1883200000015663</bag_LVC:identificatie>
</bag_LVC:hoofdadres>
</bag_LVC:gerelateerdeAdressen>
<bag_LVC:identificatie>1883030000000011</bag_LVC:identificatie>
</bag_LVC:Standplaats>
</product_LVC:LVC-product>
</xb:producten>
</xb:antwoord>
更新
当我使用 //*:hoofdadres/*:identificatie
时,我遇到了异常
//*:hoofdadres/*:identificatie' has an invalid token.
这是困扰我的部分:
// This will get the element BUT it will only get the same
// first element whatever node is processed
string xPathExpression = "//bag_LVC:gerelateerdeAdressen/bag_LVC:hoofdadres/bag_LVC:identificatie";
XmlElement Hoofdadres = (XmlElement)XMLNode.SelectSingleNode(xPathExpression, ns);
I have a XML file that contains node named Standplaatsen
.
I can get a collection of these nodes. Then I want to drill it into this collection with a foreach
loop and check each seperate nodes within the node collection.
foreach (XmlNode XMLNode in XMLNodes)
{
//This will be found nicely
string test1 = XMLNode["bag_LVC:identificatie"].InnerXml.ToString();
//This will cause a NULL reference with or without a leading '//'
string test2 = XMLNode["bag_LVC:gerelateerdeAdressen/bag_LVC:hoofdadres/bag_LVC:identificatie"].InnerXml.ToString();
// This will get the element BUT it will only get the same
// first element whatever node is procesed
string xPathExpression = "//bag_LVC:gerelateerdeAdressen/bag_LVC:hoofdadres/bag_LVC:identificatie";
XmlElement Hoofdadres = (XmlElement)XMLNode.SelectSingleNode(xPathExpression, ns);
}
Does anyone know how to get the correct value of the hoofdadres\identificatie
element of each node.
Example XML:
<xb:antwoord>
<xb:producten>
<product_LVC:LVC-product>
<bag_LVC:Standplaats>
<bag_LVC:gerelateerdeAdressen>
<bag_LVC:hoofdadres>
<bag_LVC:identificatie>1883200000020771</bag_LVC:identificatie>
</bag_LVC:hoofdadres>
</bag_LVC:gerelateerdeAdressen>
<bag_LVC:identificatie>1883030000000010</bag_LVC:identificatie>
</bag_LVC:Standplaats>
<bag_LVC:Standplaats>
<bag_LVC:gerelateerdeAdressen>
<bag_LVC:hoofdadres>
<bag_LVC:identificatie>1883200000015663</bag_LVC:identificatie>
</bag_LVC:hoofdadres>
</bag_LVC:gerelateerdeAdressen>
<bag_LVC:identificatie>1883030000000011</bag_LVC:identificatie>
</bag_LVC:Standplaats>
</product_LVC:LVC-product>
</xb:producten>
</xb:antwoord>
Update
When I use //*:hoofdadres/*:identificatie
then I got an exception
//*:hoofdadres/*:identificatie' has an invalid token.
It's the part that troubles me:
// This will get the element BUT it will only get the same
// first element whatever node is processed
string xPathExpression = "//bag_LVC:gerelateerdeAdressen/bag_LVC:hoofdadres/bag_LVC:identificatie";
XmlElement Hoofdadres = (XmlElement)XMLNode.SelectSingleNode(xPathExpression, ns);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在纯 xquery 中:
in pure xquery: