Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added -indent value "tab" to asXML and asJSON.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0118a1190b90d40d66ee82087284008f4e11ea1037fd115e4be1cb3fbbbca601
User & Date: rolf 2020-07-23 01:03:14
Context
2020-07-23
01:39
Reworded parts of the "Getting the Code" section of the README, triggered by [0d5fa4ee6f]. check-in: 53338753e8 user: rolf tags: trunk
01:03
Added -indent value "tab" to asXML and asJSON. check-in: 0118a1190b user: rolf tags: trunk
01:00
Worked on the asXML documentation. Closed-Leaf check-in: 66cae3c794 user: rolf tags: tabs
00:03
Cherry-pick by hand of [c4947454bce0]. check-in: ba1e7f4ba5 user: rolf tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to CHANGES.





1
2
3
4
5
6
7




2020-07-03  Rolf Ade  <rolf@pointsman.de>

        User configurable separator character between namespace URI
        and local name for XML namespace-aware SAX parser:  Added the
        option -namespaceseparator to the expat command.

2020-05-14  Rolf Ade  <rolf@pointsman.de>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
2020-07-23  Rolf Ade  <rolf@pointsman.de>

        Added -indent value "tab" to asXML and asJSON.

2020-07-03  Rolf Ade  <rolf@pointsman.de>

        User configurable separator character between namespace URI
        and local name for XML namespace-aware SAX parser:  Added the
        option -namespaceseparator to the expat command.

2020-05-14  Rolf Ade  <rolf@pointsman.de>

Changes to doc/domDoc.html.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119










120
121
122
123
124
125
126
...
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
...
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
<html>
<head>
<link rel="stylesheet" href="manpage.css"><title>tDOM manual: domDoc</title><meta name="xsl-processor" content="Jochen Loewer (loewerj@hotmail.com), Rolf Ade (rolf@pointsman.de) et. al."><meta name="generator" content="$RCSfile: tmml-html.xsl,v $ $Revision: 1.11 $"><meta charset="utf-8">
</head><body>
<div class="header">
<div class="navbar" align="center">
<a href="#SECTid0x1eae960">NAME</a> · <a href="#SECTid0x1e5ff20">SYNOPSIS</a> · <a href="#SECTid0x1e97f70">DESCRIPTION </a> · <a href="#SECTid0x1efaea0">SEE ALSO</a> · <a href="#SECTid0x1efb230">KEYWORDS</a>
</div><hr class="navsep">
</div><div class="body">
  <h2><a name="SECTid0x1eae960">NAME</a></h2><p class="namesection">
<b class="names">domDoc - </b><br>Manipulates an instance of a DOM document object</p>
  
  <h2><a name="SECTid0x1e5ff20">SYNOPSIS</a></h2><pre class="syntax">domDocObjCmd <i class="m">method</i> ?<i class="m">arg arg ...</i>?</pre><pre class="syntax">domDoc <i class="m">docToken</i> <i class="m">method</i> ?<i class="m">arg arg ...</i>?</pre>

  <h2><a name="SECTid0x1e97f70">DESCRIPTION </a></h2><p>This command manipulates one particular instance of a document
object. <i class="m">method</i> indicates a specific method of the document class. These
methods should closely conform to the W3C recommendation "Document Object Model
(Core) Level 1" (<a href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html">http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html</a>). Look
at these documents for a deeper understanding of the functionality.</p><p>The valid methods are:</p><dl class="commandlist">
        
          <dt>
<b class="method">documentElement</b> ?<i class="m">objVar</i>?</dt>
................................................................................
          <dt><b class="method">getDefaultOutputMethod</b></dt>
          <dd>Returns the default output method of the document. This is
usually a result of a XSLT transformation.</dd>
        

      
        <dt>
<b class="method">asXML</b> <b class="option">?-indent none/1..8?</b> <b class="option">?-channel channelId?</b> <b class="option">?-escapeNonASCII?</b> <b class="option">?-doctypeDeclaration &lt;boolean&gt;?</b> <b class="option">-xmlDeclaration &lt;boolean&gt;?</b> <b class="option">-encString &lt;string&gt;</b> <b class="option">?-escapeAllQuot?</b> <b class="option">?-indentAttrs?</b> <b class="option">?-nogtescape?</b> <b class="option">?-noEmptyElementTag?</b>
</dt>
        <dd>
<p>Returns the DOM tree as an (optional indented) XML
        string or sends the output directly to the given
        channelId.</p>











        <p>If the option <i class="m">-escapeNonASCII</i> is given,
        every non 7 bit ASCII character in attribute values or element
        PCDATA content will be escaped as character reference in
        decimal representation.</p>

        <p>The flag <i class="m">-doctypeDeclaration</i> determines whether
        there will be a DOCTYPE declaration emitted before the first
................................................................................
<i class="m">xpathQuery</i> to the document. The context node of the query is the root
node in the sense of the XPath recommendation (not the document element). The
result can be a string/value, a list of strings, a list of nodes or a list
of attribute name / value pairs. If <i class="m">typeVar</i> is given
the result type name is stored into that variable (empty,
bool, number, string, nodes, attrnodes or mixed).</p>

<p>The argument <i class="m">xpathQuery</i> has to be a valid XPath
expression. However, there is one exception to that rule. Tcl variable
names can appear in the XPath statement at any position where it is
legal according to the rules of the XPath syntax to put an XPath
variable. The value of the variable is substituted for the variable
name. Ignoring the syntax rules of XPath the Tcl variable name may be
any legal Tcl var name: local variables, global variables, array
entries and so on.  The value will always be seen as string literal by
the xpath engine. Cast the value explicitly with the according xpath
functions (number(), boolean()) to another data type, if needed.</p>

<p>The option <i class="m">-namespaces</i> expects a tcl list with prefix /
namespace pairs as argument. If this option is not given, then any
namespace prefix within the xpath expression will be first resolved
against the list of prefix / namespace pairs set with the
selectNodesNamespaces method for the document the node belongs to. If
this fails, then the namespace definitions in scope of the context
node will be used to resolve the prefix. If this option is given, any
namespace prefix within the xpath expression will be first resolved
against that given list (and ignoring the document global prefix /
namespace list). If the list binds the same prefix to different
namespaces, then the first binding will win.  If this fails, then the
namespace definitions in scope of the context node will be used to
resolve the prefix, as usual.</p>

<p>If the <i class="m">-cache</i> option is used with a true value, then the
<i class="m">xpathQuery</i> will be looked up in a document specific cache. If
the query is found, then the stored pre-compiled query will be used.
If the query isn't found, it will be compiled and stored in the cache,
for use in further calls. Please notice, that the <i class="m">xpathQuery</i> as
given as string is used as key for the cache. This means that equal
XPath expressions, which differ only in white space, are treated as
different cache entries. Special care is needed if the XPath
expression includes namespace prefixes or references to tcl variables.
Both namespace prefixes and tcl variable references will be resolved
according to the XML prefix namespace mappings and tcl variable values
at expression compilation time. If the same XPath expression is used
later on in a context with other XML prefix namespace mappings or
values of the used tcl variables, make sure to first remove the
compiled expression from the cache with the help of the
<b class="method">deleteXPathCache</b> method, to force a recompilation.
Without using the <i class="m">-cache</i> option such consideration is never
needed.</p>

