Skip to main content
Modules

XML

XML

The XML module is responsible for performing handling actions on files with the .xml extension.

xmlToJson

Method responsible for getting a javascript object (JSON) from an XML file. The XML tags are turned into a JSON in which each property corresponds to an XML tag.

js
const fileXML = await XML.xmlToJson["v1_0_0"]({
xmlPath: `C:\\Users\\Roberty\\Downloads\\nf.xml`
})

Required parameters

  • xmlPath: String - expects the path where the XML file is.

Optional parameters

  • There are no optional parameters.

Return

This method returns the following object:

  • json: Object - it returns the whole xml as JSON. Just use json.tag-present-in-the-xml to get the desired property. Example:
js
fileXML.json.NFe.infNFe

xmlGetFields

Method responsible for getting one or more fields of a JSON obtained by the xmlToJson action.

js
const file = await XML.xmlGetFields["v1_0_0"]({
xmlJson: fileXML,
fields: [`xProd`, `ide`]
})

Required parameters

  • xmlJson: Object from xmlToJson - expects a value returned by the xmlToJson action.
  • fields: String[] - expects an array of strings where each string is a desired field of the JSON.

Optional parameters

  • There are no optional parameters.

Return

This method returns the following object:

  • fields: Object - it returns an object with every property passed in the fields field. Just use fields.value-passed-in-the-array to get the desired property. Example:
js
file.fields.xProd
file.fields.ide