NoEmptyElement (XmlNode property): Difference between revisions

From m204wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by 2 users not shown)
Line 17: Line 17:
==Usage notes==
==Usage notes==
<ul>
<ul>
<li><var>NoEmptyElement</var> can be useful if you are using <var class="product">SOUL</var> to generate HTML. Tests show that some browsers work correctly for certain childless elements only if they have an empty element tag, and for other childless elements they work correctly only if there are separate start and end tags.  Because of this inconsistency, you cannot obtain a "blanket" suppression of empty element tags via using the <var>NoEmptyElt</var> option of the serialization methods (for example, see the <var>[[Serial_(XmlDoc/XmlNode_function)#noempty|Serial]]</var> method).
<div id="browserExample"></div>
<br/><br/>
<li><var>NoEmptyElement</var> can be useful if you are using <var class="product">SOUL</var> to generate HTML. Tests show that some browsers work correctly for certain childless elements only if they have an empty element tag, and for other childless elements they work correctly only if there are separate start and end tags.  Because of this inconsistency, using the <var>NoEmptyElt</var> option of the serialization methods (for example, see the <var>[[Serial_(XmlDoc/XmlNode_function)#noempty|Serial]]</var> method) to suppress all empty element tags does not guarantee successful HTML.
For example, many browsers require the <code>div</code> tag to be serialized with a separate start and end tag (<code>NoEmptyElement=True</code>), and they require the <code>br</code> tag to be serialized without a separated end tage (<code>NoEmptyElement=False</code> - the default).  This can readily be accomplished as follows:
<p>
For example, many browsers require the <code>&lt;div></code> tag to be serialized with a separate start and end tag (<code>NoEmptyElement=True</code>), and they require the <code>&lt;br></code> tag to be serialized without a separated end tag (<code>NoEmptyElement=False</code> &mdash; the default).  This can readily be accomplished as follows: </p>


<p class="code"><nowiki>%d    is object xmlDoc auto new
<p class="code"><nowiki>%d    is object xmlDoc auto new
%html is object xmlNode
%html is object xmlNode
%nd  is object xmlNode
%nd  is object xmlNode
%out  is longstring


%html = %d:addElement('html')
%html = %d:addElement('html')
Line 43: Line 43:
</nowiki></p>
</nowiki></p>
</ul>
</ul>
A variation of this example is part of the larger discussion of <var>XmlDoc</var> [[XmlDoc API#Information form and content|Information form and content]].


==Examples==
==Examples==

Latest revision as of 18:03, 18 March 2014

Suppress/produce empty tag when serializing this Element, if childless (XmlNode class)

NoEmptyElement indicates whether or not to serialize the method object XmlNode with a separate start tag and end tag instead of with a single empty-element tag if the node is childless. A Boolean value of True serializes with a separate start tag and end tag (for example, <address></address> versus <address/>). The default value, False, serializes childless nodes in the usual way, that is, with an empty-element tag.

NoEmptyElement may be specified for any Element node.

Syntax

%currentBoolean = nod:NoEmptyElement nod:NoEmptyElement = newBoolean

Syntax terms

%currentBoolean The Boolean enumeration value of object nod's NoEmptyElement property.
nod An XmlNode object expression.
newBoolean The Boolean value to set for nod's NoEmptyElement property.

Usage notes

  • NoEmptyElement can be useful if you are using SOUL to generate HTML. Tests show that some browsers work correctly for certain childless elements only if they have an empty element tag, and for other childless elements they work correctly only if there are separate start and end tags. Because of this inconsistency, using the NoEmptyElt option of the serialization methods (for example, see the Serial method) to suppress all empty element tags does not guarantee successful HTML.

    For example, many browsers require the <div> tag to be serialized with a separate start and end tag (NoEmptyElement=True), and they require the <br> tag to be serialized without a separated end tag (NoEmptyElement=False — the default). This can readily be accomplished as follows:

    %d is object xmlDoc auto new %html is object xmlNode %nd is object xmlNode %html = %d:addElement('html') * Add children of 'html' element: %nd = %html:addElement('div') %nd:noEmptyElement = true; * div must separate start and end tags %nd:addAttribute('id', 'x') %nd = %html:addElement('br') * End of 'html' element children %d:print

    The result of the above fragment is:

    <html> <div id="x"></div> <br/> </html>

A variation of this example is part of the larger discussion of XmlDoc Information form and content.

Examples

The node in the following fragment is serialized with a start and end tag:

%texta = %form:addElement('textArea') %texta:noEmptyElement = True %texta:addAttribute('name', 'foo') %texta:addAttribute('rows', '15') %texta:addAttribute('cols', '40') %texta:print

The result is:

<textArea name="foo" rows="15" cols="40"></textArea>

Request-cancellation errors (for set method)

This list is not exhaustive: it does not include all the errors that are request cancelling.

  • The newBoolean setting is an invalid value.

See also