File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes get Element value using another element 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 "get Element value using another element" Watch "get Element value using another element" New topic
Author

get Element value using another element

Kathiresan Chinna
Ranch Hand

Joined: Aug 17, 2008
Posts: 115
Hi there,

I have the XML data like

<databases>
<database>
<user-name>db-user1</user-name>
<password>db-passwd1</password>
</database>

<database>
<user-name>db-user2</user-name>
<password>db-passwd2</password>
</database>
</databases>

I have to get the string "db-passwd2" using "db-user2"
I do not want to write the code for iterate all the element and get this.
Can anyone tell is there any builtin function availbale for this ?

Thanks
Kathiresan

Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

The "built-in" function you are thinking of is for you to write and execute an XPath expression which finds the node you want.
Kathiresan Chinna
Ranch Hand

Joined: Aug 17, 2008
Posts: 115
Hi,

I am not familiar with XPath expression.
Can you simply tell how to get started or links ?

Thank you
Kathir
Kathiresan Chinna
Ranch Hand

Joined: Aug 17, 2008
Posts: 115

Hi,

I found one here

http://www.ibm.com/developerworks/library/x-javaxpathapi.html

Kathir
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: get Element value using another element