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>

XPATH

config:Manifest/config:Text[@config:name='siteowner']

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

Answers


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());

Cheers!

nukeuser


Need Your Help

Storing file permissions in Subversion repository

windows svn file-permissions

How do you store file permissions in a repository? A few files need to be read-only to stop a third party program from trashing it but after checking out of the repository they are set to read-writ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.