aspose file tools*
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
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPath problem: can Watch "XPath problem: can New topic
Author

XPath problem: can't resolve path

Mike Himstead
Ranch Hand

Joined: Apr 12, 2006
Posts: 178
Hi,

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 ---
de.my.ipad.antsupport.transformer.IllegalInstructionException: Unable to resolve xpath //web-app/servlet[servlet-name='ServletRedirector'] in document ipad-aip_web_template.cfg
at de.my.ipad.antsupport.transformer.XmlFileTransformer.excuteXmlDelete(XmlFileTransformer.java:114)
at de.my.ipad.antsupport.transformer.XmlFileTransformer.transformXml(XmlFileTransformer.java:86)
at de.my.ipad.antsupport.transformer.XmlFileTransformer.transform(XmlFileTransformer.java:174)
at de.my.ipad.antsupport.ui.IpadConfTask.execute(IpadConfTask.java:34)
...

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
Bartender

Joined: Oct 14, 2005
Posts: 18901
    
    8

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()="http://java.sun.com/xml/ns/j2ee"]/*[local-name()="servlet" and namespace-uri()="http://java.sun.com/xml/ns/j2ee"]

or

//*[local-name()="web-app"][namespace-uri()="http://java.sun.com/xml/ns/j2ee"]/*[local-name()="servlet"][namespace-uri()="http://java.sun.com/xml/ns/j2ee"]

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: XPath problem: can't resolve path