XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Neal  WaltersSubject: Xpath when namespace present
Author: Neal Walters
Date: 19 Nov 2004 09:06 AM
I have seen other posts where people have discussed how to build
Xpath when the XML contains a namespace such as follows:

<?xml version="1.0" encoding="utf-8"?>
<DocumentProcessingInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.odimo.com/Amazon/MIPService/">
<documentProcessingStatus xmlns="http://www.amazon.com/merchants/merchant-interface/">_DONE_</documentProcessingStatus>
<processingReport xmlns="http://www.amazon.com/merchants/merchant-interface/">
<documentID>1861223</documentID>
<generatedDateTime>2004-11-15T05:51:02.0000000-05:00</generatedDateTime>
</processingReport>
</DocumentProcessingInfo>

I go to tree view, right click, choose "Copy xpath query to clipboard"
and it generates xpath of: /DocumentProcessingInfo/documentProcessingStatus,
which yields 0 hits when I run it.

If I cannot remove the namespace (and cannot add a prefix to it),
how do I build proper Xpath query and why can't Stylus Studio build
query for me? Two of us spent 45 minutes last night working on
this and finally gave up. We tried a few variations using the
"local-name" keyword.

We are using Stylus Studio to help us with our Biztalk 2004 implementation.
Below is a similar post I sent to Microsoft newsgroup. The short xpath is
about 45 characters in length but doesn't work. The correct xpath is
about 150 characters long and very confusing. We would like to use
Stylus Studio to build the Xpath that works.


// Not sure why shorted Xpath does not work here...
//vXpath =
"/ns0:Order/ns0:ShipMethod-15[1]/@ShipMethodID";

