xml-js
xml-js copied to clipboard
Question: Validating Output Of Parsing Xml Document
Hi There,
I tried out your module to see whether it would be candidate library to use for automated testing of SOAP functionality. I detail my use case below with a sample file
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:bsvc="urn:com.company/bsvc">
<soapenv:Header>
<bsvc:Company_Common_Header>
<!--Optional:-->
<bsvc:Include_Reference_Descriptors_In_Response>?</bsvc:Include_Reference_Descriptors_In_Response>
</bsvc:Company_Common_Header>
</soapenv:Header>
</soapenv:Envelope>
I load that xml via the following code....
const xml = convert.xml2json((readFileSync('./files/Sample.xml', 'utf8')), {compact : true, ignoreAttributes : false, spaces: 2});
However, I'm returned the following JSON payload...
{
"soapenv:Envelope": {
"_attributes": {
"xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
"xmlns:bsvc": "urn:com.company/bsvc"
},
"soapenv:Header": {
"bsvc:Company_Common_Header": {
"_comment": "Optional:",
"bsvc:Include_Reference_Descriptors_In_Response": {
"_text": "?"
}
}
}
}
}
Just wondering when I send the same xml to this service for example https://codebeautify.org/xmltojson
how come I get a different payload to above?
{
"Envelope": {
"Header": {
"Company_Common_Header": {
"Include_Reference_Descriptors_In_Response": {
"__prefix": "bsvc",
"__text": "?"
},
"__prefix": "bsvc"
},
"__prefix": "soapenv"
},
"_xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
"_xmlns:bsvc": "urn:com.company/bsvc",
"__prefix": "soapenv"
}
}
The last result rendered is generally what I get returned back when I use an online service to validate the integrity of the payload as opposed to this library. The latter payload is something I'm seeing quite frequently across online sites. Thoughts? What's the reasons for the discrepancies?