This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XPath " Watch "XPath " New topic
Author

XPath

Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
I am newbie to XPath. I have the below file, to parse and retrieve the <jar> under <test> only and ignore <jar> under <subcomponent>. I am using XPath for the same.



The code,


When I retrieve, I am not getting the value. Please someone help me.

Thanks,
Ananth
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Ananth Ram wrote:I am newbie to XPath. I have the below file, to parse and retrieve the <jar> under <test> only and ignore <jar> under <subcomponent>. I am using XPath for the same.

In that case you might want to consider finding out the difference between the "/" and "//" operators in XPath.
When I retrieve, I am not getting the value. Please someone help me.

Could you provide a description of the problem? "Not getting the value" doesn't mean anything when the first line of your post says you are expecting more than one value. So, tell us what you see, what you expected to see, and what the difference is.
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Thanks, I tried both "\\" and "\". When I print on the console, I get to see only null.
But the iterations exactly match the <jar> under <test> only. But, how do I retrieve the value say 3, 4 or 8, 9.

Thanks,
Ananth
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Ananth Ram wrote:Thanks, I tried both "\\" and "\".

Perhaps that's the problem. The backslash doesn't mean anything in XPath. You need slashes.
When I print on the console, I get to see only null.

Just the four characters "n" "u" "l" "l"?
Ananth Ram
Ranch Hand

Joined: Jan 18, 2001
Posts: 99
Yes, the four characters.

null.

Thanks, I am going over the XPath Expressions.
The expressions were not correct.

Able to retrieve the values from the same.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XPath
 
Similar Threads
Parsing XML file using Xpath in jdk1.4
XPath expression constrained by a predicate doesn't work (//element[@attribute="value"])
XPath 2
below code is correct way to write the code in generic way if we receive different xml formats
How to Generalize the code?