jQuery.parseXML()Method
Examples
Create a jQuery object using an XML string and get the value of the title node.
<p id="someElement"></p>
<p id="anotherElement"></p>
<script>
$(function () {
var xml = "<rss version='2.0'><channel><title>RSS Title</title></channel></rss>",
xmlDoc = $.parseXML( xml ),
$xml = $( xmlDoc ),
$title = $xml.find( "title" );
//Append "RSS Title" to #someElement
$( "#someElement" ).append( $title.text() );
//Change the title to "XML Title"
$title.text( "XML Title" );
//Append "XML Title" to #anotherElement
$( "#anotherElement" ).append( $title.text() );
})
</script>
Try it yourself »
Definition and Usage
The $.parseXML() function is used to parse a string into a corresponding XML document.
Tip:This function uses the browser's built-in parsing function to create a valid XML document, which can be passed to the jQuery() function to create a typical jQuery object, so that it can be traversed or manipulated.
Syntax
$.parseXML( xmlString )
| Parameters | Description |
|---|---|
| xmlString | String type A well-formed string used to parse into the corresponding XML document. |
Other Extensions
jQuery Misc Methods