Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes Access Xml node values 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 "Access Xml node values" Watch "Access Xml node values" New topic
Author

Access Xml node values

kamal palia
Greenhorn

Joined: Jul 20, 2012
Posts: 17
<form action="http://localhost:7003/MultiMPI/Authenticate" method="post">
<textarea name="xmlData" cols=90 rows=90>
<req-auth>
<request-id>4sS4yV6tQ2</request-id>
<response-id>MTQ0NzY2</response-id>
<req-type>1002</req-type>
<auth-data>
<field name='OTP2' value='360055' />
</auth-data>
</req-auth>
</textarea>
<br><input type="submit" value="Request">
</form>



how can i get value 360055?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2452
    
    8

Using XSLT surely able to get the necessary values. However, does your form data follow a DTD or XML Schema? With such doc you can jump to the node or tag you need.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD OCPJP7 OCPWCD5 OCPBCD5
kamal palia
Greenhorn

Joined: Jul 20, 2012
Posts: 17
I am able to access all the nodes value by using

NodeList requestID = element.getElementsByTagName("request-id");
Element line = (Element) requestID.item(0);

but using same how can i get the value of

<auth-data>
<field name='OTP2' value='360055' />
</auth-data>

360055?
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 2452
    
    8

so what element are you on, <auth-data> or <field>? The actual value you need is in the field element with the attribute "value".

You may want to check out this link which is similar to what you should be getting at.
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 520
    
    3
If you know getElementsByTagName well, you can continue to use one step further. Off-hand like this?
 
GeeCON Prague 2014
 
subject: Access Xml node values