Only 48 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Xpath with name space?  RSS feed

 
John Landon
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have the following xml:


I need to access to the "def1" node. The xpath abc/def1 is not right. What should I include in side the xpath for the namespace?

Thanks,
John.
 
Paul Clapham
Sheriff
Posts: 22185
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In plain XPath there isn't any way to refer to elements in the default namespace. But if you have a way of providing a namespace context to your XPath expression, then do this:

(1) Provide a namespace context that maps your namespace URI ("abc123" in this case) to a prefix, let's say "x" for example.

(2) Write your XPath expression as "x:abc/x:def1".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!