XMLHelper
-
- UpdatedFeb 1, 2024
- 2 minutes to read
- Washington DC
- Building applications
The XML helper script include makes it easy to parse XML in scripts.
Use the following methods to export XML to JSON, or JSON to XML.
- The toObject() method returns the XML elements as JSON properties. This method works properly whether the supplied parameter is an XML document or an XML string. This method has an optional parameter of the XML input for conversion as an alternative to specifying the XML input in the constructor.
- The toXMLDoc() method returns JSON provided as XML elements.
Note: You must escape ampersand characters (&) in your XML or the conversion silently fails.
See also:
Example
The following example shows how to convert an XML document into JSON and uses a recursive function to output each member. The recursive function helps indicate how the XML document structure is rendered as
JSON.
Output: