Subject: XPATH: Retrieve Value without namespace prefixes
Posted By: ramesh.kumarm Post Date: 9/14/2006 1:17:59 AM
Hello everyone,
Kindly help me in solving this issue.
This is the XML file
<test:New_Service_Request xmlns:test="http://test.com">
  <test:Message_Type>abcdef</test:Message_Type>
  <test:Message_Source>FlowStream</test:Message_Source>
  <test:Message_Id>800043660</test:Message_Id>
</test:New_Service_Request>


Need XPATH to retrieve the value 'abcdef' without giving the namespace. I mean normally we give //*/test:MessageType in value-of to retieve it. But now these messages change dynamically.
So the namespace changes too. Hence one can't rely on the namespace to retrieve this info.

My Question: Is there by any means by omitting this namespace we could do a xpath to retrieve 'abcdef'?
PLZ PLZ help......in a very urgent sutation.

THANX A LOT!

ramesh.

Reply By: mhkay Reply Date: 9/14/2006 2:39:51 AM
Saying that you want to retrieve an element called Message_Source without knowing what namespace it's in is a bit like saying you want to go to London but you're not sure whether it's London, Ontario or London, England. It suggests there's something very fishy in the way you are using namespaces.

However, you can do it. In XPath 2.0 you can do select="*:Message_Source", in 1.0 you can do select=*[local-name()='Message_Source]". It may not be especially efficient.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply By: ramesh.kumarm Reply Date: 9/14/2006 3:21:35 AM
Thanx for your prompt reply Michael.
But i need to extract the value of the Message_Source and the not Message_Source string. If i wanted to extract the word Message_Source, then i might have used local-name(*/*[2])
Unfortunately i need the value it holds. 'abcdef' is what i need.
Do you have any suggestions on this.
thanx a lot.

ramesh

Reply By: ramesh.kumarm Reply Date: 9/14/2006 3:37:56 AM
Hey Michael, you know what - i got through with this.

//*/*[local-name()='Message_Source']

Anyway, thanx a lot for your help Mike.

ramesh

Reply By: mhkay Reply Date: 9/14/2006 3:50:36 AM
Using select=*[local-name()='Message_Source']" as I suggested will select the Message_Source node (assuming you are currently at its parent). You can then extract the string value of the node in the normal way.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference

Go to topic 49580

Return to index page 175
Return to index page 174
Return to index page 173
Return to index page 172
Return to index page 171
Return to index page 170
Return to index page 169
Return to index page 168
Return to index page 167
Return to index page 166