Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: still problems with XPath and namespaces...

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 1/3/2005 6:45:00 PM

Stefan Franke wrote:


> The XML I'm using looks like this:
> 
> <SAMMLUNG
>    xmlns:buch="http://www.example.com/buecher"
>    xmlns:cd="http://www.example.com/cds">
> 
>    <buch:ARTIKEL Status="vorhanden">
>       <buch:TITEL>The Marble Faun</buch:TITEL>
>       <buch:AUTOR>Nathaniel Hawthorne</buch:AUTOR>
>       <buch:PREIS>10.95</buch:PREIS>
>    </buch:ARTIKEL>
>    <cd:ARTIKEL>
>       <cd:TITEL>Violinkonzerte 1, 2 und 3</cd:TITEL>
>       <cd:KOMPONIST>Mozart</cd:KOMPONIST>
>       <cd:PREIS>16.49</cd:PREIS>
>    </cd:ARTIKEL>
> </SAMMLUNG>
> 
> 
> If I want to display e.g. all the CDs of Mozart, I would do something like 
> this if I wouldn't have to deal with namespaces:
> 
> string(//*/TITEL[following-sibling::KOMPONIST='Mozart'])

Not really, if you apply the string function to a nodeset then you get 
the string value of the first node in document order so the above 
doesn't give you all CD titles but only one.

> My suggestion when dealing with namespaces would be something like this (but 
> it doesn't work, as there is no TITEL-element anywhere, but I don't know how 
> to get it in there):
> 
> string(//*[local-name()='ARTIKEL' and 
> namespace-uri()='http://www.example.com/cds']/*[string(local-name()='KOMPONIST') 
> = 'Mozart'])

How are you evaluating your XPaths? You should simply be able to declare 
prefixes for the namespaces and then use e.g.
   //prefix:TITLE
instead of going to the pain of using namespace-uri comparisons.
So I think you should better tell us about the software you are using to 
evaluate XPaths and then probably someone can tell you how to use 
namespace prefixes bound to namespaces when evaluating XPath expressions.

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent