This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XPath problem: can't resolve path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPath problem: can Watch "XPath problem: can New topic

XPath problem: can't resolve path

Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178

I'm working at a project using XML processing for building a conventional web application. The processing ensures that application properties are set depending on the target stage. Basically there's a properties template file and an instruction file, the template file is processed with the instructions.

Unfortenately I do have a problem processing the template for a web.xml file. First the instructions:

As you can see it reads the template for a web.xml file, determines an output file followed by an instruction to delete an element for stage p(roduction).

The template file:

The build process works fine using the given files.

Now I wanted to update the web.xml template to a higher JSP spec, so I changed the file as follows:

The rest is identical code, the only changed lines are at top of the file. Now the build fails with an error:


--- Nested Exception --- Unable to resolve xpath //web-app/servlet[servlet-name='ServletRedirector'] in document ipad-aip_web_template.cfg

Why can't the xpath be resolved? In my understanding nothing changed in the files structure itself. Or am I missing the obvious?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I wouldn't say "obvious" but in the second example your web-app element is in the default namespace and in the first example it isn't in any namespace, right?
Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178
Okay, I hit a namespace problem here and read up a little bit on this. So far I have the following:

//*[local-name()="web-app" and namespace-uri()=""]/*[local-name()="servlet" and namespace-uri()=""]



Of course the restriction "sub-element" servlet-name=ServletRedirector is still missing, I have a hard time to express this in a way like my example above. I know that I can next predicates, I just can't figure out how.
I agree. Here's the link:
subject: XPath problem: can't resolve path
It's not a secret anymore!