W3C home > Mailing lists > Public > xmlschema-dev@w3.org > December 2011

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

From: Liam R E Quin <liam@holoweb.net>
Date: Thu, 08 Dec 2011 21:58:46 -0500
To: Andy Davidson <andy_davidson@apple.com>
Cc: xmlschema-dev@w3.org
Message-ID: <1323399526.11397.563.camel@localhost.localdomain>
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/
Received on Friday, 9 December 2011 03:00:24 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:19 UTC