This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes reading web.xml by XPATH Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "reading web.xml by XPATH" Watch "reading web.xml by XPATH" New topic
Author

reading web.xml by XPATH

Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 477

Hi Guys ,

i'm new to XPATH , i'm trying to read a copy of the web.xml named testweb.xml , but i didnt get any results , only the program prints "for done " and nothing else , here is my code


anything i;m missing ?


Thanks,
Sherif
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 459
    
    1
Hi Sherif,

Please correct your subject. I think you wanted to write web.xml.

Further below XPathExpression does not seems to be right..



Please go through this for clarity on XPATH.


Vinod Tiwari | Twitter
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 477

Vinod Tiwari wrote:Hi Sherif,

Please correct your subject. I think you wanted to write web.xml.

Further below XPathExpression does not seems to be right..



Please go through this for clarity on XPATH.


Hi , i cant find anything wrong ...
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

All that means is that the XPath expression you chose doesn't select any nodes from the document. One would have to look at the document to see why not. And right now, you're the only one who can do that. We can't see it from here.
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 477

Paul Clapham wrote:All that means is that the XPath expression you chose doesn't select any nodes from the document. One would have to look at the document to see why not. And right now, you're the only one who can do that. We can't see it from here.


Sorry You are right Paul , i forget to post the web.xml file , here is the part that i wanna get from the xml file
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

Clearly your first error is that the XPath expression is looking for a "wep-app" element as the root, whereas the root of that document is a "web-app" element.

But you're going to come back and tell me that was just a typing error when you made the post, the actual code does say "web-app". Then your problem is that all of your document is in the default namespace, whereas an XPath expression specifying an element name with no prefix is looking for elements with no namespace.

You can fix that by creating a namespace context which assigns the prefix "x" to the namespace URI "http://java.sun.com/xml/ns/javaee", and assigning that namespace context to your XPath object. Then change the XPath expression to "/x:web-app/x:context-param/x:param-name".
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 477

Yhanks for your fast reply , do you mean putting this and it will be like this then the XPATh expression object will be like this

Am i right ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18168
    
    8

No.

If I was going to suggest changing the XML document, I would have suggested just getting rid of the default namespace declaration. But I didn't suggest changing the XML document at all, because for all I know changing it would break something. What gave you that idea?
Vinod Tiwari
Ranch Hand

Joined: Feb 06, 2008
Posts: 459
    
    1
Your xpath should be something like where i=1,2,...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: reading web.xml by XPATH
 
Similar Threads
Parsing String which comes as xml
Count the no of a particular element in xml file
parsing doubt
Deleting the children from node - xml
DTD Validation problem via Sax