Okay, so we have a webapp that's communicating with a web-service via XML.
As of now we're assembling those XMLs by just hacking Strings together (and sending that via XMLHttpRequest/POST). I'm of a mind to re-factor that into using the facilities for building and serialising an XML DOM tree that are built into the browser, i.e. document.implementation & XMLSerializer().serializeToString(doc) (see Mozilla docs here and here). It's been working fine so far, except the resulting string doesn't contain an XML declaration.
So, how's that supposed to work? Any good advice and/or reading?
Oh, yeah, I've found this mozilla bug describing the problem and a hacky workaround (the linked thread is available via archive.org).
Different browsers have different behavior around outputting the xml declarations.
Here's been my experience:
Not sure what IE does. Another noteworthy observation is that there is seemingly no API (that i have found) to turn off the declaration in Opera. As a result, I'd find a better 'hack' than the one that you point to that is aware of if the XML declaration is already there or not. Perhaps a quick string based check if the serialized form contains the declaration would be adequate (e.g if (serialized.slice(0, 21) == "<?xml version=\"1.0\"?>") ...
though this isn't a great way to check/ I'd consider alternatives).
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