1

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

Community
  • 1
  • 1
Pintac
  • 1,565
  • 3
  • 21
  • 38
  • 1
    Your **relative** XPath expression is fine as long as context node is document root. You could use also this absolute expression: `/config:Manifest/config:Text[@config:name='siteowner']`. If this result in a empty node set, do check if your namespace URI binding is correct. –  Dec 03 '10 at 15:22

2 Answers2

4

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

Community
  • 1
  • 1
nukeuser
  • 56
  • 2
0

Not a 100% sure but I believe you need a token in front of you xpath statement:

I would try the following:

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

And if that doesn't work try this:

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

And if neither of those work try this:

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