domDoc (3)
NAME
domDoc - Manipulates an instance of a DOM document objectSYNOPSIS
domDocObjCmd method ?arg arg ...?
DESCRIPTION
This command manipulates one particular instance of a document object. method indicates a specific method of the document class. These methods should closely conform to the W3C recommendation "Document Object Model (Core) Level 1" (www.w3.org/TR/REC-DOM-Level-1/level-one-core.html Look at these documents for a deeper understanding of the functionality.
The valid methods are:
- documentElement ?objVar?
- getElementsByTagName name
- getElementsByTagNameNS uri localname
- createElement tagName ?objVar?
- createElementNS url tagName ?objVar?
- createTextNode text ?objVar?
- createComment text ?objVar?
- createCDATASection data ?objVar?
- createProcessingInstruction target data ?objVar?
- delete
- Explicitly deletes the document, including the associated Tcl object commands (for nodes, fragment/new nodes, the document object itself) and the underlying DOM tree.
- getDefaultOutputMethod
- Returns the default output method of the document. This is usually a result of a XSLT transformation.
- asXML ?-indent none/1..8? ?-channel channelId? ?-escapeNonASCII? ?-doctypeDeclaration <boolean>? ?-escapeAllQuot?
- Returns the DOM tree as an (optional indented) XML string or sends the output directly to the given channelId. If the option -escapeNonASCII is given, every non 7 bit ASCII character in attribute values or element PCDATA content will be escaped as character reference in decimal representation. The flag -doctypeDeclaration determines, whether there will be a DOCTYPE declaration emitted before the first node of the document. The default is, to do not. The DOCTYPE name will always be the element name of the document element. An external entity declaration of the external subset is only emitted, if the document has a system identifier. If the option -escapeAllQuot is given, quotation marks will be escaped with " even in text content of elements.
- asHTML ?-channel channelId? ?-escapeNonASCII? ?-htmlEntities? ?-doctypeDeclaration <boolean>?
- Returns the DOM tree serialized acording to HTML rules (HTML elements are recognized regardless of case, without end tags for emtpy HTML elements etc.), as string or sends the output directly to the given channelId. If the option -escapeNonASCII is given, every non 7 bit ASCII character in attribute values or element PCDATA content will be escaped as character reference in decimal representation. If the option -htmlEntities is given, a character is outputed using a HTML 4.01 character entity reference, if one is defined for it. The flag -doctypeDeclaration determines, whether there will be a DOCTYPE declaration emitted before the first node of the document. The default is, to do not. The DOCTYPE name will always be the element name of the document element without case normalization. An external entity declaration of the external subset is only emitted, if the document has a system identifier. The doctype declaration will be written from the avaliable informations, without check, if this is a known (w3c) HTML version information or if the document confirms to the given HTML version.
- asText
- The asText method outputs the result tree by outputting the string-value of every text node in the result tree in document order without any escaping. In effect, this is what the xslt output method "text" (XSLT 1.0 recommendation, section 16.3) does.
- publicId ?publicId?
- systemId ?systemId?
- internalSubset ?internalSubset?
- Returns the internal subset of the doctype declaration of the document, if there is one, otherwise the empty string. If there is a value given to the method, the internal subset of the document is set to this value. Note, that none of the parsing methods preserve the internal subset of a document; a freshly parsed document will always have an empty internal subset. Also note, that the method doesen't do any syntactical check on a given internal subset.
- cdataSectionElements (?URI:?localname|*) ?<boolean>?
- selectNodesNamespaces ?prefixUriList?
- This method allows to control a document global prefix to namespace URI mapping, which will be used for selectNodes method calls (on document as well as on all nodes, which belongs to the document), if it is not overwritten by using the -namespaces option of the selectNodes method. Any namespace prefix within an xpath expression will be first resolved against this list. If the list bind the same prefix to different namespaces, then the first binding will win. If a prefix could not resolved against the document global prefix / namespaces list, then the namespace definitions in scope of the context node will be used to resolve the prefix, as usual. If the optional argument prefixUriList is given, then the global prefix / namespace list is set to this list and returns it. Without the optional argument the method returns the current list. The default is the empty list.
- xslt ?-parameters parameterList? ?-ignoreUndeclaredParameters? ?-xsltmessagecmd script? stylesheet ?outputVar?
-
The optional -parameters option sets top level <xsl:param> to string values. The parameterList has to be a tcl list consisting of parameter name and value pairs.
If the option -ignoreUndeclaredParameters is given, then parameter names in the parameterList given to the -parameters options that are not declared as top-level parameters in the stylesheet are silently ignored. Without this option, an error is raised, if the user tries to set a top-level parameter, which is not declared in the stylesheet.
The -xsltmessagecmd option sets a callback for xslt:message elements in the stylesheet. The actual command consists of the script, given as argument to the option, appended with the XML Fragment from instantiating the xsl:message element content as string (as if the XPath string() function would have been applied to the XML Fragment) and a flag, which indicates, if the xsl:message has an attribute "terminate" with the value "yes".
- toXSLTcmd ?objVar?
-
The syntax of the created xsltCmd is:
-
xsltCmd method ?arg ...?
The valid methods are:
- transform ?-parameters parameterList? ?-ignoreUndeclaredParameters? ?-xsltmessagecmd script? domDoc ?outputVar?
-
The optional -parameters option sets top level <xsl:param> to string values. The parameterList has to be a tcl list consisting of parameter name and value pairs.
If the option -ignoreUndeclaredParameters is given, then parameter names in the parameterList given to the -parameters options that are not declared as top-level parameters in the stylesheet are silently ignored. Without this option, an error is raised, if the user tries to set a top-level parameter, which is not declared in the stylesheet.
The -xsltmessagecmd option sets a callback for xslt:message elements in the stylesheet. The actual command consists of the script, given as argument to the option, appended with the XML Fragment from instantiating the xsl:message element content as string (as if the XPath string() function would have been applied to the XML Fragment) and a flag, which indicates, if the xsl:message has an attribute "terminate" with the value "yes".
- delete
- Deletes the xsltCmd and cleans up all used recourses
If the first argument to an xsltCmd is a domDoc or starts with a "-", then the command is processed in the same way as <xsltCmd> transform.
-
- normalize ?-forXPath?
- nodeType
- Returns the node type of the document node. This is always DOCUMENT_NODE.
- getElementById id
- firstChild ?objVar?
- Returns the first top level node of the document.
- lastChild ?objVar?
- Returns the last top level node of the document.
- appendChild newChild
- removeChild child
- hasChildNodes
- Returns 1 if the document has any nodes in the tree. Otherwise 0 is returned.
- childNodes
- Returns a list of the top level nodes of the document.
- ownerDocument ?domObjVar?
- Returns the document itself.
- insertBefore newChild refChild
- replaceChild newChild oldChild
- appendFromList list
- appendXML XMLstring
- selectNodes ?-namespaces prefixUriList? ?-cache <boolean>? xpathQuery ?typeVar?
-
-
Returns the result of applying the XPath query xpathQuery 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 typeVar is given the result type name is stored into that variable (empty, bool, number, string, nodes, attrnodes or mixed).
The argument xpathQuery 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 option -namespaces 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 bind 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.
If the -cache option is used with a true value, then the xpathQuery 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 pre-compiled and stored in the cache, for use in further calls. Please notice, that the xpathQuery 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. During pre-compilation, the prefixes will be resolved first to the prefix / namespace pairs of the -namespaces option, if given, and to the namespaces in scope of the context node at pre-compilation time. If the XPath is found in the cache, neither the -namespaces option nor the namespaces in scope of the context node will be taken in account but the already resolved (stored) namespaces will be used for the query.
Examples:
-
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="www.defaultnamespace.org"><child/></doc>}] set root [$doc documentElement] set childNodes [$root selectNodes -namespaces {default www.defaultnamespace.org} default:child]
-
-
- baseURI ?URI?
- Returns the present baseURI of the document. If the optional argument URI is given, sets the base URI of the document to the given URI.
- appendFromScript tclScript
- insertBeforeFromScript tclScript refChild
- deleteXPathCache ?xpathQuery?
Otherwise, if an unknown method name is given, the command with the same name as the given metho within the namespace ::dom::domDoc is tried to be executed. This allows quick method additions on Tcl level.
Newly created nodes are appended to a hidden fragment list. If they are not moved into the tree they are automaticaly deleted, when the whole document gets deleted.