Re: what is the correct for xpath selector for xsi:type

Liam R E Quin <[email protected]>
Newsgroups gmane.text.xml.schema.devel
Message-ID <[email protected]>
On Thu, 2011-12-08 at 17:08 -0800, Andy Davidson wrote:
> Hi
> 
> I am trying use libxml2 to parse the following xml. 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <zoo:cageRequest
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>     xmlns:zoo="http://www.example.org/Zoo"
>     xsi:schemaLocation="http://www.example.org/Zoo ../XSD/ZooRequest.xsd ">
>   <animal xsi:type="zoo:Fish">
>       <name>tuna</name>
>       <numberOfFins>4</numberOfFins>
>   </animal>
> </zoo:cageRequest>
> 
> I need to do some special processing based on the value of xsi:type.

Since libxml is stuck on XPath 1, you can use explicit xsi:type
attributes but not type annotations that result from schema validation
episodes - you'd need an XPath 2 engine for that, such as Saxon.

>   I eventual get a a xmlNodePtr that points to   
> 
> <animal xsi:type="zoo:Fish">
>       <name>tuna</name>
>       <numberOfFins>4</numberOfFins>
>   </animal>
> 
> I can not seem to select the attribute. "@*" works but is not going to work long term.
> 
> "@xsi:type" and "@type" did not work

You need to bind the prefix xsi to the right URI in the namespace
context before evaluating the expression. Google for xpath and
namespaces. Then you can use @xsi:type.

Liam

-- 
Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/
Pictures from old books: http://fromoldbooks.org/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.