I have a string of XML format. As shown below:
<gt>
<st>sample1</st>
<tt>sample2</tt>
<tt>sample3</tt>
</gt>
I need to get the node value in Java script file. How can I get the value?
Use .parseXML()
.
var xmldom = $.parseXML('<gt><st>sample1</st><tt>sample2</tt><tt>sample3</tt></gt>');
console.log($(xmldom).find('gt *'));
This will find all nodes under <gt>
.
Try this code:
var xml = "<gt><st>sample1</st><tt>sample2</tt><tt>sample3</tt></gt>",
xmlDoc = $.parseXML(xml),
$xml = $( xmlDoc ),
$st = $xml.find( "st" );
alert( $st.text() );
See the js fiddle example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With