Problem running xpath query with namespaces -


I use an xpath expression, trying to select node-set in an XML document with different namespaces I am here.

XML looks like this:

   & Lt; OrderNo & gt; 20090811 & lt; / OrderNo & gt; & Lt; Status & gt; 0 & lt; / Status & gt; & Lt; / Header & gt; & Lt; Lines & gt; ...  

I just want to select "message" -node, in which "orderstatus" is a child and therefore I want to use the following xpath expression: / message [count ( 'Orderstats') & gt; 0] but it will not work when I get an error message: "Namespace Manager or XsltContext is required. This query contains a prefix, variable, or user defined function".

So I think I want to use an expression that looks like this: / * [local-name (=) 'message'] [count ('orderstats') & Gt; 0] But this does not seem to work. Any ideas?

BR,

Andreas

< / Blockquote>
  / message [count ('orderstats') [0]  

but it will not work since I get an error message : "Namespace Manager or XsltContext is required.

This is a frequently asked question.

An unused name in an XP is not always considered as "a name space".

However, to select the element you want, actually in "http://www.noventus.se/epix1/genericheader.xsd" namespace Are there.

You have two possible ways to write your XPath expression :

  1. The hosting language to associate the prefixes with all the different namespaces Use the features of which have names from expressions. You have not indicated what hosting is a minor in this concrete case, so I can not help you with this. A C # example can be found
< P> If you've added the prefix "xxx" to the namespace "http://www.noventus.se/epix1/genericheader.xsd" and the alias "Yyy" at the place name of "http://www.noventus.se/epix1/orderstatus.xsd" , then your expression can be written as:

/ xxx: message [yyy: orderstatus]

: 2: if you come If you do not want to use any prefix at all, XPath expression can still be prepared, though it will not be even readable:

/ * [local-name () = 'message

Finally, note :

  1. [local-name () = 'order-status']

    To check that an element is x a child y , it is necessary to test for a positive count (y) is not. Use : x [y]

  2. Expath state is 1-based This means that the nodextexpress [0] never selects the node you want: nodeet encryption [1]


Comments