JQuery | parseXML() Method

This parseXML() Method in jQuery is used to parse a string into an XML document.

Syntax:

jQuery.parseXML( data )

Parameters: This method accept single parameter which is mentioned above and described below:

  • data: This parameter holds the well-formed XML string to be parsedd.

Return Value: It returns the XML document.

Below exa,ples illustrate the parseXML() method in jQuery:
Example 1: In this example, the parseXML() method parses a string into an XML document.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <title>JQuery | parseXML() method</title>
    <script src=
    </script>
    <style>
        #a {
            color: blue;
        }
          
        #b {
            color: red;
        }
    </style>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color: green"
        GeeksforGeeks 
    </h1>
  
    <h3>JQuery | parseXML() method</h3>
    <p id="a"></p>
    <p id="b"></p>
  
    <script>
        var xml = "<rss version='2.0'>"+
                    "<channel>"+ 
                      "<body>String : parseXML</body>"+
                     "</channel>"+
                  "</rss>",
            xmlDoc = $.parseXML(xml),
            $xml = $(xmlDoc),
            $body = $xml.find("body");
  
        $("#a").append($body.text());
        $body.text("XMLDocument : parseXML");
        $("#b").append($body.text());
    </script>
</body>
  
</html>

chevron_right


Output:

Example 2: .

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
  
<head>
    <meta charset="utf-8">
    <title>JQuery | parseXML() method</title>
    <script src=
    </script>
    <style>
        #a {
            color: blue;
        }
          
        #b {
            color: red;
        }
    </style>
</head>
  
<body style="text-align:center;">
  
    <h1 style="color: green"
        GeeksforGeeks 
    </h1>
  
    <h3>JQuery | parseXML() method</h3>
    <p id="a"></p>
    <p id="b"></p>
  
    <script>
        var xml = "<rss version='2.0'>"+
                    "<channel>"+
                      "<body style='text-align:center;'>"+
                        "<h1 style='color: green'>GeeksForGeeks</h1>"+
                        "<h3>JQuery | parseXML() method</h3>"+
                      "</body>"+
                    "</channel>"+
                  "</rss>",
            xmlDoc = $.parseXML(xml),
            $xml = $(xmlDoc),
            $val = $xml.find("h3");
        $val.text("Parses a string into an XML document.");
        $("#a").append($val.text());
    </script>
</body>
  
</html>    

chevron_right


Output:




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.