I am using XPath in Java under Eclipse. I am writing a soap web service, the XML is using prefix and a namespace and I wanted to remove the prefix and only keep the namespace because I prefer a more readable looking XML document.
When I removed the prefixes from XML definition file and tried to query the XML with XPath I started to get null for every node in the XML!
My question is do I have to use a prefix if I want to use XPath? isn't just namespace is enough?
<myrequest
xmlns="http://www.mywebsite.com/xml/webservice"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mywebsite.com/xml/webservice Request.xsd">
<state>
<value>demox</value>
this is how my XML starts and when I query this with XPath like XPath.selectSingleNode()
I always receive null from the XPath for every node in it.
String myExpression = "myrequest/state/value";
Document doc = new Document(requestXML);
Element e = doc.getRootElement();
request.setMybase(getBase((org.jdom.Element)
XPath.selectSingleNode(doc,myExpression)));