Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 78206 of The global XML object

  • Revision slug: E4X_Tutorial/The_global_XML_object
  • Revision title: The global XML object
  • Revision id: 78206
  • Created:
  • Creator: Sephr
  • Is current revision? No
  • Comment fixing comment

Revision Content

{{ Previous("E4X Tutorial:Namespaces") }}

The global XML Object

E4X-capable JavaScript engines put a new property on the global object. The XML object has several properties that allow you to customize parsing and serialization of E4X. XML elements will remember the settings of the XML object from the time of their creation.

ignoreComments

true by default. This property tells E4X to ignore comment nodes when serializing and filtering. This means that if ignoreComments is true, the list returned by .comments() will be empty. Observe:

var element = <foo>
                <!-- my comment -->
                <bar/>
              </foo>;
element.comments().length(); // returns 0
element.toXMLString(); // returns <foo><bar/></foo>

XML.ignoreComments = false;

element = <foo>
            <!-- my comment -->
            <bar/>
          </foo>;
element.comments().length(); // returns 1
element.toXMLString(); // returns <foo><!-- my comment --><bar/></foo>

ignoreProcessingInstructions

true by default. This property tells E4X to ignore processing instructions in XML when serializing and filtering. For example

var element = <foo>
                <?process x="true"?>
                <bar/>
                <?process x="false"?>
              </foo>;
element.toXMLString(); // returns <foo><bar/></foo>

XML.ignoreProcessingInstructions = false;

var element = <foo>
                <?process x="true"?>
                <bar/>
                <?process x="false"?>
              </foo>;
element.toXMLString(); // returns <foo><?process x="true"?><bar/><?process x="false"?></foo>

ignoreWhitespace

true by default. Ignores whitespace between nodes and leading and trailing whitespace in text nodes, which would otherwise be interpreted as text nodes or as part of those text nodes, respectively.

prettyPrinting

true by default. When true, toXMLString() includes newlines and indenting for the serialization of E4X objects.

prettyIndent

2 by default. The number of spaces to indent each level in the XML tree. Ignored if prettyPrinting is false.

{{ Previous("E4X Tutorial:Namespaces") }}

Revision Source

<p>{{ Previous("E4X Tutorial:Namespaces") }}
</p>
<h2 name="The_global_XML_Object"> The global XML Object </h2>
<p>E4X-capable JavaScript engines put a new property on the global object. The <code>XML</code> object has several properties that allow you to customize parsing and serialization of E4X. XML elements will remember the settings of the XML object from the time of their creation.
</p>
<h3 name="ignoreComments"> <code>ignoreComments</code> </h3>
<p><code>true</code> by default.
This property tells E4X to ignore comment nodes when serializing and filtering. This means that if <code>ignoreComments</code> is true, the list returned by <code>.comments()</code> will be empty. Observe:
</p>
<pre class="eval">var element = &lt;foo&gt;
                &lt;!-- my comment --&gt;
                &lt;bar/&gt;
              &lt;/foo&gt;;
element.comments().length(); // returns 0
element.toXMLString(); // returns &lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;

XML.ignoreComments = false;

element = &lt;foo&gt;
            &lt;!-- my comment --&gt;
            &lt;bar/&gt;
          &lt;/foo&gt;;
element.comments().length(); // returns 1
element.toXMLString(); // returns &lt;foo&gt;&lt;!-- my comment --&gt;&lt;bar/&gt;&lt;/foo&gt;
</pre>
<h3 name="ignoreProcessingInstructions"> <code>ignoreProcessingInstructions</code> </h3>
<p><code>true</code> by default.
This property tells E4X to ignore processing instructions in XML when serializing and filtering. For example
</p>
<pre class="eval">var element = &lt;foo&gt;
                &lt;?process x="true"?&gt;
                &lt;bar/&gt;
                &lt;?process x="false"?&gt;
              &lt;/foo&gt;;
element.toXMLString(); // returns &lt;foo&gt;&lt;bar/&gt;&lt;/foo&gt;

XML.ignoreProcessingInstructions = false;

var element = &lt;foo&gt;
                &lt;?process x="true"?&gt;
                &lt;bar/&gt;
                &lt;?process x="false"?&gt;
              &lt;/foo&gt;;
element.toXMLString(); // returns &lt;foo&gt;&lt;?process x="true"?&gt;&lt;bar/&gt;&lt;?process x="false"?&gt;&lt;/foo&gt;
</pre>
<h3 name="ignoreWhitespace"> <code>ignoreWhitespace</code> </h3>
<p><code>true</code> by default.
Ignores whitespace between nodes and leading and trailing whitespace in text nodes, which would otherwise be interpreted as text nodes or as part of those text nodes, respectively.
</p>
<h3 name="prettyPrinting"> <code>prettyPrinting</code> </h3>
<p><code>true</code> by default.
When true, <code>toXMLString()</code> includes newlines and indenting for the serialization of E4X objects.
</p>
<h3 name="prettyIndent"> <code>prettyIndent</code> </h3>
<p><code>2</code> by default.
The number of spaces to indent each level in the XML tree. Ignored if <code>prettyPrinting</code> is false.
</p><p>{{ Previous("E4X Tutorial:Namespaces") }}
</p>
Revert to this revision