0

I need to repair an XML file in TypeScript and I cannot find any info on it, since everyone who posts something like this has different needs. I'd like to be pointed in the right direction here.

I have an XML request as shown below. It is autogenerated by node-soap when given JSON. Using the WSDL, node-soap attempts to fill in the namespace prefixes for each property. The problem is, it gets them wrong a lot. In this example below, q106 should be replaced with hep3.

<soap:Envelope q15="some-good-url" q106="some-good-url-1" q98-"some-good-url-2>
...
    <q98:SalesOrderAuditInfo>
                <q15:ConfirmedBy xsi:nil="true"></q15:ConfirmedBy>
                <q15:ConfirmedDate>0001-01-01T00:00:00</q15:ConfirmedDate>
                <q15:CreatedBy>
                    <q106:ID>103</q106:ID>
                    <q106:Value>System, System</q106:Value>
                </q15:CreatedBy>
                <q15:CreatedDate>2022-10-26T00:43:13.413</q15:CreatedDate>
                <q15:SalesOrderType>Standard</q15:SalesOrderType>
    </q98:SalesOrderAuditInfo>

I know which namespace prefixes are bad because I have a sample request that was supplied to me. It's just XML. It looks like this:

<soap:Envelope hep="some-good-url" hep1="some-good-url-1" hep2-"some-good-url-2 hep3="some-good-url-3">
...
    <hep2:SalesOrderAuditInfo>
                <hep:ConfirmedBy xsi:nil="true"></hep:ConfirmedBy>
                <hep:ConfirmedBy:ConfirmedDate>0</hep:ConfirmedByConfirmedDate>
                <hep:CreatedBy>
                    <hep3:ID>103</hep3:ID>
                    <hep3:Value>System, System</hep3:Value>
                </hep:CreatedBy>
                <hep:CreatedDate>0</hep:CreatedDate>
                <hep:SalesOrderType>Standard</hep:SalesOrderType>
    </hep2:SalesOrderAuditInfo>

Here is the part that really matters. The Sample Request is the entire possible request body. The supplied request (with incorrect namespaces) is a subset of the sample request. I need to loop through each of the elements in the supplied request, and check to make sure the URL of that element matches the URL of the respective element in the sample request.

So in this example, loop through each element of supplied request. Start with SalesOrderAuditInfo. It's namespace URL is some-good-url-2. If we check the Sample Request, we can see that SalesOrderAuditInfo also corresponds to some-good-url-2. Continue until we hit the ID tag. This has a namespace set to some-good-url-1. If we check the Same ID (inside of CreatedBy, inside of SalesOrderAuditInfo), we can see the namespace should actually be set to some-good-url-3. So we replace q106 with hep3.

I also need to take all of the namespaces defined in the Sample Request Envelope and move them into the supplied request envelope so that this new hep3 will be defined.

At this point, I need to edit the namespace prefix. In this example, q106:ID would be replaced be the string hep3:ID. Same with all of the closing tags.

Which library can I use to accomplish this in XML? Is anyone familiar with node-soap screwing these namespaces up and know of any fix?

I am using node-soap v0.43

chxpel
  • 141
  • 2
  • 13

0 Answers0