Solved

XPATH with Namespace using Dom4j

Posted on 2008-06-11
5
1,413 Views
Last Modified: 2013-11-23
Hi,
I am using dom4j api and trying to evaluate an xpath. It is not working for me when the xml uses namespaces. Could you please let me know what changes should I make?
dom4j version: 1.6




ee-ques.txt
0
Comment
Question by:pattabi23in
  • 4
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 21764098
Your prefixes don't correspond to those defined in the document header - they must
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 21764154
e.g.

>> <m_SessionID>SESSION9</m_SessionID>

has no namespace set
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21764261
After fixing that your session id is returnable (my JDOM works) with the expression below:
 org.jdom.xpath.XPath xpath = org.jdom.xpath.XPath.newInstance("//soap:Header/snp:m_Header/snp:m_SessionID");

Open in new window

0
 

Author Closing Comment

by:pattabi23in
ID: 31466330
crazy thing that I did not notice the missing namespace. Thank you for spotting that. After the fix it worked.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 21769336
:-)
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 39
replace a word with other 1 44
Convert from a json string array to a Java object 3 35
JAVA API design with micro service cloud in mind 1 19
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question