<p>Examples:</p>
          <pre class="example">set paragraphNodes [$node selectNodes {chapter[3]//para[@type='warning' or @type='error'} ]
foreach paragraph $paragraphNodes {
    lappend  values [$paragraph selectNodes attribute::type]
}

set doc [dom parse {&lt;doc xmlns="http://www.defaultnamespace.org"&gt;&lt;child/&gt;&lt;/doc&gt;}]
set root [$doc documentElement]
set childNodes [$root selectNodes -namespaces {default http://www.defaultnamespace.org} default:child]</pre>

          </dd>
      

      
        <dt>
<b class="method">baseURI</b> <i class="m">?URI?</i>
</dt>
................................................................................

  </dl><p>Otherwise, if an unknown method name is given, the command with the
same name as the given method within the namespace <tt class="samp">::dom::domDoc</tt> is
tried to be executed. This allows quick method additions on Tcl level.</p><p>Newly created nodes are appended to a hidden fragment list. If they
are not moved into the tree they are automatically deleted as soon as the whole
document gets deleted.</p>

    <h2><a name="SECTid0x1efaea0">SEE ALSO</a></h2><p class="seealso">dom, domNode</p>

    <h2><a name="SECTid0x1efb230">KEYWORDS</a></h2><p class="keywords">
<a class="keyword" href="keyword-index.html#KW-DOMnodecreation">DOM node creation</a>, <a class="keyword" href="keyword-index.html#KW-documentelement">document element</a>
</p>

</div><hr class="navsep"><div class="navbar" align="center">
<a class="navaid" href="index.html">Contents</a> · <a class="navaid" href="category-index.html">Index</a> · <a class="navaid" href="keyword-index.html">Keywords</a> · <a class="navaid" href="http://tdom.org">Repository</a>
</div>
</body>
</html>






|


|


|

|







 







|






>
>
>
>
>
>
>
>
>
>







 







|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







|

|








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
...
596
597
598
599
600
601
602
603
604
605
606


















































607
608
609
610
611
612
613
...
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
<html>
<head>
<link rel="stylesheet" href="manpage.css"><title>tDOM manual: domDoc</title><meta name="xsl-processor" content="Jochen Loewer (loewerj@hotmail.com), Rolf Ade (rolf@pointsman.de) et. al."><meta name="generator" content="$RCSfile: tmml-html.xsl,v $ $Revision: 1.11 $"><meta charset="utf-8">
</head><body>
<div class="header">
<div class="navbar" align="center">
<a href="#SECTid0x5632bcecc630">NAME</a> · <a href="#SECTid0x5632bce02bb0">SYNOPSIS</a> · <a href="#SECTid0x5632bceaad50">DESCRIPTION </a> · <a href="#SECTid0x5632bcf17a00">SEE ALSO</a> · <a href="#SECTid0x5632bcf17d90">KEYWORDS</a>
</div><hr class="navsep">
</div><div class="body">
  <h2><a name="SECTid0x5632bcecc630">NAME</a></h2><p class="namesection">
<b class="names">domDoc - </b><br>Manipulates an instance of a DOM document object</p>
  
  <h2><a name="SECTid0x5632bce02bb0">SYNOPSIS</a></h2><pre class="syntax">domDocObjCmd <i class="m">method</i> ?<i class="m">arg arg ...</i>?</pre><pre class="syntax">domDoc <i class="m">docToken</i> <i class="m">method</i> ?<i class="m">arg arg ...</i>?</pre>

  <h2><a name="SECTid0x5632bceaad50">DESCRIPTION </a></h2><p>This command manipulates one particular instance of a document
object. <i class="m">method</i> indicates a specific method of the document class. These
methods should closely conform to the W3C recommendation "Document Object Model
(Core) Level 1" (<a href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html">http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html</a>). Look
at these documents for a deeper understanding of the functionality.</p><p>The valid methods are:</p><dl class="commandlist">
        
          <dt>
<b class="method">documentElement</b> ?<i class="m">objVar</i>?</dt>
................................................................................
          <dt><b class="method">getDefaultOutputMethod</b></dt>
          <dd>Returns the default output method of the document. This is
usually a result of a XSLT transformation.</dd>
        

      
        <dt>
<b class="method">asXML</b> <b class="option">?-indent none/tabs/1..8?</b> <b class="option">?-channel channelId?</b> <b class="option">?-escapeNonASCII?</b> <b class="option">?-doctypeDeclaration &lt;boolean&gt;?</b> <b class="option">-xmlDeclaration &lt;boolean&gt;?</b> <b class="option">-encString &lt;string&gt;</b> <b class="option">?-escapeAllQuot?</b> <b class="option">?-indentAttrs?</b> <b class="option">?-nogtescape?</b> <b class="option">?-noEmptyElementTag?</b>
</dt>
        <dd>
<p>Returns the DOM tree as an (optional indented) XML
        string or sends the output directly to the given
        channelId.</p>

        <p>The -indent option requires "no", "none", "tabs" or a
        natural number betwenn 0 and 8, both included, as value. With
        the values "no" or "none" no additional white space outside of
        markup will be added to the serialization. I. Otherwise, it's
        a "pretty-print" serialization, due to inserting white space
        between end and the next start tag according to the nesting
        level. The level indentation wide is given with the number. If
        the value is "tabs", then indentation is done with tabs, one
        tab per level.</p>
        
        <p>If the option <i class="m">-escapeNonASCII</i> is given,
        every non 7 bit ASCII character in attribute values or element
        PCDATA content will be escaped as character reference in
        decimal representation.</p>

        <p>The flag <i class="m">-doctypeDeclaration</i> determines whether
        there will be a DOCTYPE declaration emitted before the first
................................................................................
<i class="m">xpathQuery</i> to the document. The context node of the query is the root
node in the sense of the XPath recommendation (not the document element). The
result can be a string/value, a list of strings, a list of nodes or a list
of attribute name / value pairs. If <i class="m">typeVar</i> is given
the result type name is stored into that variable (empty,
bool, number, string, nodes, attrnodes or mixed).</p>

          <p>See the documentation of the of the
          <b class="command">domNode</b> command method
          <b class="method">selectNodes</b> for a detailed description of
          the arguments.</p>


















































          </dd>
      

      
        <dt>
<b class="method">baseURI</b> <i class="m">?URI?</i>
</dt>
................................................................................

  </dl><p>Otherwise, if an unknown method name is given, the command with the
same name as the given method within the namespace <tt class="samp">::dom::domDoc</tt> is
tried to be executed. This allows quick method additions on Tcl level.</p><p>Newly created nodes are appended to a hidden fragment list. If they
are not moved into the tree they are automatically deleted as soon as the whole
document gets deleted.</p>

    <h2><a name="SECTid0x5632bcf17a00">SEE ALSO</a></h2><p class="seealso">dom, domNode</p>

    <h2><a name="SECTid0x5632bcf17d90">KEYWORDS</a></h2><p class="keywords">
<a class="keyword" href="keyword-index.html#KW-DOMnodecreation">DOM node creation</a>, <a class="keyword" href="keyword-index.html#KW-documentelement">document element</a>
</p>

</div><hr class="navsep"><div class="navbar" align="center">
<a class="navaid" href="index.html">Contents</a> · <a class="navaid" href="category-index.html">Index</a> · <a class="navaid" href="keyword-index.html">Keywords</a> · <a class="navaid" href="http://tdom.org">Repository</a>
</div>
</body>
</html>

Changes to doc/domDoc.n.

233
234
235
236
237
238
239
240
241
242
243
244
245
246










247
248
249
250
251
252
253
...
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
Tcl object commands (for nodes, fragment/new nodes, the document object itself)
and the underlying DOM tree.
.TP
\&\fB\fBgetDefaultOutputMethod\fP
\&\fRReturns the default output method of the document. This is
usually a result of a XSLT transformation.
.TP
\&\fB\fBasXML\fP \fB?-indent none/1..8?\fP \fB?-channel channelId?\fP \fB?-escapeNonASCII?\fP \fB?-doctypeDeclaration <boolean>?\fP \fB-xmlDeclaration <boolean>?\fP \fB-encString <string>\fP \fB?-escapeAllQuot?\fP \fB?-indentAttrs?\fP \fB?-nogtescape?\fP \fB?-noEmptyElementTag?\fP
\&\fR
.RS
.PP
Returns the DOM tree as an (optional indented) XML
string or sends the output directly to the given
channelId.










.PP
If the option \fI-escapeNonASCII\fR is given,
every non 7 bit ASCII character in attribute values or element
PCDATA content will be escaped as character reference in
decimal representation.
.PP
The flag \fI-doctypeDeclaration\fR determines whether
................................................................................
\&\fIxpathQuery\fR to the document. The context node of the query is the root
node in the sense of the XPath recommendation (not the document element). The
result can be a string/value, a list of strings, a list of nodes or a list
of attribute name / value pairs. If \fItypeVar\fR is given
the result type name is stored into that variable (empty,
bool, number, string, nodes, attrnodes or mixed).
.PP
The argument \fIxpathQuery\fR has to be a valid XPath
expression. However, there is one exception to that rule. Tcl variable
names can appear in the XPath statement at any position where it is
legal according to the rules of the XPath syntax to put an XPath
variable. The value of the variable is substituted for the variable
name. Ignoring the syntax rules of XPath the Tcl variable name may be
any legal Tcl var name: local variables, global variables, array
entries and so on.  The value will always be seen as string literal by
the xpath engine. Cast the value explicitly with the according xpath
functions (number(), boolean()) to another data type, if needed.
.PP
The option \fI-namespaces\fR expects a tcl list with prefix /
namespace pairs as argument. If this option is not given, then any
namespace prefix within the xpath expression will be first resolved
against the list of prefix / namespace pairs set with the
selectNodesNamespaces method for the document the node belongs to. If
this fails, then the namespace definitions in scope of the context
node will be used to resolve the prefix. If this option is given, any
namespace prefix within the xpath expression will be first resolved
against that given list (and ignoring the document global prefix /
namespace list). If the list binds the same prefix to different
namespaces, then the first binding will win.  If this fails, then the
namespace definitions in scope of the context node will be used to
resolve the prefix, as usual.
.PP
If the \fI-cache\fR option is used with a true value, then the
\&\fIxpathQuery\fR will be looked up in a document specific cache. If
the query is found, then the stored pre-compiled query will be used.
If the query isn't found, it will be compiled and stored in the cache,
for use in further calls. Please notice, that the \fIxpathQuery\fR as
given as string is used as key for the cache. This means that equal
XPath expressions, which differ only in white space, are treated as
different cache entries. Special care is needed if the XPath
expression includes namespace prefixes or references to tcl variables.
Both namespace prefixes and tcl variable references will be resolved
according to the XML prefix namespace mappings and tcl variable values
at expression compilation time. If the same XPath expression is used
later on in a context with other XML prefix namespace mappings or
values of the used tcl variables, make sure to first remove the
compiled expression from the cache with the help of the
\&\fBdeleteXPathCache\fP method, to force a recompilation.
Without using the \fI-cache\fR option such consideration is never
needed.
.PP
Examples:

          
.CS
set paragraphNodes [$node selectNodes {chapter[3]//para[@type='warning' or @type='error'} ]
foreach paragraph $paragraphNodes {
    lappend  values [$paragraph selectNodes attribute::type]
}

set doc [dom parse {<doc xmlns="http://www.defaultnamespace.org"><child/></doc>}]
set root [$doc documentElement]
set childNodes [$root selectNodes -namespaces {default http://www.defaultnamespace.org} default:child]
.CE
.RE
.TP
\&\fB\fBbaseURI\fP \fI?URI?\fB
\&\fRReturns the present baseURI of the document. If the optional
argument URI is given, sets the base URI of the document to the given URI.
.TP
\&\fB\fBappendFromScript\fP \fItclScript\fB







|






>
>
>
>
>
>
>
>
>
>







 







|
|
|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
...
625
626
627
628
629
630
631
632
633
634
635
636
637



















































638
639
640
641
642
643
644
Tcl object commands (for nodes, fragment/new nodes, the document object itself)
and the underlying DOM tree.
.TP
\&\fB\fBgetDefaultOutputMethod\fP
\&\fRReturns the default output method of the document. This is
usually a result of a XSLT transformation.
.TP
\&\fB\fBasXML\fP \fB?-indent none/tabs/1..8?\fP \fB?-channel channelId?\fP \fB?-escapeNonASCII?\fP \fB?-doctypeDeclaration <boolean>?\fP \fB-xmlDeclaration <boolean>?\fP \fB-encString <string>\fP \fB?-escapeAllQuot?\fP \fB?-indentAttrs?\fP \fB?-nogtescape?\fP \fB?-noEmptyElementTag?\fP
\&\fR
.RS
.PP
Returns the DOM tree as an (optional indented) XML
string or sends the output directly to the given
channelId.
.PP
The -indent option requires "no", "none", "tabs" or a
natural number betwenn 0 and 8, both included, as value. With
the values "no" or "none" no additional white space outside of
markup will be added to the serialization. I. Otherwise, it's
a "pretty-print" serialization, due to inserting white space
between end and the next start tag according to the nesting
level. The level indentation wide is given with the number. If
the value is "tabs", then indentation is done with tabs, one
tab per level.
.PP
If the option \fI-escapeNonASCII\fR is given,
every non 7 bit ASCII character in attribute values or element
PCDATA content will be escaped as character reference in
decimal representation.
.PP
The flag \fI-doctypeDeclaration\fR determines whether
................................................................................
\&\fIxpathQuery\fR to the document. The context node of the query is the root
node in the sense of the XPath recommendation (not the document element). The
result can be a string/value, a list of strings, a list of nodes or a list
of attribute name / value pairs. If \fItypeVar\fR is given
the result type name is stored into that variable (empty,
bool, number, string, nodes, attrnodes or mixed).
.PP
See the documentation of the of the
.TP
\&\fBdomNode
\&\fR command method
\&\fBselectNodes\fP for a detailed description of
the arguments.



















































.RE
.TP
\&\fB\fBbaseURI\fP \fI?URI?\fB
\&\fRReturns the present baseURI of the document. If the optional
argument URI is given, sets the base URI of the document to the given URI.
.TP
\&\fB\fBappendFromScript\fP \fItclScript\fB

Changes to doc/domDoc.xml.

107
108
109
110
111
112
113
114
115
116
117
118










119
120
121
122
123
124
125
...
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
        <commanddef>
          <command><method>getDefaultOutputMethod</method></command>
          <desc>Returns the default output method of the document. This is
usually a result of a XSLT transformation.</desc>
        </commanddef>

      <commanddef>
        <command><method>asXML</method> <option>?-indent none/1..8?</option> <option>?-channel channelId?</option> <option>?-escapeNonASCII?</option> <option>?-doctypeDeclaration &lt;boolean&gt;?</option> <option>-xmlDeclaration &lt;boolean&gt;?</option> <option>-encString &lt;string&gt;</option> <option>?-escapeAllQuot?</option> <option>?-indentAttrs?</option> <option>?-nogtescape?</option> <option>?-noEmptyElementTag?</option></command>
        <desc><p>Returns the DOM tree as an (optional indented) XML
        string or sends the output directly to the given
        channelId.</p>











        <p>If the option <m>-escapeNonASCII</m> is given,
        every non 7 bit ASCII character in attribute values or element
        PCDATA content will be escaped as character reference in
        decimal representation.</p>

        <p>The flag <m>-doctypeDeclaration</m> determines whether
        there will be a DOCTYPE declaration emitted before the first
................................................................................
result can be a string/value, a list of strings, a list of nodes or a list
of attribute name / value pairs. If <m>typeVar</m> is given
the result type name is stored into that variable (empty,
bool, number, string, nodes, attrnodes or mixed).</p>

          <p>See the documentation of the of the
          <command>domNode</command> command method
          <method>>selectNodes</method> for a detailed description of
          the arguments.</p>
          </desc>
      </commanddef>

      <commanddef>
        <command><method>baseURI</method> <m>?URI?</m></command>
        <desc>Returns the present baseURI of the document. If the optional 







|




>
>
>
>
>
>
>
>
>
>







 







|







107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
...
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
        <commanddef>
          <command><method>getDefaultOutputMethod</method></command>
          <desc>Returns the default output method of the document. This is
usually a result of a XSLT transformation.</desc>
        </commanddef>

      <commanddef>
        <command><method>asXML</method> <option>?-indent none/tabs/1..8?</option> <option>?-channel channelId?</option> <option>?-escapeNonASCII?</option> <option>?-doctypeDeclaration &lt;boolean&gt;?</option> <option>-xmlDeclaration &lt;boolean&gt;?</option> <option>-encString &lt;string&gt;</option> <option>?-escapeAllQuot?</option> <option>?-indentAttrs?</option> <option>?-nogtescape?</option> <option>?-noEmptyElementTag?</option></command>
        <desc><p>Returns the DOM tree as an (optional indented) XML
        string or sends the output directly to the given
        channelId.</p>

        <p>The -indent option requires "no", "none", "tabs" or a
        natural number betwenn 0 and 8, both included, as value. With
        the values "no" or "none" no additional white space outside of
        markup will be added to the serialization. I. Otherwise, it's
        a "pretty-print" serialization, due to inserting white space
        between end and the next start tag according to the nesting
        level. The level indentation wide is given with the number. If
        the value is "tabs", then indentation is done with tabs, one
        tab per level.</p>
        
        <p>If the option <m>-escapeNonASCII</m> is given,
        every non 7 bit ASCII character in attribute values or element
        PCDATA content will be escaped as character reference in
        decimal representation.</p>

        <p>The flag <m>-doctypeDeclaration</m> determines whether
        there will be a DOCTYPE declaration emitted before the first
................................................................................
result can be a string/value, a list of strings, a list of nodes or a list
of attribute name / value pairs. If <m>typeVar</m> is given
the result type name is stored into that variable (empty,
bool, number, string, nodes, attrnodes or mixed).</p>

          <p>See the documentation of the of the
          <command>domNode</command> command method
          <method>selectNodes</method> for a detailed description of
          the arguments.</p>
          </desc>
      </commanddef>

      <commanddef>
        <command><method>baseURI</method> <m>?URI?</m></command>
        <desc>Returns the present baseURI of the document. If the optional 

Changes to doc/domNode.html.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
...
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
<html>
<head>
<link rel="stylesheet" href="manpage.css"><title>tDOM manual: domNode</title><meta name="xsl-processor" content="Jochen Loewer (loewerj@hotmail.com), Rolf Ade (rolf@pointsman.de) et. al."><meta name="generator" content="$RCSfile: tmml-html.xsl,v $ $Revision: 1.11 $"><meta charset="utf-8">
</head><body>
<div class="header">
<div class="navbar" align="center">
<a href="#SECTid0x561e82e6b640">NAME</a> · <a href="#SECTid0x561e82d945a0">SYNOPSIS</a> · <a href="#SECTid0x561e82e49c80"> DESCRIPTION </a> · <a href="#SECTid0x561e82ebbf40">SEE ALSO</a> · <a href="#SECTid0x561e82ebc2d0">KEYWORDS</a>
</div><hr class="navsep">
</div><div class="body">
  <h2><a name="SECTid0x561e82e6b640">NAME</a></h2><p class="namesection">
<b class="names">domNode - </b><br>Manipulates an instance of a DOM node object</p>



  <h2><a name="SECTid0x561e82d945a0">SYNOPSIS</a></h2><pre class="syntax">$nodeObject <i class="m">method</i> <i class="m">arg arg ...</i>
</pre><pre class="syntax">domNode <i class="m">nodeToken</i> <i class="m">method</i> <i class="m">arg arg ...</i>
</pre>
  <h2><a name="SECTid0x561e82e49c80"> DESCRIPTION </a></h2><p>This command manipulates one particular instance of a DOM node object.
<i class="m">method</i> indicates a specific method of the node class. These methods
should closely conform to the W3C recommendation "Document Object Model
(Core) Level 1" (<a href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html">http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html</a>)
as well to parts of the W3C draft "XML Pointer Language (XPointer)"
(<a href="http://www.w3.org/TR/1998/WD-xptr-19980303">http://www.w3.org/TR/1998/WD-xptr-19980303</a>).
Please note, that the XPointer methods are deprecated. Use DOM methods
or XPath expressions instead of them.</p><p>The selectNodes method implements the "XML Path
................................................................................
you must specify the attribute name with prefix, even if you want to set an
already existing attribute to a new value. While searching, if the attribute
already exists, only the given <i class="m">uri</i> and the localname of the
<i class="m">qualifiedName</i> is used.</p>

        <pre class="example">$node setAttributeNS "http://some.uri.com/wow" prefix:attr1 attrValue</pre>

<p>If the uri is the empty string and the attribute name doesn't have
a prefix, this method has the same effect as the method
<b>setAttribute</b>.</p>

        <pre class="example">$node setAttributeNS "" attri "some Value"</pre>

<p>With the exceptions of the special prefixes "xmlns" and "xml" you
always must provide a non empty <i class="m">uri</i> if your <i class="m">qualifiedName</i> has a
prefix. It is not recommended to set xml namespace declarations. The effects are complicated and not always obvious up to resulting a not well-formed serializations after further processing.</p>
................................................................................
 the namespace <i class="m">uri</i>.</dd>
      

      
        <dt>
<b class="method">attributes</b> <b class="option">?attributeNamePattern?</b>
</dt>
        <dd>Returns information about the attriubtes matching the
        <i class="m">attributeNamePattern</i>. If <i class="m">attributeNamePattern</i>
        isn't given, information about all attributes are returned.
        The return value is a Tcl list, the elements just the
        attriubute name in case of non namespaced attriubtes and three
        element sublists for namespaced attributes. n case of an
        "ordinary" namespaced attribute, the sublist elements are
        {&lt;localname&gt; &lt;prefix&gt; &lt;namespace_uri&gt;}. In the special case of
        an xml namespace declaration it is {&lt;the prefix defined&gt;
        &lt;localname&gt; ""}.
        </dd>
      
................................................................................
        <dt><b class="method">asList</b></dt>
        <dd>Returns the DOM substree starting form the current node as a
nested Tcl list.</dd>
      

      
        <dt>
<b class="method">asXML</b> <b class="option">?-indent none/1..8?</b> <b class="option">?-channel channelId?</b> <b class="option">?-escapeNonASCII?</b> <b class="option">-xmlDeclaration &lt;boolean&gt;?</b> <b class="option">-encString &lt;string&gt;</b> <b class="option">?-escapeAllQuot?</b> <b class="option">?-indentAttrs?</b> <b class="option">?-nogtescape?</b> <b class="option">?-noEmptyElementTag?</b>
</dt>
        <dd>
<p>Returns the DOM substree starting from the current
        node as the root node of the result as an (optional indented)
        XML string or sends the output directly to the given
        channelId.</p>

        <p>If the option <i class="m">-escapeNonASCII</i> is given,
        every non 7 bit ASCII character in attribute values or element
        PCDATA content will be escaped as character reference in
        decimal representation.</p>

        <p>The flag <i class="m">-xmlDeclaration</i> determines whether there
        will be an XML Declaration and a newline emitted before
        anything else. The default is, to do not. If this flag is
        given with a true argument then</p>

        <p>
<i class="m">-encString</i> sets the encoding value in the XML
        Declaration. Otherwise, this option is ignored. Please note,
        that this option just enhance the string representation of the
        generated XML Declaration with an encoding information string,
        nothing more. It's up to the user to handle encoding in case
        of writing to a channel or reparsing.</p>
            
        <p>If the option <i class="m">-escapeAllQuot</i> is given,
        quotation marks will be escaped with &amp;quot; even in text
        content of elements.</p>

        <p>If the option <i class="m">-indentAttrs</i> is
        given, then attributes will each be separated with newlines
        and indented to the same level as the parent node plus the
        value given as argument to <i class="m">-indentAttrs</i> (0..8).</p>

        <p>If the option <i class="m">-nogtescape</i> is given then the
        character '&gt;' won't get escaped in attribute values and text
        content of elements. The default is to escape this
        character.</p>

        <p>If the option <i class="m">-noEmptyElementTag</i> is given then no
        empty tag syntax will be used. Instead, if an element has
        empty content it will be serialized with an element start tag
        and an immediately following element end tag.</p>
</dd>

      

      
        <dt>
<b class="method">asHTML</b> <b class="option">?-channel channelId?</b>
<b class="option">?-escapeNonASCII?</b>  <b class="option">?-htmlEntities?</b>
</dt>
................................................................................
      

    </dl><p>Otherwise, if an unknown method name is given, the command with the same
name as the given method within the namespace <tt class="l">::dom::domNode</tt> is tried to
be executed. This allows quick method additions on Tcl level.</p>


  <h2><a name="SECTid0x561e82ebbf40">SEE ALSO</a></h2><p class="seealso">dom, domDoc</p>
  
  <h2><a name="SECTid0x561e82ebc2d0">KEYWORDS</a></h2><p class="keywords">
<a class="keyword" href="keyword-index.html#KW-XML">XML</a>, <a class="keyword" href="keyword-index.html#KW-DOM">DOM</a>, <a class="keyword" href="keyword-index.html#KW-document">document</a>, <a class="keyword" href="keyword-index.html#KW-node">node</a>, <a class="keyword" href="keyword-index.html#KW-parsing">parsing</a>
</p>
  
</div><hr class="navsep"><div class="navbar" align="center">
<a class="navaid" href="index.html">Contents</a> · <a class="navaid" href="category-index.html">Index</a> · <a class="navaid" href="keyword-index.html">Keywords</a> · <a class="navaid" href="http://tdom.org">Repository</a>
</div>
</body>
</html>






|


|




|


|







 







|
|







 







|



|







 







|







|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
|
<







 







|

|








1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
...
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
...
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516

































517

518
519
520
521
522
523
524
...
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
<html>
<head>
<link rel="stylesheet" href="manpage.css"><title>tDOM manual: domNode</title><meta name="xsl-processor" content="Jochen Loewer (loewerj@hotmail.com), Rolf Ade (rolf@pointsman.de) et. al."><meta name="generator" content="$RCSfile: tmml-html.xsl,v $ $Revision: 1.11 $"><meta charset="utf-8">
</head><body>
<div class="header">
<div class="navbar" align="center">
<a href="#SECTid0x55a2288bc630">NAME</a> · <a href="#SECTid0x55a2287f2bb0">SYNOPSIS</a> · <a href="#SECTid0x55a22889ac90"> DESCRIPTION </a> · <a href="#SECTid0x55a22890bf10">SEE ALSO</a> · <a href="#SECTid0x55a22890c2a0">KEYWORDS</a>
</div><hr class="navsep">
</div><div class="body">
  <h2><a name="SECTid0x55a2288bc630">NAME</a></h2><p class="namesection">
<b class="names">domNode - </b><br>Manipulates an instance of a DOM node object</p>



  <h2><a name="SECTid0x55a2287f2bb0">SYNOPSIS</a></h2><pre class="syntax">$nodeObject <i class="m">method</i> <i class="m">arg arg ...</i>
</pre><pre class="syntax">domNode <i class="m">nodeToken</i> <i class="m">method</i> <i class="m">arg arg ...</i>
</pre>
  <h2><a name="SECTid0x55a22889ac90"> DESCRIPTION </a></h2><p>This command manipulates one particular instance of a DOM node object.
<i class="m">method</i> indicates a specific method of the node class. These methods
should closely conform to the W3C recommendation "Document Object Model
(Core) Level 1" (<a href="http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html">http://www.w3.org/TR/REC-DOM-Level-1/level-one-core.html</a>)
as well to parts of the W3C draft "XML Pointer Language (XPointer)"
(<a href="http://www.w3.org/TR/1998/WD-xptr-19980303">http://www.w3.org/TR/1998/WD-xptr-19980303</a>).
Please note, that the XPointer methods are deprecated. Use DOM methods
or XPath expressions instead of them.</p><p>The selectNodes method implements the "XML Path
................................................................................
you must specify the attribute name with prefix, even if you want to set an
already existing attribute to a new value. While searching, if the attribute
already exists, only the given <i class="m">uri</i> and the localname of the
<i class="m">qualifiedName</i> is used.</p>

        <pre class="example">$node setAttributeNS "http://some.uri.com/wow" prefix:attr1 attrValue</pre>

<p>If the uri is the empty string and the attribute name has no
prefix, this method has the same effect as the method
<b>setAttribute</b>.</p>

        <pre class="example">$node setAttributeNS "" attri "some Value"</pre>

<p>With the exceptions of the special prefixes "xmlns" and "xml" you
always must provide a non empty <i class="m">uri</i> if your <i class="m">qualifiedName</i> has a
prefix. It is not recommended to set xml namespace declarations. The effects are complicated and not always obvious up to resulting a not well-formed serializations after further processing.</p>
................................................................................
 the namespace <i class="m">uri</i>.</dd>
      

      
        <dt>
<b class="method">attributes</b> <b class="option">?attributeNamePattern?</b>
</dt>
        <dd>Returns information about the attributes matching the
        <i class="m">attributeNamePattern</i>. If <i class="m">attributeNamePattern</i>
        isn't given, information about all attributes are returned.
        The return value is a Tcl list, the elements just the
        attribute name in case of non namespaced attributes and three
        element sublists for namespaced attributes. n case of an
        "ordinary" namespaced attribute, the sublist elements are
        {&lt;localname&gt; &lt;prefix&gt; &lt;namespace_uri&gt;}. In the special case of
        an xml namespace declaration it is {&lt;the prefix defined&gt;
        &lt;localname&gt; ""}.
        </dd>
      
................................................................................
        <dt><b class="method">asList</b></dt>
        <dd>Returns the DOM substree starting form the current node as a
nested Tcl list.</dd>
      

      
        <dt>
<b class="method">asXML</b> <b class="option">?-indent none/tabs/1..8?</b> <b class="option">?-channel channelId?</b> <b class="option">?-escapeNonASCII?</b> <b class="option">?-doctypeDeclaration &lt;boolean&gt;?</b> <b class="option">-xmlDeclaration &lt;boolean&gt;?</b> <b class="option">-encString &lt;string&gt;</b> <b class="option">?-escapeAllQuot?</b> <b class="option">?-indentAttrs?</b> <b class="option">?-nogtescape?</b> <b class="option">?-noEmptyElementTag?</b>
</dt>
        <dd>
<p>Returns the DOM substree starting from the current
        node as the root node of the result as an (optional indented)
        XML string or sends the output directly to the given
        channelId.</p>

        <p>See the documentation of the of the <b class="command"> domDoc
        </b> command method <b class="method">asXML</b> for a
        detailed description of the arguments.</p>

































        </dd>

      

      
        <dt>
<b class="method">asHTML</b> <b class="option">?-channel channelId?</b>
<b class="option">?-escapeNonASCII?</b>  <b class="option">?-htmlEntities?</b>
</dt>
................................................................................
      

    </dl><p>Otherwise, if an unknown method name is given, the command with the same
name as the given method within the namespace <tt class="l">::dom::domNode</tt> is tried to
be executed. This allows quick method additions on Tcl level.</p>


  <h2><a name="SECTid0x55a22890bf10">SEE ALSO</a></h2><p class="seealso">dom, domDoc</p>
  
  <h2><a name="SECTid0x55a22890c2a0">KEYWORDS</a></h2><p class="keywords">
<a class="keyword" href="keyword-index.html#KW-XML">XML</a>, <a class="keyword" href="keyword-index.html#KW-DOM">DOM</a>, <a class="keyword" href="keyword-index.html#KW-document">document</a>, <a class="keyword" href="keyword-index.html#KW-node">node</a>, <a class="keyword" href="keyword-index.html#KW-parsing">parsing</a>
</p>
  
</div><hr class="navsep"><div class="navbar" align="center">
<a class="navaid" href="index.html">Contents</a> · <a class="navaid" href="category-index.html">Index</a> · <a class="navaid" href="keyword-index.html">Keywords</a> · <a class="navaid" href="http://tdom.org">Repository</a>
</div>
</body>
</html>

Changes to doc/domNode.n.

296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
...
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518

519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558


        
.CS
$node setAttributeNS "http://some.uri.com/wow" prefix:attr1 attrValue
.CE
.PP
If the uri is the empty string and the attribute name doesn't have
a prefix, this method has the same effect as the method
\&\fBsetAttribute\fR.


        
.CS
$node setAttributeNS "" attri "some Value"
.CE
................................................................................
.RE
.TP
\&\fB\fBremoveAttributeNS\fP \fIuri\fB \fIlocalName\fB
\&\fRRemoves the attribute with the local name \fIlocalName\fR within
the namespace \fIuri\fR.
.TP
\&\fB\fBattributes\fP \fB?attributeNamePattern?\fP
\&\fRReturns information about the attriubtes matching the
\&\fIattributeNamePattern\fR. If \fIattributeNamePattern\fR
isn't given, information about all attributes are returned.
The return value is a Tcl list, the elements just the
attriubute name in case of non namespaced attriubtes and three
element sublists for namespaced attributes. n case of an
"ordinary" namespaced attribute, the sublist elements are
{<localname> <prefix> <namespace_uri>}. In the special case of
an xml namespace declaration it is {<the prefix defined>
<localname> ""}.
.TP
\&\fB\fBattributeNames\fP \fB?attributeNamePattern?\fP
................................................................................
\&\fRReturns the column number of that node in the originally parsed
XML.
.TP
\&\fB\fBasList\fP
\&\fRReturns the DOM substree starting form the current node as a
nested Tcl list.
.TP
\&\fB\fBasXML\fP \fB?-indent none/1..8?\fP \fB?-channel channelId?\fP \fB?-escapeNonASCII?\fP \fB-xmlDeclaration <boolean>?\fP \fB-encString <string>\fP \fB?-escapeAllQuot?\fP \fB?-indentAttrs?\fP \fB?-nogtescape?\fP \fB?-noEmptyElementTag?\fP
\&\fR
.RS
.PP
Returns the DOM substree starting from the current
node as the root node of the result as an (optional indented)
XML string or sends the output directly to the given
channelId.
.PP
If the option \fI-escapeNonASCII\fR is given,
every non 7 bit ASCII character in attribute values or element

PCDATA content will be escaped as character reference in
decimal representation.
.PP
The flag \fI-xmlDeclaration\fR determines whether there
will be an XML Declaration and a newline emitted before
anything else. The default is, to do not. If this flag is
given with a true argument then
.PP
\&\fI-encString\fR sets the encoding value in the XML
Declaration. Otherwise, this option is ignored. Please note,
that this option just enhance the string representation of the
generated XML Declaration with an encoding information string,
nothing more. It's up to the user to handle encoding in case
of writing to a channel or reparsing.
.PP
If the option \fI-escapeAllQuot\fR is given,
quotation marks will be escaped with &quot; even in text
content of elements.
.PP
If the option \fI-indentAttrs\fR is
given, then attributes will each be separated with newlines
and indented to the same level as the parent node plus the
value given as argument to \fI-indentAttrs\fR (0..8).
.PP
If the option \fI-nogtescape\fR is given then the
character '>' won't get escaped in attribute values and text
content of elements. The default is to escape this
character.
.PP
If the option \fI-noEmptyElementTag\fR is given then no
empty tag syntax will be used. Instead, if an element has
empty content it will be serialized with an element start tag
and an immediately following element end tag.

.RE
.TP
\&\fB\fBasHTML\fP \fB?-channel channelId?\fP \fB?-escapeNonASCII?\fP  \fB?-htmlEntities?\fP
\&\fRReturns the DOM substree starting from the current node as the
root node of the result serialized according to HTML rules (HTML elements are
recognized regardless of case, without end tags for empty HTML elements etc.),
as string or sends the output directly to the given channelId. If the option







|
|







 







|



|







 







|








|
<
>
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>







296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
...
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517

518
519
520































521
522
523
524
525
526
527
528


        
.CS
$node setAttributeNS "http://some.uri.com/wow" prefix:attr1 attrValue
.CE
.PP
If the uri is the empty string and the attribute name has no
prefix, this method has the same effect as the method
\&\fBsetAttribute\fR.


        
.CS
$node setAttributeNS "" attri "some Value"
.CE
................................................................................
.RE
.TP
\&\fB\fBremoveAttributeNS\fP \fIuri\fB \fIlocalName\fB
\&\fRRemoves the attribute with the local name \fIlocalName\fR within
the namespace \fIuri\fR.
.TP
\&\fB\fBattributes\fP \fB?attributeNamePattern?\fP
\&\fRReturns information about the attributes matching the
\&\fIattributeNamePattern\fR. If \fIattributeNamePattern\fR
isn't given, information about all attributes are returned.
The return value is a Tcl list, the elements just the
attribute name in case of non namespaced attributes and three
element sublists for namespaced attributes. n case of an
"ordinary" namespaced attribute, the sublist elements are
{<localname> <prefix> <namespace_uri>}. In the special case of
an xml namespace declaration it is {<the prefix defined>
<localname> ""}.
.TP
\&\fB\fBattributeNames\fP \fB?attributeNamePattern?\fP
................................................................................
\&\fRReturns the column number of that node in the originally parsed
XML.
.TP
\&\fB\fBasList\fP
\&\fRReturns the DOM substree starting form the current node as a
nested Tcl list.
.TP
\&\fB\fBasXML\fP \fB?-indent none/tabs/1..8?\fP \fB?-channel channelId?\fP \fB?-escapeNonASCII?\fP \fB?-doctypeDeclaration <boolean>?\fP \fB-xmlDeclaration <boolean>?\fP \fB-encString <string>\fP \fB?-escapeAllQuot?\fP \fB?-indentAttrs?\fP \fB?-nogtescape?\fP \fB?-noEmptyElementTag?\fP
\&\fR
.RS
.PP
Returns the DOM substree starting from the current
node as the root node of the result as an (optional indented)
XML string or sends the output directly to the given
channelId.
.PP
See the documentation of the of the

.TP
\&\fB domDoc
\&\fR command method \fBasXML\fP for a































detailed description of the arguments.
.RE
.TP
\&\fB\fBasHTML\fP \fB?-channel channelId?\fP \fB?-escapeNonASCII?\fP  \fB?-htmlEntities?\fP
\&\fRReturns the DOM substree starting from the current node as the
root node of the result serialized according to HTML rules (HTML elements are
recognized regardless of case, without end tags for empty HTML elements etc.),
as string or sends the output directly to the given channelId. If the option

Changes to doc/domNode.xml.

445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
      <commanddef>
        <command><method>asList</method></command>
        <desc>Returns the DOM substree starting form the current node as a
nested Tcl list.</desc>
      </commanddef>

      <commanddef>
        <command><method>asXML</method> <option>?-indent none/1..8?</option> <option>?-channel channelId?</option> <option>?-escapeNonASCII?</option> <option>-xmlDeclaration &lt;boolean&gt;?</option> <option>-encString &lt;string&gt;</option> <option>?-escapeAllQuot?</option> <option>?-indentAttrs?</option> <option>?-nogtescape?</option> <option>?-noEmptyElementTag?</option></command>
        <desc><p>Returns the DOM substree starting from the current
        node as the root node of the result as an (optional indented)
        XML string or sends the output directly to the given
        channelId.</p>

        <p>If the option <m>-escapeNonASCII</m> is given,
        every non 7 bit ASCII character in attribute values or element
        PCDATA content will be escaped as character reference in
        decimal representation.</p>

        <p>The flag <m>-xmlDeclaration</m> determines whether there
        will be an XML Declaration and a newline emitted before
        anything else. The default is, to do not. If this flag is
        given with a true argument then</p>

        <p><m>-encString</m> sets the encoding value in the XML
        Declaration. Otherwise, this option is ignored. Please note,
        that this option just enhance the string representation of the
        generated XML Declaration with an encoding information string,
        nothing more. It's up to the user to handle encoding in case
        of writing to a channel or reparsing.</p>
            
        <p>If the option <m>-escapeAllQuot</m> is given,
        quotation marks will be escaped with &amp;quot; even in text
        content of elements.</p>

        <p>If the option <m>-indentAttrs</m> is
        given, then attributes will each be separated with newlines
        and indented to the same level as the parent node plus the
        value given as argument to <m>-indentAttrs</m> (0..8).</p>

        <p>If the option <m>-nogtescape</m> is given then the
        character '>' won't get escaped in attribute values and text
        content of elements. The default is to escape this
        character.</p>

        <p>If the option <m>-noEmptyElementTag</m> is given then no
        empty tag syntax will be used. Instead, if an element has
        empty content it will be serialized with an element start tag
        and an immediately following element end tag.</p></desc>

      </commanddef>

      <commanddef>
        <command><method>asHTML</method> <option>?-channel channelId?</option>
<option>?-escapeNonASCII?</option>  <option>?-htmlEntities?</option></command>
        <desc>Returns the DOM substree starting from the current node as the
root node of the result serialized according to HTML rules (HTML elements are







|





|
|
|
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
































462
463
464
465
466
467
468
      <commanddef>
        <command><method>asList</method></command>
        <desc>Returns the DOM substree starting form the current node as a
nested Tcl list.</desc>
      </commanddef>

      <commanddef>
        <command><method>asXML</method> <option>?-indent none/tabs/1..8?</option> <option>?-channel channelId?</option> <option>?-escapeNonASCII?</option> <option>?-doctypeDeclaration &lt;boolean&gt;?</option> <option>-xmlDeclaration &lt;boolean&gt;?</option> <option>-encString &lt;string&gt;</option> <option>?-escapeAllQuot?</option> <option>?-indentAttrs?</option> <option>?-nogtescape?</option> <option>?-noEmptyElementTag?</option></command>
        <desc><p>Returns the DOM substree starting from the current
        node as the root node of the result as an (optional indented)
        XML string or sends the output directly to the given
        channelId.</p>

        <p>See the documentation of the of the <command> domDoc
        </command> command method <method>asXML</method> for a
        detailed description of the arguments.</p>
        </desc>
































      </commanddef>

      <commanddef>
        <command><method>asHTML</method> <option>?-channel channelId?</option>
<option>?-escapeNonASCII?</option>  <option>?-htmlEntities?</option></command>
        <desc>Returns the DOM substree starting from the current node as the
root node of the result serialized according to HTML rules (HTML elements are

Changes to generic/tcldom.c.

157
158
159
160
161
162
163


164
165
166
167
168
169
170
...
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
...
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
...
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
....
2872
2873
2874
2875
2876
2877
2878

2879




2880

2881
2882
2883
2884
2885
2886
2887
....
2908
2909
2910
2911
2912
2913
2914

2915




2916
2917
2918




2919
2920
2921
2922
2923
2924
2925
....
3003
3004
3005
3006
3007
3008
3009

3010




3011

3012
3013
3014
3015
3016
3017
3018
....
3098
3099
3100
3101
3102
3103
3104

3105
3106
3107
3108
3109
3110
3111
....
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
....
3189
3190
3191
3192
3193
3194
3195
3196
3197




3198

3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212

3213




3214

3215
3216
3217
3218
3219
3220
3221
....
3223
3224
3225
3226
3227
3228
3229
3230
3231




3232

3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246

3247




3248

3249
3250
3251
3252
3253
3254
3255
....
3262
3263
3264
3265
3266
3267
3268

3269
3270
3271
3272
3273
3274
3275
....
3362
3363
3364
3365
3366
3367
3368



3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
....
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479



3480
3481

3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499



3500
3501

3502
3503
3504
3505
3506
3507
3508
....
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
....
3810
3811
3812
3813
3814
3815
3816





3817
3818
3819
3820
3821
3822
3823
....
3825
3826
3827
3828
3829
3830
3831
3832

3833
3834
3835
3836
3837
3838
3839
#define SERIALIZE_DOCTYPE_DECLARATION 2
#define SERIALIZE_FOR_ATTR 4 
#define SERIALIZE_ESCAPE_NON_ASCII 8
#define SERIALIZE_HTML_ENTITIES 16
#define SERIALIZE_ESCAPE_ALL_QUOT 32
#define SERIALIZE_NO_GT_ESCAPE 64
#define SERIALIZE_NO_EMPTY_ELEMENT_TAG 128



/*----------------------------------------------------------------------------
|   Module Globals
|
\---------------------------------------------------------------------------*/
#ifndef TCL_THREADS
    static int        storeLineColumn       = 0;
................................................................................
    "    getElementsByTagNameNS uri localname    \n"
    "    createElement tagName ?objVar?          \n"
    "    createElementNS uri tagName ?objVar?    \n"
    "    createCDATASection data ?objVar?        \n"
    "    createTextNode text ?objVar?            \n"
    "    createComment text ?objVar?             \n"
    "    createProcessingInstruction target data ?objVar? \n"
    "    asXML ?-indent <none,0..8>? ?-channel <channel>? ?-escapeNonASCII? ?-escapeAllQuot? ?-doctypeDeclaration <boolean>?\n"
    "    asHTML ?-channel <channelId>? ?-escapeNonASCII? ?-htmlEntities?\n"
    "    asText                                  \n"
    "    asJSON ?-indent <none,0..8>?            \n"
    "    getDefaultOutputMethod                  \n"
    "    publicId ?publicId?                     \n"
    "    systemId ?systemId?                     \n"
    "    internalSubset ?internalSubset?         \n"
................................................................................
    "    baseURI ?URI?                \n"
    "    localName                    \n"
    "    delete                       \n"
    "    getLine                      \n"
    "    getColumn                    \n"
    "    @<attrName> ?defaultValue?   \n"
    "    asList                       \n"
    "    asXML ?-indent <none,0..8>? ?-channel <channel>? ?-escapeNonASCII? ?-escapeAllQuot? ?-doctypeDeclaration <boolean>?\n"
    "    asHTML ?-channel <channelId>? ?-escapeNonASCII? ?-htmlEntities?\n"
    "    asText                       \n"
    "    asJSON ?-indent <none,0..8>? \n"
    "    appendFromList nestedList    \n"
    "    appendFromScript script      \n"
    "    insertBeforeFromScript script ref \n"
    "    appendXML xmlString          \n"
................................................................................
|
\---------------------------------------------------------------------------*/
static Tcl_VarTraceProc  tcldom_docTrace;
static Tcl_CmdDeleteProc tcldom_docCmdDeleteProc;

static void tcldom_treeAsJSON(Tcl_Obj *jstring, domNode *node,
                              Tcl_Channel channel, int indent,
                              int level,
                              int inside);

#ifdef TCL_THREADS

static int tcldom_EvalLocked(Tcl_Interp* interp, Tcl_Obj** objv,
                             domDocument* doc, int flag);

static int tcldom_RegisterDocShared(domDocument* doc);
................................................................................
        writeChars(xmlString, chan, ((domTextNode*)node)->nodeValue,
                                    ((domTextNode*)node)->valueLength);
        writeChars(xmlString, chan, "]]>", 3);
        return;
    }

    if ((indent != -1) && doIndent) {

        for(i=0; i<level; i++) {




            writeChars(xmlString, chan, "        ", indent);

        }
    }

    if (node->nodeType == COMMENT_NODE) {
        writeChars(xmlString, chan, "<!--", 4);
        writeChars(xmlString, chan, ((domTextNode*)node)->nodeValue,
                                    ((domTextNode*)node)->valueLength);
................................................................................
    writeChars(xmlString, chan, node->nodeName, -1);

    attrs = node->firstAttr;
    while (attrs) {
        if (indentAttrs > -1) {
            writeChars(xmlString, chan, "\n", 1);
            if ((indent != -1) && doIndent) {

                for(i=0; i<level; i++) {




                    writeChars(xmlString, chan, "        ", indent);
                }
                if (indentAttrs) {




                    writeChars(xmlString, chan, "        ", indentAttrs);
                }
            }
        } else {
            writeChars(xmlString, chan, " ", 1);
        }
        writeChars(xmlString, chan, attrs->nodeName, -1);
................................................................................
                writeChars(xmlString, chan, ">", 1);
            } else {
                writeChars(xmlString, chan, "/>",   2);
            }
        }
    } else {
        if ((indent != -1) && hasElements) {

            for(i=0; i<level; i++) {




                writeChars(xmlString, chan, "        ", indent);

            }
        }
        writeChars (xmlString, chan, "</", 2);
        writeChars(xmlString, chan, node->nodeName, -1);
        if (indent != -1) {
            writeChars(xmlString, chan, ">\n", 2);
        } else {
................................................................................

static
void tcldom_childsAsJSON (
    Tcl_Obj     *jstring,
    domNode     *node, /* Must be an ELEMENT_NODE */
    Tcl_Channel  channel,
    int          indent,

    int          level,
    int          inside
    )
{
    domNode   *child, *nextChild;
    int i, effectivParentType = 0;
    int first = 1;
................................................................................
            }
            if (nextChild) {
                effectivParentType = JSON_ARRAY;
            } else {
                /* Exactly one 'relevant' child node, a text node;
                 * serialize it as simple token value. */
                tcldom_treeAsJSON (jstring, child, channel, indent,
                                   level, JSON_ARRAY);
                return;
            }
        }
    }
        
    switch (effectivParentType) {
    case JSON_ARRAY:
................................................................................
                first = 0;
                level++;
            } else {
                writeChars(jstring, channel, ",", 1);
            }
            if (indent > -1) {
                writeChars(jstring, channel, "\n", 1);
                if (first) level++;
                for (i = 0; i < level; i++) {




                    writeChars(jstring, channel, "        ", indent);

                }
            }
            tcldom_treeAsJSON (jstring, child, channel, indent,
                               level, JSON_ARRAY);
            child = child->nextSibling;
            while (child
                   && child->nodeType != TEXT_NODE
                   && child->nodeType != ELEMENT_NODE) {
                child = child->nextSibling;
            }
        }
        if (indent > -1 && first == 0) {
            writeChars(jstring, channel, "\n", 1);
            level--;

            for (i = 0; i < level; i++) {




                writeChars(jstring, channel, "        ", indent);

            }
        }
        writeChars(jstring, channel, "]",1);
        break;
    case JSON_OBJECT:
        writeChars(jstring, channel, "{",1);
        while (child) {
................................................................................
                first = 0;
                level++;
            } else {
                writeChars(jstring, channel, ",", 1);
            }
            if (indent > -1) {
                writeChars(jstring, channel, "\n", 1);
                if (first) level++;
                for (i = 0; i < level; i++) {




                    writeChars(jstring, channel, "        ", indent);

                }
            }
            tcldom_treeAsJSON (jstring, child, channel, indent,
                               level, JSON_OBJECT);
            child = child->nextSibling;
            /* Inside of a JSON_OBJECT, only element childs make
             * semantically sense. */
            while (child && child->nodeType != ELEMENT_NODE) {
                child = child->nextSibling;
            }
        }
        if (indent > -1 && first == 0) {
            writeChars(jstring, channel, "\n", 1);
            level--;

            for (i = 0; i < level; i++) {




                writeChars(jstring, channel, "        ", indent);

            }
        }
        writeChars(jstring, channel, "}",1);
        break;
    default:
        break;
    }
................................................................................
\---------------------------------------------------------------------------*/
static
void tcldom_treeAsJSON (
    Tcl_Obj     *jstring,
    domNode     *node,  /* Must not be NULL */
    Tcl_Channel  channel,
    int          indent,

    int          level,
    int          inside
    )
{
    domTextNode *textNode;
    int i, seenDP, seenE;
    unsigned char c;
................................................................................
        switch (inside) {
        case JSON_OBJECT:
            /* Write the member name and recurse to the childs for the
             * value. */
            tcldom_AppendEscapedJSON (jstring, channel,
                                      node->nodeName, -1);
            writeChars (jstring, channel, ":", 1);



            tcldom_childsAsJSON (jstring, node, channel, indent,
                                 level, inside);
            break;
        case JSON_ARRAY:
            /* Since we're already inside of an array, the element can
               only be interpreted as a container for a nested JSON
               object or array. */
            tcldom_childsAsJSON (jstring, node, channel, indent,
                                 level, inside);
            break;
        case JSON_START:
            tcldom_childsAsJSON (jstring, node, channel, indent,
                                 level, inside);            
            break;
        }
        return;
    default:
        /* Any other node types (COMMENT_NODE, CDATA_SECTION_NODE, 
           PROCESSING_INSTRUCTION_NODE) are ignored. */
        return;
................................................................................
            goto cleanup;
        }
        switch ((enum asXMLOption) optionIndex) {

        case m_indent:
            if (objc < 4) {
                SetResult("-indent must have an argument "
                          "(0..8 or 'no'/'none')");
                goto cleanup;
            }
            if (strcmp("none", Tcl_GetString(objv[3]))==0) {
                indent = -1;
            }
            else if (strcmp("no", Tcl_GetString(objv[3]))==0) {
                indent = -1;
            }



            else if (Tcl_GetIntFromObj(interp, objv[3], &indent) != TCL_OK) {
                SetResult( "indent must be an integer (0..8) or 'no'/'none'");

                goto cleanup;
            }
            objc -= 2;
            objv += 2;
            break;

        case m_indentAttrs:
            if (objc < 4) {
                SetResult("-indentAttrs must have an argument "
                          "(0..8 or 'no'/'none')");
                goto cleanup;
            }
            if (strcmp("none", Tcl_GetString(objv[3]))==0) {
                indentAttrs = -1;
            }
            else if (strcmp("no", Tcl_GetString(objv[3]))==0) {
                indentAttrs = -1;
            }



            else if (Tcl_GetIntFromObj(interp, objv[3], &indentAttrs) != TCL_OK) {
                SetResult( "indentAttrs must be an integer (0..8) or 'no'/'none'");

                goto cleanup;
            }
            if (indentAttrs > 8) indentAttrs = 8;
            if (indentAttrs < 0) indentAttrs = 0;
            objc -= 2;
            objv += 2;
            break;
................................................................................
    domNode    *node,
    Tcl_Interp *interp,
    int         objc,
    Tcl_Obj    *const objv[]
)
{
    char       *channelId;
    int         optionIndex, mode, indent = -1;
    Tcl_Obj    *resultPtr;
    Tcl_Channel chan = (Tcl_Channel) NULL;

    static const char *asJSONOptions[] = {
        "-channel", "-indent",
        NULL
    };
................................................................................
                return TCL_ERROR;
            }
            if (strcmp("none", Tcl_GetString(objv[3]))==0) {
                indent = -1;
            }
            else if (strcmp("no", Tcl_GetString(objv[3]))==0) {
                indent = -1;





            }
            else if (Tcl_GetIntFromObj(interp, objv[3], &indent) != TCL_OK) {
                SetResult( "indent must be an integer (0..8) or 'no'/'none'");
                return TCL_ERROR;
            } else if (indent < 0 || indent > 8) {
                SetResult( "indent must be an integer (0..8) or 'no'/'none'");
                return TCL_ERROR;
................................................................................
                
            objc -= 2;
            objv += 2;
            break;
        }
    }
    resultPtr = Tcl_NewStringObj("", 0);
    tcldom_treeAsJSON(resultPtr, node, chan, indent, 0, JSON_START);

    Tcl_AppendResult(interp, Tcl_GetString(resultPtr), NULL);
    Tcl_DecrRefCount(resultPtr);
    return TCL_OK;
}

/*----------------------------------------------------------------------------
|   cdataSectionElements







>
>







 







|







 







|







 







<
|







 







>
|
>
>
>
>
|
>







 







>
|
>
>
>
>
|
|
<
>
>
>
>







 







>
|
>
>
>
>
|
>







 







>







 







|







 







|
|
>
>
>
>
|
>



|










>
|
>
>
>
>
|
>







 







|
|
>
>
>
>
|
>



|










>
|
>
>
>
>
|
>







 







>







 







>
>
>

|






|



|







 







|








>
>
>

|
>









|








>
>
>

|
>







 







|







 







>
>
>
>
>







 







|
>







157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
...
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
...
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
...
401
402
403
404
405
406
407

408
409
410
411
412
413
414
415
....
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
....
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929

2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
....
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
....
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
....
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
....
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
....
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
....
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
....
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
....
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
....
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
....
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
....
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
#define SERIALIZE_DOCTYPE_DECLARATION 2
#define SERIALIZE_FOR_ATTR 4 
#define SERIALIZE_ESCAPE_NON_ASCII 8
#define SERIALIZE_HTML_ENTITIES 16
#define SERIALIZE_ESCAPE_ALL_QUOT 32
#define SERIALIZE_NO_GT_ESCAPE 64
#define SERIALIZE_NO_EMPTY_ELEMENT_TAG 128
#define SERIALIZE_INDENT_WITH_TAB 256
#define SERIALIZE_INDENT_ATTR_WITH_TAB 512

/*----------------------------------------------------------------------------
|   Module Globals
|
\---------------------------------------------------------------------------*/
#ifndef TCL_THREADS
    static int        storeLineColumn       = 0;
................................................................................
    "    getElementsByTagNameNS uri localname    \n"
    "    createElement tagName ?objVar?          \n"
    "    createElementNS uri tagName ?objVar?    \n"
    "    createCDATASection data ?objVar?        \n"
    "    createTextNode text ?objVar?            \n"
    "    createComment text ?objVar?             \n"
    "    createProcessingInstruction target data ?objVar? \n"
    "    asXML ?-indent <none,tabs,0..8>? ?-channel <channel>? ?-escapeNonASCII? ?-escapeAllQuot? ?-doctypeDeclaration <boolean>?\n"
    "    asHTML ?-channel <channelId>? ?-escapeNonASCII? ?-htmlEntities?\n"
    "    asText                                  \n"
    "    asJSON ?-indent <none,0..8>?            \n"
    "    getDefaultOutputMethod                  \n"
    "    publicId ?publicId?                     \n"
    "    systemId ?systemId?                     \n"
    "    internalSubset ?internalSubset?         \n"
................................................................................
    "    baseURI ?URI?                \n"
    "    localName                    \n"
    "    delete                       \n"
    "    getLine                      \n"
    "    getColumn                    \n"
    "    @<attrName> ?defaultValue?   \n"
    "    asList                       \n"
    "    asXML ?-indent <none,tabs,0..8>? ?-channel <channel>? ?-escapeNonASCII? ?-escapeAllQuot? ?-doctypeDeclaration <boolean>?\n"
    "    asHTML ?-channel <channelId>? ?-escapeNonASCII? ?-htmlEntities?\n"
    "    asText                       \n"
    "    asJSON ?-indent <none,0..8>? \n"
    "    appendFromList nestedList    \n"
    "    appendFromScript script      \n"
    "    insertBeforeFromScript script ref \n"
    "    appendXML xmlString          \n"
................................................................................
|
\---------------------------------------------------------------------------*/
static Tcl_VarTraceProc  tcldom_docTrace;
static Tcl_CmdDeleteProc tcldom_docCmdDeleteProc;

static void tcldom_treeAsJSON(Tcl_Obj *jstring, domNode *node,
                              Tcl_Channel channel, int indent,

                              int outputFlags, int level, int inside);

#ifdef TCL_THREADS

static int tcldom_EvalLocked(Tcl_Interp* interp, Tcl_Obj** objv,
                             domDocument* doc, int flag);

static int tcldom_RegisterDocShared(domDocument* doc);
................................................................................
        writeChars(xmlString, chan, ((domTextNode*)node)->nodeValue,
                                    ((domTextNode*)node)->valueLength);
        writeChars(xmlString, chan, "]]>", 3);
        return;
    }

    if ((indent != -1) && doIndent) {
        if (outputFlags & SERIALIZE_INDENT_WITH_TAB) {
            for(i=0; i<level; i++) {
                writeChars(xmlString, chan, "\t", 1);
            }
        } else {
            for(i=0; i<level; i++) {
                writeChars(xmlString, chan, "        ", indent);
            }
        }
    }

    if (node->nodeType == COMMENT_NODE) {
        writeChars(xmlString, chan, "<!--", 4);
        writeChars(xmlString, chan, ((domTextNode*)node)->nodeValue,
                                    ((domTextNode*)node)->valueLength);
................................................................................
    writeChars(xmlString, chan, node->nodeName, -1);

    attrs = node->firstAttr;
    while (attrs) {
        if (indentAttrs > -1) {
            writeChars(xmlString, chan, "\n", 1);
            if ((indent != -1) && doIndent) {
                if (outputFlags & SERIALIZE_INDENT_WITH_TAB) {
                    for(i=0; i<level; i++) {
                        writeChars(xmlString, chan, "\t", 1);
                    }
                } else {
                    for(i=0; i<level; i++) {
                        writeChars(xmlString, chan, "        ", indent);
                    }

                }
                if (outputFlags & SERIALIZE_INDENT_ATTR_WITH_TAB) {
                    writeChars(xmlString, chan, "\t", 1);
                } else {
                    writeChars(xmlString, chan, "        ", indentAttrs);
                }
            }
        } else {
            writeChars(xmlString, chan, " ", 1);
        }
        writeChars(xmlString, chan, attrs->nodeName, -1);
................................................................................
                writeChars(xmlString, chan, ">", 1);
            } else {
                writeChars(xmlString, chan, "/>",   2);
            }
        }
    } else {
        if ((indent != -1) && hasElements) {
            if (outputFlags & SERIALIZE_INDENT_WITH_TAB) {
                for(i=0; i<level; i++) {
                    writeChars(xmlString, chan, "\t", 1);
                }
            } else {
                for(i=0; i<level; i++) {
                    writeChars(xmlString, chan, "        ", indent);
                }
            }
        }
        writeChars (xmlString, chan, "</", 2);
        writeChars(xmlString, chan, node->nodeName, -1);
        if (indent != -1) {
            writeChars(xmlString, chan, ">\n", 2);
        } else {
................................................................................

static
void tcldom_childsAsJSON (
    Tcl_Obj     *jstring,
    domNode     *node, /* Must be an ELEMENT_NODE */
    Tcl_Channel  channel,
    int          indent,
    int          outputFlags,
    int          level,
    int          inside
    )
{
    domNode   *child, *nextChild;
    int i, effectivParentType = 0;
    int first = 1;
................................................................................
            }
            if (nextChild) {
                effectivParentType = JSON_ARRAY;
            } else {
                /* Exactly one 'relevant' child node, a text node;
                 * serialize it as simple token value. */
                tcldom_treeAsJSON (jstring, child, channel, indent,
                                   outputFlags, level, JSON_ARRAY);
                return;
            }
        }
    }
        
    switch (effectivParentType) {
    case JSON_ARRAY:
................................................................................
                first = 0;
                level++;
            } else {
                writeChars(jstring, channel, ",", 1);
            }
            if (indent > -1) {
                writeChars(jstring, channel, "\n", 1);
                if (outputFlags & SERIALIZE_INDENT_WITH_TAB) {
                    for (i = 0; i < level; i++) {
                        writeChars(jstring, channel, "\t", 1);
                    }
                } else {
                    for (i = 0; i < level; i++) {
                        writeChars(jstring, channel, "        ", indent);
                    }
                }
            }
            tcldom_treeAsJSON (jstring, child, channel, indent,
                               outputFlags, level, JSON_ARRAY);
            child = child->nextSibling;
            while (child
                   && child->nodeType != TEXT_NODE
                   && child->nodeType != ELEMENT_NODE) {
                child = child->nextSibling;
            }
        }
        if (indent > -1 && first == 0) {
            writeChars(jstring, channel, "\n", 1);
            level--;
            if (outputFlags & SERIALIZE_INDENT_WITH_TAB) {
                for (i = 0; i < level; i++) {
                    writeChars(jstring, channel, "\t", 1);
                }
            } else {
                for (i = 0; i < level; i++) {
                    writeChars(jstring, channel, "        ", indent);
                }
            }
        }
        writeChars(jstring, channel, "]",1);
        break;
    case JSON_OBJECT:
        writeChars(jstring, channel, "{",1);
        while (child) {
................................................................................
                first = 0;
                level++;
            } else {
                writeChars(jstring, channel, ",", 1);
            }
            if (indent > -1) {
                writeChars(jstring, channel, "\n", 1);
                if (outputFlags & SERIALIZE_INDENT_WITH_TAB) {
                    for (i = 0; i < level; i++) {
                        writeChars(jstring, channel, "\t", 1);
                    }
                } else {
                    for (i = 0; i < level; i++) {
                        writeChars(jstring, channel, "        ", indent);
                    }
                }
            }
            tcldom_treeAsJSON (jstring, child, channel, indent,
                               outputFlags, level, JSON_OBJECT);
            child = child->nextSibling;
            /* Inside of a JSON_OBJECT, only element childs make
             * semantically sense. */
            while (child && child->nodeType != ELEMENT_NODE) {
                child = child->nextSibling;
            }
        }
        if (indent > -1 && first == 0) {
            writeChars(jstring, channel, "\n", 1);
            level--;
            if (outputFlags & SERIALIZE_INDENT_WITH_TAB) {
                for (i = 0; i < level; i++) {
                    writeChars(jstring, channel, "\t", 1);
                }
            } else {
                for (i = 0; i < level; i++) {
                    writeChars(jstring, channel, "        ", indent);
                }
            }
        }
        writeChars(jstring, channel, "}",1);
        break;
    default:
        break;
    }
