[xml] question on xml validtion and xpath



Hi,

 

I’m trying to validate my XML file against XSchema that is linked inline to such file.

XML file has elements with default namespace, without prefix, to which XSchema documents links to, enabling it to do its validation work.

 

Validation goes ok. Next thing I tried is using Xpath _expression_ to select something using absolute path from my XML file and XPath returned no results.

 

Sample XML file:

 

<?xml version="1.0" encoding="utf-8" ?>

<TU xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com config.xsd"> 

            <Model Name="Models">

                       

            </Model>                   

</TU>

 

Associated XML Schema:

 

<?xml version="1.0" ?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com">

            <xs:element name="TU">

            // validation rules here…

</xs:element>

</xs:schema>

 

 

Question: My Xpath Inquiry:

 

/TU/Model

 

returns no results – why is this and how can I make it so that both Xpath would correctly return such node selection, as well as XSchema would be able to validate the same document?

 

If I define XML file with namespace prefix:

 

<?xml version="1.0" encoding="utf-8" ?>

<TU xmlns:MyNS="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com config.xsd"> 

            <Model Name="Models">

                       

            </Model>                   

</TU>

 

Then XPath selection works fine, but my validation fails – how can I make this work?

 

Any help would be very appreciated.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]