parseFromString method (DOMParser)
Builds an XMLDocument object from the specified string.
Note: The DOMParser object and its parseFromString method are supported in Internet Explorer from version 9.The parseFromString method is useful if you have an XML formatted text and you need to handle it as an XML document.
For example, when an XML document is downloaded with the XMLHttpRequest object, the responseXML property of the XMLHttpRequest object refers to an XMLDocument object that represents the downloaded content. If the downloaded content is not well-formed or the character encoding was detected wrong, the responseXML property refers to an XMLDocument object that describes the error. In that case, you can use the responseText property of the XMLHttpRequest object and the parseFromString method to build an XMLDocument object 'manually'.In older Internet Explorer versions (and optionally in newer ones as well), use the loadXML method for similar functionality. See the example and the ParseHTTPResponse method in the attached ajax.js file of the example below for details.
You can find the related objects in the Supported by objects section below.
|Required. String that specifies the contents of the XML file to parse.|
Required. String that specifies the content type of the string to parse. Only the XML format is supported, so use one of the following equivalent values:
Returns the created XMLDocument object. If the input string is not well-formed, the parseFromString method raises an exception in Internet Explorer.
Example HTML code 1:
This example illustrates the use of the parseFromString and the loadXML methods:
Did you find this example helpful?
User Contributed Comments