xQuery XMLNodes 集合中的单个 XMLNode

发布于 2024-11-28 01:47:01 字数 2420 浏览 0 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

非要怀念 2024-12-05 01:47:01

在纯 xquery 中:

doc()//\*:hoofdadres/\*:identificatie

in pure xquery:

doc()//\*:hoofdadres/\*:identificatie
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文