Using the Soap module in Nodejs (via loopback-connector-soap), I'm trying to convert json to xml for my soap request, but I have a few problems...
What it is:
<ns:UserDefinedFields>
<ns:UserDefinedField>
<ns:displayName>Campaign?</ns:displayName>
<ns:fieldValue>Yes</ns:fieldValue>
</ns:UserDefinedField>
</ns:UserDefinedFields>
<ns:UserDefinedFields>
<ns:UserDefinedField>
<ns:displayName>Anticipated Use</ns:displayName>
<ns:fieldValue>6</ns:fieldValue>
</ns:UserDefinedField>
What it should be:
<ns:UserDefinedFields>
<ns:UserDefinedField>
<base:displayName>Campaign?</base:displayName>
<base:fieldValue>Yes</base:fieldValue>
</ns:UserDefinedField>
<ns:UserDefinedField>
<base:displayName>Anticipated Use</base:displayName>
<base:fieldValue>6</base:fieldValue>
</ns:UserDefinedField>
</ns:UserDefinedFields>
<ns:UserDefinedFields>
<base:fieldValue>
instead of <ns:fieldValue>
Any advice would be super helpful! Thanks!
The XML:
{
...
"UserDefinedFields": [
{
"displayName": "Campaign?",
"fieldValue": "Yes"
},
{
"displayName": "Anticipated Use",
"fieldValue": 6
}
]
...
}
The XSD:
...
<xs:element name="UserDefinedFields" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="UserDefinedField" type="base:UserDefinedFieldType" minOccurs="0" maxOccurs="15"/>
</xs:sequence>
</xs:complexType>
</xs:element>
...
To deal with the namespace, pass the ignoredNamespaces the soap.createClient
options.
{
"ignoredNamespaces": {
namespaces: ['ns']
},
}
And then add the namespace manually. It's ugly, but it works.
To deal with multiple UserDefinedFields
, it should look like this:
{
. . .
DomainRegistration['ns:UserDefinedFields']['ns:UserDefinedField'][0] : {
"base:displayName": "Campaign?",
"base:fieldValue": "Yes"
},
DomainRegistration['ns:UserDefinedFields']['ns:UserDefinedField'][1] : {
"base:displayName": "Anticipated Use",
"base:fieldValue": 6
}
. . .
}
Or to put it more simply:
{
ouside: {
insideA: [
'one',
'two',
]
insideB: [
{'one':'ONE'},
{'two':'TWO'}
]
}
}
//will create:
<outside>
<insideA>
<one />
<two />
</insideA>
<insideB>
<one>ONE</one>
</insideB>
<insideB>
<two>TWO</two>
</insideB>
</outside>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With