When a JavaScript code with xmlHttpRequest.responseXML()
runs, it creates a DOM Document
object from the XML-structured HTTP response body.
Have you ever wondered at what moment the XML string is turned into the DOM Document
by an xmlHttpRequest
object?
There are two possibilities:
- The parsing could take place when
responseXML()
is executed. This way, resources are not wasted on converting the XML string until it's actually needed. - Alternatively, the parsing might occur once the HTTP response is received. If the server sends back a text/xml content-type, it indicates that XML was requested and likely needs to be converted into a DOM for proper use of the data received.
Both options have their advantages, but my inclination is that the XML string is parsed only upon calling responseXML
.
So, when exactly does the parsing of the XML string happen?
I ask because I want to compare browser performance in deserializing XML versus JSON data.