................................................................................
\---------------------------------------------------------------------------*/
static
void tcldom_treeAsJSON (
    Tcl_Obj     *jstring,
    domNode     *node,  /* Must not be NULL */
    Tcl_Channel  channel,
    int          indent,
    int          outputFlags,
    int          level,
    int          inside
    )
{
    domTextNode *textNode;
    int i, seenDP, seenE;
    unsigned char c;
................................................................................
        switch (inside) {
        case JSON_OBJECT:
            /* Write the member name and recurse to the childs for the
             * value. */
            tcldom_AppendEscapedJSON (jstring, channel,
                                      node->nodeName, -1);
            writeChars (jstring, channel, ":", 1);
            if (indent > -1 || outputFlags & SERIALIZE_INDENT_WITH_TAB) {
                writeChars (jstring, channel, " ", 1);
            }
            tcldom_childsAsJSON (jstring, node, channel, indent,
                                 outputFlags, level, inside);
            break;
        case JSON_ARRAY:
            /* Since we're already inside of an array, the element can
               only be interpreted as a container for a nested JSON
               object or array. */
            tcldom_childsAsJSON (jstring, node, channel, indent,
                                 outputFlags, level, inside);
            break;
        case JSON_START:
            tcldom_childsAsJSON (jstring, node, channel, indent,
                                 outputFlags, level, inside);            
            break;
        }
        return;
    default:
        /* Any other node types (COMMENT_NODE, CDATA_SECTION_NODE, 
           PROCESSING_INSTRUCTION_NODE) are ignored. */
        return;
................................................................................
            goto cleanup;
        }
        switch ((enum asXMLOption) optionIndex) {

        case m_indent:
            if (objc < 4) {
                SetResult("-indent must have an argument "
                          "(0..8 or 'no'/'none'/'tabs')");
                goto cleanup;
            }
            if (strcmp("none", Tcl_GetString(objv[3]))==0) {
                indent = -1;
            }
            else if (strcmp("no", Tcl_GetString(objv[3]))==0) {
                indent = -1;
            }
            else if (strcmp("tabs", Tcl_GetString(objv[3]))==0) {
                outputFlags |= SERIALIZE_INDENT_WITH_TAB;
            }
            else if (Tcl_GetIntFromObj(interp, objv[3], &indent) != TCL_OK) {
                SetResult( "indent must be an integer (0..8) or "
                           "'no'/'none'/'tabs'");
                goto cleanup;
            }
            objc -= 2;
            objv += 2;
            break;

        case m_indentAttrs:
            if (objc < 4) {
                SetResult("-indentAttrs must have an argument "
                          "(0..8 or 'no'/'none'/'tabs')");
                goto cleanup;
            }
            if (strcmp("none", Tcl_GetString(objv[3]))==0) {
                indentAttrs = -1;
            }
            else if (strcmp("no", Tcl_GetString(objv[3]))==0) {
                indentAttrs = -1;
            }
            else if (strcmp("tabs", Tcl_GetString(objv[3]))==0) {
                outputFlags |= SERIALIZE_INDENT_ATTR_WITH_TAB;
            }
            else if (Tcl_GetIntFromObj(interp, objv[3], &indentAttrs) != TCL_OK) {
                SetResult( "indentAttrs must be an integer (0..8) or "
                           "'no'/'none'/'tabs'");
                goto cleanup;
            }
            if (indentAttrs > 8) indentAttrs = 8;
            if (indentAttrs < 0) indentAttrs = 0;
            objc -= 2;
            objv += 2;
            break;
................................................................................
    domNode    *node,
    Tcl_Interp *interp,
    int         objc,
    Tcl_Obj    *const objv[]
)
{
    char       *channelId;
    int         optionIndex, mode, outputFlags = 0, indent = -1;
    Tcl_Obj    *resultPtr;
    Tcl_Channel chan = (Tcl_Channel) NULL;

    static const char *asJSONOptions[] = {
        "-channel", "-indent",
        NULL
    };
................................................................................
                return TCL_ERROR;
            }
            if (strcmp("none", Tcl_GetString(objv[3]))==0) {
                indent = -1;
            }
            else if (strcmp("no", Tcl_GetString(objv[3]))==0) {
                indent = -1;
            }
            else if (strcmp("tabs", Tcl_GetString(objv[3]))==0) {
                /* User wants indentation */
                indent = 0;
                outputFlags |= SERIALIZE_INDENT_WITH_TAB;
            }
            else if (Tcl_GetIntFromObj(interp, objv[3], &indent) != TCL_OK) {
                SetResult( "indent must be an integer (0..8) or 'no'/'none'");
                return TCL_ERROR;
            } else if (indent < 0 || indent > 8) {
                SetResult( "indent must be an integer (0..8) or 'no'/'none'");
                return TCL_ERROR;
................................................................................
                
            objc -= 2;
            objv += 2;
            break;
        }
    }
    resultPtr = Tcl_NewStringObj("", 0);
    tcldom_treeAsJSON(resultPtr, node, chan, indent, outputFlags, 0,
                      JSON_START);
    Tcl_AppendResult(interp, Tcl_GetString(resultPtr), NULL);
    Tcl_DecrRefCount(resultPtr);
    return TCL_OK;
}

