Leonidas-from-XIV / node-xml2js

XML to JavaScript object converter.
MIT License
4.89k stars 606 forks source link

XML to javascript and back - operation should be reversible #167

Open lafar6502 opened 9 years ago

lafar6502 commented 9 years ago

If you parse an xml document into an object and then use xml2js.Builder to convert the resulting object back to xml, the output should be equivalent to the original xml document. This way it would be much easier to modify xml and save it. Currently the resulting XML is just an xml representation of a javascript object that is totally different from the original xml. An example - xml namespace information gets serialized to something like `

<$ns> urn:hl7-org:v3 effectiveTime
              <value xsi:type="[object Object]" value="[object Object]" unit="[object Object]">
                <$ns>
                  <uri>urn:hl7-org:v3</uri>
                  <local>value</local>
                </$ns>
              </value>
              <interpretationCode code="[object Object]" codeSystem="[object Object]">
                <$ns>
                  <uri>urn:hl7-org:v3</uri>
                  <local>interpretationCode</local>
                </$ns>
              </interpretationCode>

`

for original xml being

`

                                <value xsi:type="PQ" value="145" unit="mm[Hg]"/>
                                <interpretationCode code="N" codeSystem="2.16.840.1.113883.5.83"/>

`

Leonidas-from-XIV commented 9 years ago

Due to the magnitude of options that change the generation of the JS object, it is difficult to support the generation on the same XML that was fed in. But if you feel like submitting PRs, great!

(That said, xsi:type="[object Object]" is definitely a bug)