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
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Neal WaltersSubject: Xpath to return xmlns
Author: Neal Walters
Date: 09 Jan 2007 11:00 AM
Is there an xpath to return the xmlns without having to define any namespace?

When I use Stylus to generate xpath I get:
/*[local-name()="MyRoot" and namespace-uri()="http://MyRoot"]/@xmlns:ns0

Can I make this more generic to return whatever the value of xmlns is, regardless of whether it is ns0 or x1? And can I do it without having to define the ns0?

I'd like something like //[prefix=xmlns[1] - in other words give me the value of the first attribute that is found that has a prefix of xmlns.

Is it possible? I'm trying to do this in an MS/SQL2005 xquery.

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

Postnext
(Deleted User) Subject: Xpath to return xmlns
Author: (Deleted User)
Date: 09 Jan 2007 11:32 AM
Hi Neil,
what you want to do is not entirely doable in XPath, because the attributes starting with "xmlns" are not part of the 'attribute::' axis, but belong to the 'namespace::' axis.
So the query you are looking for is /*/namespace::*[1]
But with this caveats:
1) the axis contains all the xmlns:xxx attributes defined on the element AND on all the parent elements, plus the predefined 'xml' namespace
2) the order is implementation defined, so you need to test where SQL2005 places the 'xml' namespace
3) not all XPath 1.0 processors implement this axis, and the ones who did had so many headaches that XPath 2.0 made it deprecated and optional (and XQuery removed it altogether)

Hope this helps,
Alberto

Posttop
Neal WaltersSubject: Xpath to return xmlns
Author: Neal Walters
Date: 09 Jan 2007 11:41 AM
You got me on the right path. I went to SQL2005 help and found their namespace function. I did as follows:

select xmlfield.query('namespace-uri(/*[1])')
from mytable

and I got what I was looking for.

Thanks!!!!!
Neal Walters
http://Biztalk-Training.com

 
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.