Non-jQuery version:

var parseXml;

if (window.DOMParser) {
    parseXml = function(xmlStr) {
        return ( new window.DOMParser() ).parseFromString(xmlStr, "text/xml");
    };
} else if (typeof window.ActiveXObject != "undefined" && new window.ActiveXObject("Microsoft.XMLDOM")) {
    parseXml = function(xmlStr) {
        var xmlDoc = new window.ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = "false";
        xmlDoc.loadXML(xmlStr);
        return xmlDoc;
    };
} else {
    parseXml = function() { return null; }
}

var xmlDoc = parseXml("<foo>Stuff</foo>");
if (xmlDoc) {
    window.alert(xmlDoc.documentElement.nodeName);
}

Since jQuery 1.5, you can use jQuery.parseXML(), which works in exactly the same way as the above code:

var xmlDoc = jQuery.parseXML("<foo>Stuff</foo>");
if (xmlDoc) {
    window.alert(xmlDoc.documentElement.nodeName);
}
Answer from Tim Down on Stack Overflow
🌐
W3Schools
w3schools.com › xml › xml_parser.asp
XML Parser
All major browsers have a built-in XML parser to access and manipulate XML. The XML DOM (Document Object Model) defines the properties and methods for accessing and editing XML. However, before an XML document can be accessed, it must be loaded into an XML DOM object. All modern browsers have a built-in XML parser that can convert text into an XML DOM object. This example parses a text string into an XML DOM object, and extracts the info from it with JavaScript...
People also ask

