Although Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office is a single library, there are times when you may want to parse an XML document in different ways. The XML recommendation allows parsers to validate or not validate documents, and allows nonvalidating parsers to skip the retrieval of external resources. In addition, you may want the parser to process the document while your code continues or remove extraneous white space from your documents.
The DOMDocument
object exposes four properties that allow the user to change parsing behavior at run time.
Each of these properties takes and returns a Boolean value. The default value for async
, validateOnParse
, and resolveExternals
is True. The default value for preserveWhiteSpace
, which specifies whether to honor the xml:space
attribute in XML documents, is False.
The following Microsoft Visual Basic® Scripting Edition (VBScript) sample code loads and parses an XML file synchronously; however, the XML document is not validated as it is parsed.
dim XMLDoc set XMLDoc = Server.CreateObject("Msxml2.DOMDocument.5.0") XMLDoc.async = false XMLDoc.validateOnParse = false XMLDoc.load("sample.xml")
The following example is in Microsoft JScript®.
var XMLDoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); XMLDoc.async = false; XMLDoc.validateOnParse = false; XMLDoc.load("sample.xml");
Note Although not explicitly indicated in this code, by default, the parser will resolve externals and will not honor the value of the xml:space
attribute.
Asynchronous parsing allows your application to do other things, such as display a progress bar, while the file is being parsed. After loading the XML document but before manipulating or reading it, be sure to check the readyState
property to ensure that the document has been fully loaded and that the Document Object Model (DOM) is available.
readyState Property (DOMDocument)