XMLHelper

Helper for XML manipulation.

Functions

1

Convert a JavaScript object to an XML string.

From:

{
    name : 'Task 1',
    data : [
        {
            text : 'foo 1',
            ref  : 'fooItem 1'
        },
        {
            text : 'foo 2',
            ref  : 'fooItem 2'
        }
    ]
}

To:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
    <name>Task 1</name>
    <data>
        <element>
            <text>foo 1</text>
            <ref>fooItem 1</ref>
        </element>
        <element>
            <text>foo 2</text>
            <ref>fooItem 2</ref>
        </element>
    </data>
</root>
ParameterTypeDescription
objObject

Object to convert.

optionsObject

Convert options.

options.rootNameString

Root name for the XML. root by default.

options.elementNameString

Element name for each node of the XML. element by default.

options.xmlnsString

Add value for xmlns property for the root tag of the XML.

options.includeHeaderBoolean

false to not include the header <?xml version="1.0" encoding="UTF-8"?> on top of the XML.

options.rootElementForArrayBoolean

false to not include a root element for array of items. e.g. for the above example:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
    <name>Task 1</name>
    <element>
        <text>foo 1</text>
        <ref>fooItem 1</ref>
    </element>
    <element>
        <text>foo 2</text>
        <ref>fooItem 2</ref>
    </element>
</root>
Returns: String -

the XML