Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reading web.xml by XPATH

 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Vinod Tiwari
Ranch Hand
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21137
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 466
1
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your xpath should be something like where i=1,2,...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic