Mittwoch, 16. Februar 2011

xmlnamespace without prefix

Regarding the following XML, the XPath-Expression "//title" will only return the second title node.

The reason is the Namespace "withoutPrefix" which is defined without any Prefix, applying to all "nacked" nodes.

To retrieve the first title node, a "default" Prefix has to be added to the Namespacemanger.

Add the defined Prefix to your xPath-Expression and you 'll get the node.


<rootnode>
  <firstnode  xmlns="withoutPrefix" xmlns:inf="withPrefix">
    <title>the first title</title>
    <inf:type>nonsense</inf:type>
  </firstnode>
  <secondnode  xmlns:inf="withPrefix">
    <title>the second title</title>
    <inf:type>crap</inf:type>
  </secondnode>
</rootnode>


nsmgr.AddNamespace("default", "withoutPrefix");

string xPath = "//default:title");

1 Kommentar:

  1. Ich denke, du kannst ein Video für Tiktok dazu machen. Ich rate dir, Tiktok Likes kaufen für dein Video, um es zu promoten

    AntwortenLöschen