In JavaScript, xmlHttpRequest.responseXML()
returns a DOM Document
object. The DOM Document
object is created from an XML-structured HTTP response body.
At what point during the life of an xmlHttpRequest
object is the XML string parsed into the DOM Document
?
I can imagine it may occur in one of two places.
- When
responseXML()
is called.
No need to waste resources parsing the XML string into a DOM until you know it's actually needed. - When the HTTP response has been received.
If the server returns a text/xml content-type, it's clear you've requested XML and you're probably going to want the response body parsed into a DOM as you otherwise can't do much with the requested data.
Both options have some merit, although I'm inclined to say that the XML string is parsed only when responseXML
is called.
At what point does parsing of the XML string occur?
Reaons for asking: I need to measure browser-based XML deserialisation performance, with the aim of comparing this to JSON deserialisation performance.