Jump to content

xquery and namespaces


Guest Kashmulik
 Share

Recommended Posts

Guest Kashmulik

Hi,I use xquery in order to retrieve some data from an xml file. The xml I get has the following structure:

<a>  <b xmlns:"someNamespace">	<c>val1</c>	<d>val2</d>	<e>	  <f>val3</f>	  <g>val4</g>	</e>  </b>  <b xmlns:"someNamespace">  .  .	  .  </b>..	.</a>

The problem is, that all of the nodes that I want to retrieve their data have the same namespace ("someNamespace") but I don't want to write it any time I address some node. Unfortunately I can't declare a global namespace because the root node "a" is not in the namespace...Does anyone have a solution to my problem?thnx

Link to comment
Share on other sites

Can't you declare a default namespace for all nodes inside "/*"? I would have thought XQuery would allow you to do something like that. If not, then there must be a way with which in XQuery, you can designate a prefix (say "s" for example) that will have the namespace URI "someNamespace". When you do your query, you'll just have to reference the prefix all the time, like

s:b/s:c

If you really want to match those elements regardless of their namespace URI, you can use something like

*[local-name() = 'b']/*[local-name() = 'c']

but if you ask me, that's even uglyer.BTW, your XML is not well formed. It should be

xmlns="someNamespace"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...