What JavaScript conversion method is there for a string data type
divWe can explicitly convert values of Boolean or numeric data types to string values using String or n toString to guarantee that our code operates as expectedbrbrbrdiv
🌐
scholarhat.com
scholarhat.com › home
Convert string to xml and xml to string using javascript
How can XML data be converted to a string
divWe begin by creating a TransformerFactory and a Transformer for XML transformation The modified XML is then stored in text form using a StringWriter The transform method then modifies the XML Document which we may store into the result string using stringWritebrbrbrdiv
🌐
scholarhat.com
scholarhat.com › home
Convert string to xml and xml to string using javascript
What does XML mean in JavaScript
divXML Extensible Markup Language is a markup language that is similar to HTML but lacks predefined tags Instead you create your tags that are tailored to your requirements This is an effective method for storing data in a format that can be stored foundnbspandnbspshareddiv
🌐
scholarhat.com
scholarhat.com › home
Convert string to xml and xml to string using javascript
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › XML › Guides › Parsing_and_serializing_XML
Parsing and serializing XML - XML | MDN
fetch("example.xml") .then((response) => response.text()) .then((text) => { const parser = new DOMParser(); const doc = parser.parseFromString(text, "text/xml"); console.log(doc.documentElement.nodeName); }); This code fetches the resource as a text string, then uses DOMParser.parseFromString() ...
🌐
ScholarHat
scholarhat.com › home
Convert string to xml and xml to string using javascript
September 22, 2025 - Following are the Methods for Converting XML to String · In JavaScript, the XMLSerializer object has a serializeToString method that converts a DOM node (an XML document or any element within it) into its equivalent XML string representation.
🌐
Medium
medium.com › @polyismstudio › converting-json-from-and-to-xml-in-javascript-9d3d8288331f
Converting JSON from and to XML in Javascript | by Sem Postma | Medium
December 1, 2018 - function xml2obj(xml, opt) { if (typeof xml === 'string') { var dom = (new DOMParser).parseFromString(xml, 'application/xml'); xml = dom.childNodes[dom.childNodes.length - 1]; } opt = opt || {}; var attrPrefix = opt.attrPrefix || ''; function ...
🌐
OpenText
docs.microfocus.com › SM › 9.50 › Hybrid › Content › programming › javascript › reference › javascript_method_xml_toxmlstring.htm
JavaScript method: XML.toXMLString()
Develop > Programming Guide > JavaScript and Service Manager reference > Service Manager defined JavaScript objects > JavaScript object: XML > JavaScript method: XML.toXMLString() This method converts an XML object into a valid XML string.
Find elsewhere
🌐
C# Corner
c-sharpcorner.com › blogs › xml-parser-in-javascript
XML Parser In JavaScript
March 21, 2023 - XMLSerialzer() object is used to parse the XML to string using the serializeToString method.
🌐
Macfh
macfh.co.uk › JavaJive › ProgScriptWeb › JSSSV2XML.html
JavaScript SSV To XML Convertor
You can specify the separator character, string, or regular expression. Default is a \t, \x09, <TAB>, <Ctrl-I> character. You can use JavaScript escapes to specify unprintable characters, or regular expressions (but do not include the latter's bounding slashes, and sometimes you may need to double-escape some characters, for example if \Character doesn't work, try \\Character).
🌐
SAP Community
community.sap.com › t5 › application-development-discussions › how-do-i-convert-a-json-string-to-xml-in-abap › m-p › 11653767
Solved: Re: How do I convert a JSON string to XML in ABAP - SAP Community
April 30, 2021 - writer = cl_sxml_string_writer=>create( ). CALL TRANSFORMATION id SOURCE text = json_string RESULT XML writer. xml = cl_abap_codepage=>convert_from( writer->get_output( ) ). But this did not help. am I missing something here. ... Hi. You need first a json reader. Using the ID transformation, I think it cannot go directly to an XML, it has to go to an ABAP variable (structure in your case).
🌐
Tribalgroup
docs.ebs.tribalgroup.com › content › Workflow Manager › Workflow Manager Appendix › Use the ConvertJsonStringToDictionary Activity.htm
Use the ConvertJsonStringToDictionary activity
The ConvertJsonStringToDictionary activity can be used to convert a JSON (JavaScript Object Notation) string and return a dictionary of string key-value pairs. The ConvertJsonStringToDictionary activity is located in the XML/Json section of the Tribal Toolbox.
🌐
Microsoft Press Store
microsoftpressstore.com › articles › article.aspx
Programming in HTML5 with JavaScript and CSS3: Access and Secure Data | Microsoft Press Store
August 25, 2014 - When this code runs, the person object is reconstructed from the JSON string. Capturing dynamic image data follows a similar pattern as with the other techniques reviewed. The key difference is now the responsetype property must be set to blob. The following code demonstrates retrieving a binary image object and deserializing it into the webpage: var xReq = new XMLHttpRequest(); xReq.open("GET", "orange.jpg", false); xReq.responseType = 'blob'; xReq.send(null); var blob = xReq.response; document.getElementById("result").src = URL.createObjectURL(blob);
🌐
| Mitya.uk
mitya.uk › projects › j-path
J-Path | Mitya.uk
jpath(input, path) - the main function, ... array of items - which may be of any data type depending on what was targeted. jpath.obj_to_xml(obj) - convert a JavaScript object, obj, to an XML string....
🌐
Tribalgroup
docs.ebs.tribalgroup.com › content › Workflow Manager › Workflow Manager Appendix › Use the ConvertXmlToJson activity.htm
Use the ConvertXmlToJson Activity
The ConvertXmlToJson activity can be used to convert an XML (Extensible Markup Language) value into a JSON (JavaScript Object Notation) value.
🌐
Tribalgroup
docs.ebs.tribalgroup.com › content › Workflow Manager › Workflow Manager Appendix › Use the ConvertJSONtoString activity.htm
Use the ConvertJsonToString activity
The ConvertJsonToString activity can be used to convert a JSON (JavaScript Object Notation) value into a string representation of a JSON object. The ConvertJsonToString activity is located in the XML/Json section of the Tribal Toolbox.
🌐
InformIT
informit.com › articles › article.aspx
Data-Oriented Mashup Techniques | Mashup Styles, Techniques, and Technologies | InformIT
May 25, 2009 - In the preceding listing a DOM parser is instantiated and is accessed to get the root node. Each node is then traversed via its child nodes until the desired text data node is found. Note that there is a different parser used for Microsoft Internet Explorer and Mozilla. Since JSON is pure JavaScript, a string containing JSON data can simply be evaluated to create a JavaScript object.
🌐
Justwebdevelopment
justwebdevelopment.com › home › php › read xml data in php
Read xml data in php | PHP Development | Justwebdevelopment
September 14, 2011 - PHP: Hypertext Preprocessor programming language, a popular dynamic web page scripting language, features the built-in SimpleXML extension, which simplifies reading and using XML in your PHP scripts. Read an RSS feed, XML office documents, or your own custom XML document.
🌐
GitLab
git.fmrib.ox.ac.uk › sean fitzgibbon › fix › repository
matlab_ciftireadwrite/@gifti/private/xml_parser.m · d85b77364ac63ca407bf8eec07ef46acec1d367c · Sean Fitzgibbon / fix · GitLab
FIX - FMRIB's ICA-based Xnoiseifier Gholamreza Salimi-Khorshidi and Stephen Smith, FMRIB Analysis Group MATLAB compilation/wrapper Duncan Mortimer Copyright (C) 2012-2019 University of Oxford
🌐
Drumcoder
drumcoder.co.uk › blog › 2018 › apr › 10 › json-xml-jackson
JSON to XML with Jackson - drumcoder.co.uk
String jsonString = "" + "{\n \"_links\": {\n" + " \"individual\": {\n" + " \"href\": \"/individuals/matching\",\n" + " \"name\": \"GET\",\n" + " \"title\": \"Individual Details\"\n" + " },\n" + " \"self\": {\n" + " \"href\": \"/individuals/matching/\"\n" + " }\n" // + " }\n" // + "}"; ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper xmlMapper = new XmlMapper(); JsonNode tree = objectMapper.readTree(jsonString); String jsonAsXml = xmlMapper.writer().withRootName("RootTagName").writeValueAsString(tree);
🌐
SiteLint
sitelint.com › home page › blog › best practices › check if a string is valid html using javascript
Check if a string is valid HTML using JavaScript – SiteLint
September 21, 2025 - One method is to use DOMParser API and its method parseFromString. The DOMParser API interface allows you to parse XML or HTML source code from a string and convert it into a DOM Document.