/*----------------------------------------------------------------------------
|   cdataSectionElements

Changes to tests/domDoc.test.

315
316
317
318
319
320
321



































322
323
324
325
326
327
328
    set root [$doc documentElement]
    $root setAttribute attr "foo\"bar"
    set result [$doc asXML -indent none]
    $doc delete
    set result
} {<doc attr="foo&quot;bar"/>}




































set doc [dom parse <root/>]

test domDoc-2.1 {publicId - no publicId there} {
    $doc publicId
} {}

test domDoc-2.2 {systemId - no systemId there} {







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
    set root [$doc documentElement]
    $root setAttribute attr "foo\"bar"
    set result [$doc asXML -indent none]
    $doc delete
    set result
} {<doc attr="foo&quot;bar"/>}

test domDoc-1.32 {asXML -indent tabs} {
    set doc [dom parse {<doc><a><b/></a></doc>}]
    set result [$doc asXML -indent tabs]
    $doc delete
    set result
} "<doc>\n\t<a>\n\t\t<b/>\n\t</a>\n</doc>\n"

test domDoc-1.33 {asXML -indent tabs} {
    set doc [dom parse {<doc><a><b/></a><c><d><f/></d></c><g/></doc>}]
    set result [$doc asXML -indent tabs]
    $doc delete
    set result
} "<doc>\n\t<a>\n\t\t<b/>\n\t</a>\n\t<c>\n\t\t<d>\n\t\t\t<f/>\n\t\t</d>\n\t</c>\n\t<g/>\n</doc>\n"

test domDoc-1.34 {asXML -indent tabs -noEmptyElementTag} {
    set doc [dom parse {<doc><a><b/></a><c><d><f/></d></c><g/></doc>}]
    set result [$doc asXML -indent tabs -noEmptyElementTag]
    $doc delete
    set result
} "<doc>\n\t<a>\n\t\t<b></b>\n\t</a>\n\t<c>\n\t\t<d>\n\t\t\t<f></f>\n\t\t</d>\n\t</c>\n\t<g></g>\n</doc>\n"

test domDoc-1.35 {asXML -indent tabs -indentAttrs tabs} {
    set doc [dom parse {<doc><a a1="a1" a2="a2"><b/></a><c><d a1="a1" a2="a2"><f/></d></c><g/></doc>}]
    set result [$doc asXML -indent tabs -indentAttrs tabs]
    $doc delete
    set result
} "<doc>\n\t<a\n\t\ta1=\"a1\"\n\t\ta2=\"a2\">\n\t\t<b/>\n\t</a>\n\t<c>\n\t\t<d\n\t\t\ta1=\"a1\"\n\t\t\ta2=\"a2\">\n\t\t\t<f/>\n\t\t</d>\n\t</c>\n\t<g/>\n</doc>\n"

test domDoc-1.36 {asXML -indent tabs -indentAttrs <num>} {
    set doc [dom parse {<doc><a a1="a1" a2="a2"><b/></a><c><d a1="a1" a2="a2"><f/></d></c><g/></doc>}]
    set result [$doc asXML -indent tabs -indentAttrs 2]
    $doc delete
    set result
} "<doc>\n\t<a\n\t  a1=\"a1\"\n\t  a2=\"a2\">\n\t\t<b/>\n\t</a>\n\t<c>\n\t\t<d\n\t\t  a1=\"a1\"\n\t\t  a2=\"a2\">\n\t\t\t<f/>\n\t\t</d>\n\t</c>\n\t<g/>\n</doc>\n"

set doc [dom parse <root/>]

test domDoc-2.1 {publicId - no publicId there} {
    $doc publicId
} {}

test domDoc-2.2 {systemId - no systemId there} {

Changes to tests/domjson.test.

386
387
388
389
390
391
392




































393
394
395
396
397
398
399

test json-6.5 {asJSON - serialization of control characters} {
    set doc [dom parse -json "\"a\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008\\u0009\\u000A\\u000B\\u000C\\u000D\\u000E\\u000F\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F\\u0020b\""]
    set result [$doc asJSON]
    $doc delete
    set result
} {"a\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f b"}





































test json-7.1 {jsonType} {
    set doc [dom parse {<j>foo</j>}]
    set root [$doc documentElement]
    set result [list]
    lappend result [$root asJSON]
    lappend result [$root jsonType]







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435

test json-6.5 {asJSON - serialization of control characters} {
    set doc [dom parse -json "\"a\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\u0008\\u0009\\u000A\\u000B\\u000C\\u000D\\u000E\\u000F\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001A\\u001B\\u001C\\u001D\\u001E\\u001F\\u0020b\""]
    set result [$doc asJSON]
    $doc delete
    set result
} {"a\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\b\t\n\u000b\f\r\u000e\u000f\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f b"}

test json-6.6 {asJSON -indent} {
    set doc [dom parse -json {{"a":{"aa":[1,2,3,4,"abc"]},"b":"bvalue"}}]
    set result [$doc asJSON -indent 2]
    $doc delete
    set result
} {{
  "a": {
    "aa": [
      1,
      2,
      3,
      4,
      "abc"
    ]
  },
  "b": "bvalue"
}}

test json-6.7 {asJSON -indent} {
    set doc [dom parse -json {{"a":{"aa":[1,2,3,4,"abc"]},"b":"bvalue"}}]
    set result [$doc asJSON -indent tabs]
    $doc delete
    set result
} {{
	"a": {
		"aa": [
			1,
			2,
			3,
			4,
			"abc"
		]
	},
	"b": "bvalue"
}}

test json-7.1 {jsonType} {
    set doc [dom parse {<j>foo</j>}]
    set root [$doc documentElement]
    set result [list]
    lappend result [$root asJSON]
    lappend result [$root jsonType]