You are here: Reference > JavaScript > client-side > xml handling > properties > responseXML (XMLHttpRequest)

responseXML property (XMLHttpRequest)

Browser support:
Builds an XMLDocument object from the body of the server's response.
This property can be used when the response body is an XML formatted text. If you need the response body as a string, use the responseText property


You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

Returns the XMLDocument object built form the response body.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the responseXML property. If the responseXML property is not valid, the responseText property is used to get the contents of the response body. See the attached ajax.js file for details.
    <script type="text/javascript" src="ajax.js"></script>
    <script type="text/javascript">
        var httpRequest = null;
        function SendRequest () {
            if (!httpRequest) {
                httpRequest = CreateHTTPRequestObject ();   // defined in ajax.js
            if (httpRequest) {          
                    // The requested file must be in the same domain that the page is served from.
                var url = "news.xml";
       ("GET", url, true);    // async
                httpRequest.onreadystatechange = OnStateChange;
                httpRequest.send (null);

        function OnStateChange () {
            if (httpRequest.readyState == 0 || httpRequest.readyState == 4) {
                if (IsRequestSuccessful (httpRequest)) {    // defined in ajax.js
                    FillTable ();
                else {
                    alert ("Operation failed.");

        function FillTable () {
            var xmlDoc = ParseHTTPResponse (httpRequest);   // defined in ajax.js
            if (!xmlDoc)

            var resTable = document.getElementById ("resTable");
            var xmlNodes = ["title", "description", "pubDate", "link"];

            var itemTags = xmlDoc.getElementsByTagName ("item");
            for (i = 0; i < itemTags.length; i++) {
                resTable.insertRow (i);
                for (j = 0; j < xmlNodes.length; j++) {
                    var recordNode = itemTags[i].getElementsByTagName (xmlNodes[j])[0];
                    resTable.rows[i].insertCell (j);
                    if ('textContent' in recordNode)
                        resTable.rows[i].cells[j].innerHTML = recordNode.textContent;
                        resTable.rows[i].cells[j].innerHTML = recordNode.text;
<body onload="SendRequest ()">
    <table border="1px">
        <thead style="font-weight: bold;">
        <tbody id="resTable">
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content