Open In App

JQuery | parseXML() Method

Last Updated : 30 Apr, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report
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. html
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>JQuery | parseXML() method</title>
    <script src=
"https://code.jquery.com/jquery-3.4.1.js">
    </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>
Output: Example 2: . html
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>JQuery | parseXML() method</title>
    <script src=
"https://code.jquery.com/jquery-3.4.1.js">
    </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>    
Output:

Next Article

Similar Reads