# XML Module

Simple xml/json conversion tool.&#x20;

Import

```
import xml from 'xml';
```

### Methods

[toJs(xml)](https://docs.medable.com/reference#section-tojs-xml-)\
[toXml(json, options)](https://docs.medable.com/reference#section-toxml-json-options-)

### toJs(xml)

Parses xml into a json object.

**Arguments**

* `XML` (String) an xml input string

**Returns**

JSON Object

### toXml(json, options)

Converts a json object to an xml document.

**Arguments**

* `json` (Object) a json input object.
* `options` (Object)
  * `rootElement` (String: root)
  * `prettyPrint` (Boolean: false)
  * `indent` (String: \t)
  * `newline` (String: \n)
  * `version` (String: 1.0)
  * `encoding` (String: UTF-8)
  * `standalone` (Boolean: true)
  * `doctype` (String: null)
  * `headless` (Boolean: false)

**Returns**

XML Document String

### Examples

toJS&#x20;

Example

```
import xml from 'xml'

let xmlString = 
`<note>
    <to>John</to>
    <from>Jane</from>
    <heading>Reminder</heading>
    <body>Don't forget me this weekend!</body>
</note>`

return xml.toJs(xmlString)
```

toJS&#x20;

Example Response

```
{
    "object": "result",
    "data": {
        "note": {
            "body": [
                "Don't forget me this weekend!"
            ],
            "from": [
                "Jane"
            ],
            "heading": [
                "Reminder"
            ],
            "to": [
                "John"
            ]
        }
    }
}
```

toXml&#x20;

Example

```
import xml from 'xml'
import logger from 'logger'

let jsonString = 
`{
    "employee": [
        {
            "id": "1",
            "firstName": "Tom",
            "lastName": "Cruise",
            "photo": "https://pbs.twimg.com/profile_images/735509975649378305/B81JwLT7.jpg"
        }
    ]
}`


return xml.toXml(jsonString, {rootElement:'employees'})
```

toXml&#x20;

Example Response

```
{
    "object": "result",
    "data": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><employees>{\n\t\"employee\": [\n\t\t{\n\t\t\t\"id\": \"1\",\n\t\t\t\"firstName\": \"Tom\",\n\t\t\t\"lastName\": \"Cruise\",\n\t\t\t\"photo\": \"https://pbs.twimg.com/profile_images/735509975649378305/B81JwLT7.jpg\"\n\t\t}\n\t]\n}</employees>"
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.medable.com/cortex-api/scripting/modules-1/xml-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