vXpath = "/*[local-name()='Order' and
namespace-uri()='http://www.odimo.com/macs/macsorder.xsd']/*[local-name()='ShipMethod-15'
and
namespace-uri()='http://www.odimo.com/macs/macsorder.xsd']/@*[local-name()='ShipMethodID' and namespace-uri()='']";

// Take shipping method from SQL and insert into MACS
xpath(mMACSXml2,vXpath)
=
mSpAmazonOrderShippingResp.OrderShipping.ShipMethod;



Thanks in advance,
Neal Walters
http://Biztalk-Training.com - Free Biztalk Demos




Postnext
(Deleted User) Subject: Re: Xpath when namespace present
Author: (Deleted User)
Date: 23 Nov 2004 01:56 AM
Hi Neal,
thanks for reporting this: Stylus should definitely create the correct
XPath string also when a default namespace is declared midway in the document.

A fix for this will be in the next update of Stylus.

Thanks,
Alberto


Postnext
Neal  WaltersSubject: Re: Xpath when namespace present
Author: Neal Walters
Date: 30 Nov 2004 06:28 PM

Given this XML document:

<?xml version="1.0" encoding="utf-8"?>
<DocumentProcessingInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="TEST">
<documentProcessingStatus>_DONE_</documentProcessingStatus>
<processingReport>
<documentID>1861223</documentID>
<generatedDateTime>2004-11-15T05:51:02.0000000-05:00</generatedDateTime>
</processingReport>
</DocumentProcessingInfo>

Should I be able to build an XPath something like this?
I don't really understand it - but it's more or less the way Biztalk 2004 generates Xpath for its schemas.

/*[local-name()="DocumentProcessingInfo" and namespace-uri()='']/*[local-name()="documentProcessingStatus" and namespace-uri()='']

Stylus Studio finds 0 hits whereas I am hoping to find the documentProcessingStatus node.


Thanks again,
Neal Walters
http://Biztalk-Training.com

Postnext
Ivan PedruzziSubject: Re: Xpath when namespace present
Author: Ivan Pedruzzi
Date: 01 Dec 2004 12:41 AM

Neal,

The XML document is overriding the default namespace (xmlns="TEST")
You need to change yuor Xpath like so

/*[local-name()="DocumentProcessingInfo" and namespace-uri()='TEST']/*[local-name()="documentProcessingStatus" and namespace-uri()='TEST']

Ivan

Postnext
Neal  WaltersSubject: Re: Xpath when namespace present
Author: Neal Walters
Date: 01 Dec 2004 10:31 AM
Thanks, here are some more examples of things that work and don't work:

<TestSchema xmlns="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>
<!--
Works: /*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="A" and namespace-uri()='http://MapTest.TestSchema']
Biztalk Distinigushed field - does not work?: /*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='']"
Works: /*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="A"]
-->

I'm still researching why Biztalk builds an Xpath expression
that ends like this: and namespace-uri()=''

Thanks
Neal Walters


Postnext
Neal  WaltersSubject: Re: Xpath when namespace present
Author: Neal Walters
Date: 01 Dec 2004 12:29 PM
Here are my findings and examples:

Sample 1 – Simple Data with no namespace issues

<TestSchema>
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>

XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue
/TestSchema/CGroup/CChild1 CChild1Value



Sample 2 – Simple Data with prefixed namespace
NOTE: When you generate test xml data from a Biztalk schema, it generates it as follows with the “ns0” prefix used on the namespace.

<ns0:TestSchema xmlns:ns0="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</ns0:TestSchema>

XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/A AValue
/ns0:TestSchema/B BValue
/ns0:TestSchema/CGroup/CChild1 CChild1Value
Biztalk Distinguished Field have xpath like this:

/*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='']

NOTE: this can easily be abbreviated to the simpler syntax shown in the second XPATH example above. BValue



Sample 3 – Simple Data with non-prefixed namespace
This is a common problem when schemas have a default namespace and no prefix is used.

<TestSchema xmlns="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>

XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
NOTE: When accessing children nodes, the namespace-uri() can be omitted:

/*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="A"] AValue
/*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="B" and namespace-uri()='http://MapTest.TestSchema'] BValue
/*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="CGroup" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="CChild1" and namespace-uri()='http://MapTest.TestSchema'] CChild1Value



Sample 4 – Prefixed Namespace (not prefixed elements)
One quick solution to using complicated Xpath names is to put a prefix on the namespace. The namespace is no longer the “default namespace” and now only applies to element specifically prefixed with ns0.

<TestSchema xmlns:ns0="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>


XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue




Sample 5 – Obscure Sample
This shows how you could have two namespaces with different prefixes, and use the namespace-uri() keyword instead of the namespace prefix.

<ns0:TestSchema xmlns:ns0="http://MapTest.TestSchema" xmlns:x="testx">
<A>AValue</A>
<x:B>BValue</x:B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</ns0:TestSchema>
<!--
Works: /ns0:TestSchema/x:B
Works: /*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx']
-->


XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/x:B BValue
/*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx'] BValue


Neal Walters
http://Biztalk-Training.com - Free Training Videos



Postnext
Neal  WaltersSubject: Re: Xpath when namespace present
Author: Neal Walters
Date: 01 Dec 2004 01:45 PM
Here are my findings and examples:

Sample 1 – Simple Data with no namespace issues

<TestSchema>
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>

XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue
/TestSchema/CGroup/CChild1 CChild1Value



Sample 2 – Simple Data with prefixed namespace
NOTE: When you generate test xml data from a Biztalk schema, it generates it as follows with the “ns0” prefix used on the namespace.

<ns0:TestSchema xmlns:ns0="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</ns0:TestSchema>

XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/A AValue
/ns0:TestSchema/B BValue
/ns0:TestSchema/CGroup/CChild1 CChild1Value
Biztalk Distinguished Field have xpath like this:

/*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='']

NOTE: this can easily be abbreviated to the simpler syntax shown in the second XPATH example above. BValue



Sample 3 – Simple Data with non-prefixed namespace
This is a common problem when schemas have a default namespace and no prefix is used.

<TestSchema xmlns="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>

XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
NOTE: When accessing children nodes, the namespace-uri() can be omitted:

/*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="A"] AValue
/*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="B" and namespace-uri()='http://MapTest.TestSchema'] BValue
/*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="CGroup" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="CChild1" and namespace-uri()='http://MapTest.TestSchema'] CChild1Value



Sample 4 – Prefixed Namespace (not prefixed elements)
One quick solution to using complicated Xpath names is to put a prefix on the namespace. The namespace is no longer the “default namespace” and now only applies to element specifically prefixed with ns0.

<TestSchema xmlns:ns0="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>


XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue




Sample 5 – Obscure Sample
This shows how you could have two namespaces with different prefixes, and use the namespace-uri() keyword instead of the namespace prefix.

<ns0:TestSchema xmlns:ns0="http://MapTest.TestSchema" xmlns:x="testx">
<A>AValue</A>
<x:B>BValue</x:B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</ns0:TestSchema>
<!--
Works: /ns0:TestSchema/x:B
Works: /*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx']
-->


XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/x:B BValue
/*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx'] BValue


Neal Walters
http://Biztalk-Training.com - Free Training Videos



Posttop
Neal  WaltersSubject: Re: Xpath when namespace present
Author: Neal Walters
Date: 01 Dec 2004 02:25 PM
Here are my findings and examples:

Sample 1 – Simple Data with no namespace issues

<TestSchema>
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>

XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue
/TestSchema/CGroup/CChild1 CChild1Value



Sample 2 – Simple Data with prefixed namespace
NOTE: When you generate test xml data from a Biztalk schema, it generates it as follows with the “ns0” prefix used on the namespace.

<ns0:TestSchema xmlns:ns0="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</ns0:TestSchema>

XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/A AValue
/ns0:TestSchema/B BValue
/ns0:TestSchema/CGroup/CChild1 CChild1Value
Biztalk Distinguished Field have xpath like this:

/*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='']

NOTE: this can easily be abbreviated to the simpler syntax shown in the second XPATH example above. BValue



Sample 3 – Simple Data with non-prefixed namespace
This is a common problem when schemas have a default namespace and no prefix is used.

<TestSchema xmlns="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>

XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
NOTE: When accessing children nodes, the namespace-uri() can be omitted:

/*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="A"] AValue
/*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="B" and namespace-uri()='http://MapTest.TestSchema'] BValue
/*[local-name()="TestSchema" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="CGroup" and namespace-uri()='http://MapTest.TestSchema']/*[local-name()="CChild1" and namespace-uri()='http://MapTest.TestSchema'] CChild1Value



Sample 4 – Prefixed Namespace (not prefixed elements)
One quick solution to using complicated Xpath names is to put a prefix on the namespace. The namespace is no longer the “default namespace” and now only applies to element specifically prefixed with ns0.

<TestSchema xmlns:ns0="http://MapTest.TestSchema">
<A>AValue</A>
<B>BValue</B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</TestSchema>


XPATH Result
/TestSchema/A AValue
/TestSchema/B BValue




Sample 5 – Obscure Sample
This shows how you could have two namespaces with different prefixes, and use the namespace-uri() keyword instead of the namespace prefix.

<ns0:TestSchema xmlns:ns0="http://MapTest.TestSchema" xmlns:x="testx">
<A>AValue</A>
<x:B>BValue</x:B>
<CGroup>
<CChild1>CChild1Value</CChild1>
<CChild2>CChild2Value</CChild2>
</CGroup>
</ns0:TestSchema>
<!--
Works: /ns0:TestSchema/x:B
Works: /*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx']
-->


XPATH Result
/TestSchema/A NO MATCHES
/TestSchema/B NO MATCHES
/ns0:TestSchema/x:B BValue
/*[local-name()='TestSchema' and namespace-uri()='http://MapTest.TestSchema']/*[local-name()='B' and namespace-uri()='testx'] BValue


Neal Walters
http://Biztalk-Training.com - Free Training Videos



 
Topic Page 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.