spacer
Yehuda Shiran January 28, 2002
Preserving White Spaces in XML
Tips: January 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

Sometimes, you may want to preserve white spaces in the input XML file. You want the 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.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint