JAXP XPathFactory Namespaces
I am trying to retrieve one node from a xml doc in android(java).
<?xml version="1.0" encoding="utf-8" ?> <config:Manifest xmlns:config="http://leaflabs.com/manifest.config.xsd"> <config:Text config:name="siteowner" config:desc="Site owner" config:transform="title"/> <config:Text config:name="siteowner1" config:desc="Site owner" config:transform="title"/> </config:Manifest>
I am using JAXP XPathFactory. The problem i am getting is get null back everytime.
I made sure my xpath was correct made sure my document builder NamespaceAware is set to true and i even followed a Example (at the bottom of page) that implement the NamespaceContext but i still get nothing.
I looked at a stackoverflow Post but nobody answered the guy Link
What am i doing wrong
The issue in your code is the factory is not namespace aware. There is another thread that resolves this problem, How to use XPath on xml docs having default namespace
Suggest you try something like this,
XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(new MyNamespaceContext());