-
Notifications
You must be signed in to change notification settings - Fork 4
SOAPEncoding
SOAPEncoding is a tool for translating XML elements using the SOAP Encoding style into the corresponding javaScript values.
For plain Objects, as generic key-value mappings, {http://xml.apache.org/xml-soap}Maps are used instead of structs.
So, in current version, SOAPEncoding is mostly suitable for documents generated with Apache SOAP.
const {XMLParser, SOAPEncoding} = require ('xml-toolkit')
const xml = `
<return
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns2="http://xml.apache.org/xml-soap"
xsi:type="ns2:Map"
>
<item>
<key xsi:type="xsd:string">house_id</key>
<value xsi:type="xsd:int">9456</value>
</item>
<item>
<key xsi:type="xsd:string">eas_id</key>
<value xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="xsd:int[1]">
<item xsi:type="xsd:int">21</item>
</value>
</item>
<item>
<key xsi:type="xsd:string">executed_volume</key>
<value xsi:nil="true"/> <!-- explicit xsi:nil -->
</item>
<item>
<key xsi:type="xsd:string">executed_volume_cost</key>
<value xsi:type="xsd:string"/> <!-- just empty, ignored -->
</item>
</return>`
const node = new XMLParser ().process (xml)
const pojo = new SOAPEncoding ().decode (node)
/*
{
house_id: '9456',
eas_id: ['21'], // number as a string, like any other scalar
executed_volume: null,
}
*/ const se = new SOAPEncoding (
// {
// emptyScalar: undefined, // may be null
// }
)| Name | Defaullt | Description |
|---|---|---|
emptyScalar |
undefined |
The value for empty simple typed elements without xsi:nil set, e.g. <value xsi:type="xsd:string"/>
|
For a given XMLNode, returns the corresponding plain javaScript Object.
Any value with truthy xsi:nil is read as null.
All values of simple Types having some text content are read as strings (numbers are NOT parsed).
Empty elements of simple Types are read as emptyScalar (undefined by default).
Maps from http://xml.apache.org/xml-soap namespace are read as Objects. Entries with undefined values are skipped, so empty scalar elements are ignored by default, but this can be changed by setting emptyScalar to null.