|
NAMEdomDoc - Manipulates an instance of a DOM document objectSYNOPSISdomDocObjCmd method ?arg arg ...? domDoc docToken method ?arg arg ...? DESCRIPTIONThis 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" (http://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:
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 not to emit it. 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. The flag -xmlDeclaration determines whether there will be an XML Declaration and a newline emitted before anything else. The default is not to emit one. If this flag is given with a true argument then -encString sets the encoding value in the XML Declaration. Otherwise this option is ignored. Please note that this option just enhances 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. If the option -escapeAllQuot is given, quotation marks will be escaped with " even in text content of elements. If the option -indentAttrs 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 -indentAttrs (0..8). If the option -nogtescape is given then the character '>' won't get escaped in attribute values and text content of elements. The default is to escape this character. If the option -noEmptyElementTag 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.
The asJSON method serializes the tree into a valid JSON data string. In general, this may be a lossy serialization. For this serialization all comment, character data sections and processing instruction nodes, all attributes and all XML namespaces are ignored. Only element and text nodes may be reflected in the generated JSON serialization. Appropriate JSON data type information of a node will be respected. If an element node has the JSON type OBJECT, then every element node child of this element will be serialized as member of that object, with the node name of the child as the member name and the relevant children of that child as the value. Every other child nodes will be ignored. If an element node has the JSON type ARRAY, then the text and element node children of that element node are serialized as the consecutive values of the array. Element node children of an ARRAY element will be container nodes for nested ARRAY or OBJECT values. Text nodes with the JSON types TRUE, FALSE or NULL will be serialized to the corresponding JSON token without looking at the value of the text node. A text node without JSON type will always be serialized as a JSON string token. A text node with JSON type NUMBER will be serialized as JSON number token if the text node value is in fact a valid JSON number and as a JSON string if not. If an element node doesn't has a JSON type then the serialization of its children is determined by the following rules: Only text and element node child are relevant. If the element node to serialize is the member of a JSON object and there is no relevant child node the value of that member will be an empty JSON string. If the only relevant child node of this element node is a text node then the JSON value of that text node will be the value of the object member. If the element has more than one relevant child nodes and the first one is a text node then the relevant children will be serialized as JSON array. If the only relevant child node is an element node or the first relevant child is an element node and the node name of that only or first relevant child isn't equal to the array container node name all element node children will be serialized as the members of a JSON object (while ignoring any intermixed text nodes). If the only or first relevant child is an element node and the node name of this child is equal to the array container element name then all relevant children will be serialized as the values of a JSON array. If the element to serialize is a value of a JSON array and the node name of this element isn't equal to the array container node name that element will be seen as a container node for a JSON object and all element node children will be serialized as the members of that array while ignoring any text node children. If the element to serialize is a value of a JSON array and the node name of this element is equal to the array container node name, all relevant children will be serialized as JSON array. If the -channel option is given the serialization isn't returned as string but send directly to the channel, given as argument to the option. If the -indent option is given and the argument given to this option isn't "none" then the returned JSON string is "pretty-printed". The numeric argument to this option defines the number of spaces for any indentation level. The default is to not emit any additional white space.
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 that is not declared in the stylesheet. The option -maxApplyDepth expects a positiv integer as argument. By default, the xslt engine allows xslt templates to nest up to 3000 levels (and raises error if they nest deeper). This limit can be set by the -maxApplyDepth option. 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". If the called script returns anything else then TCL_OK then the xslt transformation will be aborted, returning error. If the called script returns -code break, the error message is empty, otherwise the result code is reported. In case of terminated transformation, the outputVar, if given, is set to the empty string.
The syntax of the created xsltCmd is: xsltCmd method ?arg ...? The valid methods are:
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 option -maxApplyDepth expects a positiv integer as argument. By default, the xslt engine allows xslt templates to nest up to 3000 levels (and raises error if they nest deeper). This limit can be set by the -maxApplyDepth option. 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".
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.
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 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. 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 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. 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 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 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 deleteXPathCache method, to force a recompilation. Without using the -cache option such consideration is never needed. 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="http://www.defaultnamespace.org"><child/></doc>}] set root [$doc documentElement] set childNodes [$root selectNodes -namespaces {default http://www.defaultnamespace.org} default:child]
Otherwise, if an unknown method name is given, the command with the same name as the given method 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 automatically deleted as soon as the whole document gets deleted. SEE ALSOdom, domNodeKEYWORDSDOM node creation, document element
Visit the GSP FreeBSD Man Page Interface. |