January 28, 2002 - Preserving White Spaces in XML | 2
January 28, 2002 Preserving White Spaces in XML Tips: January 2002
Yehuda Shiran, Ph.D.
|
DOMDocument
's xml
property to reflect the input XML file as is, without any formatting. You can use the DOMDocument
's preserveWhiteSpace
property to control the parser behavior with respect to preservation of white spaces. By default, preserveWhiteSpace
is false. If you load an XML file with these three lines:
<SCRIPT LANGUAGE="JavaScript">
<!--
function load2() {
var xmldoc;
xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmldoc.async = false;
xmldoc.load("mydvd.xml");
alert(xmldoc.xml);
}
// -->
</SCRIPT>
you will get reformatted XML when echoing the xml
property. But when you set preserveWhiteSpace
to true
in the above code:
<SCRIPT LANGUAGE="JavaScript">
<!--
function load1() {
var xmldoc;
xmldoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
xmldoc.preserveWhiteSpace = true;
xmldoc.async = false;
xmldoc.load("mydvd.xml");
alert(xmldoc.xml);
}
// -->
</SCRIPT>
you will get the original XML when echoing the xml
property.