Xml Tcl Reference Documentation

Xml

A free non-validating XML parser component with encryption and compression features.

Object Creation

set myXml [new CkXml]

Properties

Cdata (boolean 1/0)

set boolVal [CkXml_get_Cdata $myXml]
CkXml_put_Cdata $myXml $boolVal

When True, causes an XML node's content to be encapsulated in a CDATA section.

Using CDATA in XML

Content (string)

# ckStr is a CkString
CkXml_get_Content $myXml $ckStr
set strVal [CkXml_get_content $myXml]
CkXml_put_Content $myXml $strVal

The content of the XML node. It is the text between the open and close tags, not including child nodes. For example:

<tag1>This is the content</tag1>

<tag2><child1>abc</child1><child2>abc</child2>This is the content</tag2>
Because the child nodes are not included, the content of "tag1" and "tag2" are both equal to "This is the content".

Content vs. Children: A common misconception explained.

Setting XML Tag and Content

ContentInt (integer)

set intVal [CkXml_get_ContentInt $myXml]
CkXml_put_ContentInt $myXml $intVal

Set/get the content as an integer.

DebugLogFilePath (string)

# ckStr is a CkString
CkXml_get_DebugLogFilePath $myXml $ckStr
set strVal [CkXml_get_debugLogFilePath $myXml]
CkXml_put_DebugLogFilePath $myXml $strVal

If set to a file path, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

DocType (string)

# ckStr is a CkString
CkXml_get_DocType $myXml $ckStr
set strVal [CkXml_get_docType $myXml]
CkXml_put_DocType $myXml $strVal

The DOCTYPE declaration (if any) for the XML document.

Setting the XML DOCTYPE

EmitBom (boolean 1/0)

set boolVal [CkXml_get_EmitBom $myXml]
CkXml_put_EmitBom $myXml $boolVal

Introduced in version 9.5.0.44

If 1, then emit the BOM (byte order mark, also known as a preamble) for encodings such as utf-8, utf-16, etc. The defautl value is 0. This only applies when writing XML files. It does not apply when getting the XML as a string via the GetXml method.

EmitCompact (boolean 1/0)

set boolVal [CkXml_get_EmitCompact $myXml]
CkXml_put_EmitCompact $myXml $boolVal

Introduced in version 9.5.0.64

If 1, then GetXml and GetXmlSb emit compact XML. The XML emitted has no unnecessary whitespace, incuding no end-of-lines (CR's and/or LF's). The default value is 0, which maintains backward compatibility.

XML EmitCompact

EmitXmlDecl (boolean 1/0)

set boolVal [CkXml_get_EmitXmlDecl $myXml]
CkXml_put_EmitXmlDecl $myXml $boolVal

If 1, then the XML declaration is emitted for methods (such as GetXml or SaveXml) where the XML is written to a file or string. The default value of this property is 1. If set to 0, the XML declaration is not emitted. (The XML declaration is the 1st line of an XML document starting with "<?xml ...".

Encoding (string)

# ckStr is a CkString
CkXml_get_Encoding $myXml $ckStr
set strVal [CkXml_get_encoding $myXml]
CkXml_put_Encoding $myXml $strVal

This is the encoding attribute in the XML declaration, such as "utf-8" or "iso-8859-1". The default is "utf-8". This property can be set from any node in the XML document and when set, causes the encoding property to be added to the XML declaration. Setting this property does not cause the document to be converted to a different encoding.

Calling any of the LoadXml* methods causes this property to be set to the charset found within the XML, if any. If no charset is specified within the loaded XML, then the LoadXml method resets this property to its default value of "utf-8".

I (integer)

set intVal [CkXml_get_I $myXml]
CkXml_put_I $myXml $intVal

Introduced in version 9.5.0.64

Used in tagPaths (and ChilkatPath). The value of this property is substituted for "i" in "[i]". See the example below..

Demonstrate the XML "I" Property

Demonstrate the XML I, J, and K Properties

J (integer)

set intVal [CkXml_get_J $myXml]
CkXml_put_J $myXml $intVal

Introduced in version 9.5.0.64

Used in tagPaths (and ChilkatPath). The value of this property is substituted for "j" in "[j]". See the example below..

Demonstrate the XML I, J, and K Properties

K (integer)

set intVal [CkXml_get_K $myXml]
CkXml_put_K $myXml $intVal

Introduced in version 9.5.0.64

Used in tagPaths (and ChilkatPath). The value of this property is substituted for "k" in "[k]". See the example below..

LastErrorHtml (string)

# ckStr is a CkString
CkXml_get_LastErrorHtml $myXml $ckStr
set strVal [CkXml_get_lastErrorHtml $myXml]

Provides information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

LastErrorText (string)

# ckStr is a CkString
CkXml_get_LastErrorText $myXml $ckStr
set strVal [CkXml_get_lastErrorText $myXml]

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

Concept of LastErrorText

LastErrorText Standard Information

LastErrorXml (string)

# ckStr is a CkString
CkXml_get_LastErrorXml $myXml $ckStr
set strVal [CkXml_get_lastErrorXml $myXml]

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

LastMethodSuccess (boolean 1/0)

set boolVal [CkXml_get_LastMethodSuccess $myXml]
CkXml_put_LastMethodSuccess $myXml $boolVal

Introduced in version 9.5.0.52

Indicate whether the last method call succeeded or failed. A value of 1 indicates success, a value of 0 indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = 1 and failure = 0.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to 1. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

NumAttributes (integer)

set intVal [CkXml_get_NumAttributes $myXml]

The number of attributes. For example, the following node has 2 attributes:

<tag attr1="value1" attr2="value2"> This is the content</tag>

Methods for Getting Attributes

NumChildren (integer)

set intVal [CkXml_get_NumChildren $myXml]

The number of direct child nodes contained under this XML node.

SortCaseInsensitive (boolean 1/0)

set boolVal [CkXml_get_SortCaseInsensitive $myXml]
CkXml_put_SortCaseInsensitive $myXml $boolVal

If true (or 1 for ActiveX), then all Sort* methods use case insensitive sorting.

Standalone (boolean 1/0)

set boolVal [CkXml_get_Standalone $myXml]
CkXml_put_Standalone $myXml $boolVal

This is the standalone attribute in the XML declaration. This property can be set from any node in the XML document. A value of 1 adds a standalone="yes" to the XML declaration:

<?xml ... standalone="yes">

Tag (string)

# ckStr is a CkString
CkXml_get_Tag $myXml $ckStr
set strVal [CkXml_get_tag $myXml]
CkXml_put_Tag $myXml $strVal

The XML node's tag.

Setting XML Tag and Content

TreeId (integer)

set intVal [CkXml_get_TreeId $myXml]

Each tree (or XML document) has a unique TreeId. This is the ID of the tree, and can be used to determine if two Xml objects belong to the same tree.

Utf8 (boolean 1/0)

set boolVal [CkXml_get_Utf8 $myXml]
CkXml_put_Utf8 $myXml $boolVal

When set to 1, all "const char *" arguments are interpreted as utf-8 strings. If set to 0 (the default), then "const char *" arguments are interpreted as ANSI strings. Also, when set to 1, and Chilkat method returning a "const char *" is returning the utf-8 representation. If set to 0, all "const char *" return values are ANSI strings.

VerboseLogging (boolean 1/0)

set boolVal [CkXml_get_VerboseLogging $myXml]
CkXml_put_VerboseLogging $myXml $boolVal

If set to 1, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is 0. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

Version (string)

# ckStr is a CkString
CkXml_get_Version $myXml $ckStr
set strVal [CkXml_get_version $myXml]

Version of the component/library, such as "9.5.0.63"

Methods

# tag is a string
# skipTags is a string
# outStr is a CkString (output)
set status [CkXml_AccumulateTagContent $tag $skipTags $outStr]
set retStr [CkXml_accumulateTagContent $myXml $tag $skipTags]

Accumulates the content of all nodes having a specific tag into a single result string. SkipTags specifies a set of subtrees to be avoided. The skipTags are formatted as a string of tags delimited by vertical bar characters. All nodes in sub-trees rooted with a tag appearing in skipTags are not included in the result.

Returns 1 for success, 0 for failure.

XML Accumulate Tag Content

# name is a string
# value is a string
set status [CkXml_AddAttribute $name $value]

Adds an attribute to the calling node in the XML document. Returns True for success, and False for failure.

Returns 1 for success, 0 for failure.

Adding Attributes to an XML Node

AddAttribute - Insert New Attribute in XML Node

# name is a string
# value is an integer
set status [CkXml_AddAttributeInt $name $value]

Adds an integer attribute to a node.

Returns 1 for success, 0 for failure.

# tree is a CkXml
set status [CkXml_AddChildTree $tree]

Adds an entire subtree as a child. If the child was a subtree within another Xml document then the subtree is effectively transferred from one XML document to another.

Returns 1 for success, 0 for failure.

# name is a string
# value is a string
CkXml_AddOrUpdateAttribute $name $value

Adds an attribute to an XML node. If an attribute having the specified name already exists, the value is updated.

Update an XML Attribute

# name is a string
# value is an integer
CkXml_AddOrUpdateAttributeI $name $value

Adds an integer attribute to an XML node. If an attribute having the specified name already exists, the value is updated.

# styleSheet is a string
CkXml_AddStyleSheet $styleSheet

Adds a style sheet declaration to the XML document. The styleSheet should be a string such as:

<?xml-stylesheet href="mystyle.css" title="Compact" type="text/css"?>

# name is a string
# amount is an integer
CkXml_AddToAttribute $name $amount

Adds an integer amount to an integer attribute's value. If the attribute does not yet exist, this method behaves the same as AddOrUpdateAttributeI.

Update an XML Attribute

# tag is a string
# amount is an integer
CkXml_AddToChildContent $tag $amount

Adds an integer value to the content of a child node.

# amount is an integer
CkXml_AddToContent $amount

Adds an integer amount to the node's content.

# str is a string
set status [CkXml_AppendToContent $str]

Appends text to the content of an XML node

Returns 1 for success, 0 for failure.

# charset is a string
# inData is a CkByteData
set status [CkXml_BEncodeContent $charset $inData]

Sets the node's content with 8bit data that is in a specified multibyte character encoding such as utf-8, shift-jis, big5, etc. The data is first B-encoded and the content is set to be the B-encoded string. For example, if called with "Big5"for the charset, you would get a string that looks something like this: "=?Big5?B?pHCtsw==?=". The data is Base64-encoded and stored between the last pair of "?" delimiters. Use the DecodeContent method to retrieve the byte data from a B encoded string.

Returns 1 for success, 0 for failure.

# tagPath is a string
# pattern is a string
# caseSensitive is a boolean
set retBool [CkXml_ChildContentMatches $tagPath $pattern $caseSensitive]

Return 1 if a child at the specified tagPath contains content that matches a wildcarded pattern. Otherwise returns 0.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

# pathCmd is a string
# outStr is a CkString (output)
set status [CkXml_ChilkatPath $pathCmd $outStr]
set retStr [CkXml_chilkatPath $myXml $pathCmd]

Follows a series of commands to navigate through an XML document to return a piece of data or update the caller's reference to a new XML document node.

Note: This method not related to the XPath (XML Path) standard in any way.

The pathCmd is formatted as a series of commands separated by vertical bar characters, and terminated with a return-command:

    command|command|command|...|returnCommand

A command can be any of the following:

  1. TagName -- Navigate to the 1st direct child with the given tag.
  2. TagName[n] -- Navigate to the Nth direct child with the given tag.
  3. .. -- Navigate up to the parent
  4. TagName{Content} -- Navigate to the 1st direct child with the given tag having the exact content.
  5. /T/TagName -- Traverse the XML DOM tree (rooted at the caller) and navigate to the 1st node having the given tag.
  6. /C/TagName,ContentPattern -- Traverse the XML DOM tree (rooted at the caller) and navigate to the 1st node having the given tag with content that matches the ContentPattern. ContentPattern may use one or more asterisk ('*") characters to represent 0 or more of any character.
  7. /C/ContentPattern -- Traverse the XML DOM tree (rooted at the caller) and navigate to the 1st node having any tag with content that matches the ContentPattern. ContentPattern may use one or more asterisk ('*") characters to represent 0 or more of any character.
  8. /A/TagName,AttrName,AttrValuePattern -- Traverse the XML DOM tree (rooted at the caller) and navigate to the 1st node having the given tag, and attribute, with the attribute value that matches the AttrValuePattern. AttrValuePattern may use one or more asterisk ('*") characters to represent 0 or more of any character.
The returnCommand can be any of the following:
  1. * -- Return the Content of the node.
  2. (AttrName) -- Return the value of the given attribute.
  3. $ -- Update the caller's internal reference to be the node (arrived at by following the series of commands). Returns an empty string.

Returns 1 for success, 0 for failure.

ChilkatPath Sample Code

Get XML Attribute Value by Path

CkXml_Clear

Removes all children, attributes, and content from the XML node. Resets the tag name to "unnamed".

# pattern is a string
# caseSensitive is a boolean
set retBool [CkXml_ContentMatches $pattern $caseSensitive]

Return true if the node's content matches a wildcarded pattern.

# node is a CkXml
CkXml_Copy $node

Copies the tag, content, and attributes to the calling node.

# copyFromNode is a CkXml
CkXml_CopyRef $copyFromNode

Discards the caller's current internal reference and copies the internal reference from copyFromNode. Effectively updates the caller node to point to the same node in the XML document as copyFromNode.

# outData is a CkByteData (output)
set status [CkXml_DecodeContent $outData]

Decodes a node's Q or B-encoded content string and returns the byte data.

Returns 1 for success, 0 for failure.

# str is a string
# outStr is a CkString (output)
set status [CkXml_DecodeEntities $str $outStr]
set retStr [CkXml_decodeEntities $myXml $str]

Utility method to decode HTML entities. It accepts a string containing (potentially) HTML entities and returns a string with the entities decoded.

Returns 1 for success, 0 for failure.

# password is a string
set status [CkXml_DecryptContent $password]

Decrypts the content of an XML node that was previously 128-bit AES encrypted with the EncryptContent method.

Returns 1 for success, 0 for failure.

Encrypting and Decrypting Content

# password is a string
set status [CkXml_EncryptContent $password]

Encrypts the content of the calling XML node using 128-bit CBC AES encryption. The base64-encoded encrypted content replaces the original content.

Returns 1 for success, 0 for failure.

Encrypting and Decrypting Content

# returns a CkXml
# index is an integer
set ret_xml [CkXml_ExtractChildByIndex $index]

Removes and returns the Nth child of an XML node. The first child is at index 0.

Returns NULL on failure

# returns a CkXml
# tagPath is a string
# attrName is a string
# attrValue is a string
set ret_xml [CkXml_ExtractChildByName $tagPath $attrName $attrValue]

Removes and returns the first child node at the specified tag or tag path. The attrName and attrValue may be empty, in which case the first child matching the tag is removed and returned. If attrName is specified, then the first child having a tag equal to tagPath, and an attribute with attrName is returned. If attrValue is also specified, then only a child having a tag equal to tagPath, and an attribute named attrName, with a value equal to attrValue is returned.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

Returns NULL on failure

ExtractChildByName using a Tag Path

# returns a CkXml
# tagPath is a string
set ret_xml [CkXml_FindChild $tagPath]

Returns the child with the given tag or at the specified tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

Returns NULL on failure

Find Direct Child with Specific Tag

Access SOAP Body XML

# tagPath is a string
set status [CkXml_FindChild2 $tagPath]

Updates the Xml object's internal reference to point to a child at the specified tag or tagPath.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

Returns 1 for success, 0 for failure.

Find Direct Child with Specific Tag

Benefit of XML Methods Having Names Ending in "2"

# returns a CkXml
# tagPath is a string
# contentPattern is a string
set ret_xml [CkXml_FindNextRecord $tagPath $contentPattern]

Returns the next record node where the child with a specific tag matches a wildcarded pattern. This method makes it easy to iterate over high-level records.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

Returns NULL on failure

Demonstrate the XML FindNextRecord Method

# returns a CkXml
# tagPath is a string
set ret_xml [CkXml_FindOrAddNewChild $tagPath]

First checks for a child at tagPath, and if found, returns it. Otherwise creates a new child with empty content.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

Returns NULL on failure

# returns a CkXml
set ret_xml [CkXml_FirstChild]

Returns the first child. A program can step through the children by calling FirstChild, and then NextSibling repeatedly.

Returns NULL on failure

Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling

set status [CkXml_FirstChild2]

Updates the internal reference of the caller to point to its first child.

Returns 1 for success, 0 for failure.

More information about XML methods ending in "2"

Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling

Benefit of XML Methods Having Names Ending in "2"

# index is an integer
# outStr is a CkString (output)
set status [CkXml_GetAttributeName $index $outStr]
set retStr [CkXml_getAttributeName $myXml $index]

Returns the name of the Nth attribute of an XML node. The first attribute is at index 0.

Returns 1 for success, 0 for failure.

Methods for Getting Attributes

# index is an integer
# outStr is a CkString (output)
set status [CkXml_GetAttributeValue $index $outStr]
set retStr [CkXml_getAttributeValue $myXml $index]

Returns the value of the Nth attribute of an XML node. The first attribute is at index 0.

Returns 1 for success, 0 for failure.

Methods for Getting Attributes

# index is an integer
set retInt [CkXml_GetAttributeValueInt $index]

Returns an attribute as an integer. Returns 0 if the attribute does not exist.

# name is a string
# outStr is a CkString (output)
set status [CkXml_GetAttrValue $name $outStr]
set retStr [CkXml_getAttrValue $myXml $name]

Find and return the value of an attribute having a specified name.

Returns 1 for success, 0 for failure.

Methods for Getting Attributes

# name is a string
set retInt [CkXml_GetAttrValueInt $name]

Returns an attribute as an integer. Returns 0 if the attribute does not exist.

Methods for Getting Attributes

# unzipFlag is a boolean
# decryptFlag is a boolean
# password is a string
# outData is a CkByteData (output)
set status [CkXml_GetBinaryContent $unzipFlag $decryptFlag $password $outData]

Returns binary content of an XML node as a byte array. The content may have been Zip compressed, AES encrypted, or both. Unzip compression and AES decryption flags should be set appropriately.

Returns 1 for success, 0 for failure.

# returns a CkXml
# index is an integer
set ret_xml [CkXml_GetChild $index]

Returns the Nth child of an XML node

Returns NULL on failure

Iterate over Direct Child Nodes by Index

# index is an integer
set status [CkXml_GetChild2 $index]

Updates the calling object's internal reference to the Nth child node.

Returns 1 for success, 0 for failure.

More information about XML methods ending in "2"

Iterate over Direct Child Nodes by Index

Benefit of XML Methods Having Names Ending in "2"

# tagPath is a string
set retBool [CkXml_GetChildBoolValue $tagPath]

Returns 0 if the node's content is "0", otherwise returns 1 if the node contains a non-zero integer. The tagPath can be a tag or a tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "colors|primary|red".

Demonstrate the XML "I" Property

# tagPath is a string
# outStr is a CkString (output)
set status [CkXml_GetChildContent $tagPath $outStr]
set retStr [CkXml_getChildContent $myXml $tagPath]

Returns the content of a child having a specified tag. The tagPath can be a tag or a tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "colors|primary|red".

Returns 1 for success, 0 for failure.

Demonstrate the XML "I" Property

# index is an integer
# outStr is a CkString (output)
set status [CkXml_GetChildContentByIndex $index $outStr]
set retStr [CkXml_getChildContentByIndex $myXml $index]

Returns the content of the Nth child node.

Returns 1 for success, 0 for failure.

Iterate over Direct Child Nodes by Index

SQS List Queues

# returns a CkXml
# tag is a string
# content is a string
set ret_xml [CkXml_GetChildExact $tag $content]

Returns the child having the exact tag and content.

Returns NULL on failure

# tagPath is a string
set retInt [CkXml_GetChildIntValue $tagPath]

Returns the child integer content for a given tag. The tagPath can be a tag or a tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "colors|primary|red".

Demonstrate the XML "I" Property

# index is an integer
# outStr is a CkString (output)
set status [CkXml_GetChildTag $index $outStr]
set retStr [CkXml_getChildTag $myXml $index]

Returns the tag name of the Nth child node.

Returns 1 for success, 0 for failure.

# index is an integer
# outStr is a CkString (output)
set status [CkXml_GetChildTagByIndex $index $outStr]
set retStr [CkXml_getChildTagByIndex $myXml $index]

Returns the tag name of the Nth child node.

Returns 1 for success, 0 for failure.

Iterate over Direct Child Nodes by Index

# returns a CkXml
# tagPath is a string
# attrName is a string
# attrValue is a string
set ret_xml [CkXml_GetChildWithAttr $tagPath $attrName $attrValue]

Finds and returns the XML child node having both a given tag and an attribute with a given name and value.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

Returns NULL on failure

XML GetChildWithAttr

# returns a CkXml
# content is a string
set ret_xml [CkXml_GetChildWithContent $content]

Returns the first child found having the exact content specified.

Returns NULL on failure

# returns a CkXml
# tagPath is a string
set ret_xml [CkXml_GetChildWithTag $tagPath]

Returns the child at the specified tag or tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

Returns NULL on failure

# returns a CkXml
# tag is a string
# n is an integer
set ret_xml [CkXml_GetNthChildWithTag $tag $n]

Returns the Nth child having a tag that matches exactly with the tagName. Use the NumChildrenHavingTag method to determine how many children have a particular tag.

Returns NULL on failure

Iterate over Direct Children with a Specific Tag

# tag is a string
# n is an integer
set status [CkXml_GetNthChildWithTag2 $tag $n]

Updates the calling object's internal reference to the Nth child node having a specific tag.

Returns 1 for success, 0 for failure.

Iterate over Direct Children with a Specific Tag

Benefit of XML Methods Having Names Ending in "2"

# returns a CkXml
set ret_xml [CkXml_GetParent]

Returns the parent of this XML node, or NULL if the node is the root of the tree.

Returns NULL on failure

set status [CkXml_GetParent2]

Updates the internal reference of the caller to its parent.

Returns 1 for success, 0 for failure.

More information about XML methods ending in "2"

Benefit of XML Methods Having Names Ending in "2"

# returns a CkXml
set ret_xml [CkXml_GetRoot]

Returns the root node of the XML document

Returns NULL on failure

CkXml_GetRoot2

Updates the internal reference of the caller to the document root.

More information about XML methods ending in "2"

Benefit of XML Methods Having Names Ending in "2"

# returns a CkXml
set ret_xml [CkXml_GetSelf]

Returns a new XML object instance that references the same XML node.

Returns NULL on failure

# outStr is a CkString (output)
set status [CkXml_GetXml $outStr]
set retStr [CkXml_getXml $myXml]

Generate the XML text document for the XML tree rooted at this node. If called from the root node of the XML document, then the XML declarator ("<?xml version="1.0" encoding="utf-8" ?>") is included at the beginning of the XML. Otherwise, it is not included.

Returns 1 for success, 0 for failure.

# sb is a CkStringBuilder
set status [CkXml_GetXmlSb $sb]

Introduced in version 9.5.0.62

Emits the XML to a StringBuilder object. (Appends to the existing contents of sb.)

Returns 1 for success, 0 for failure.

# name is a string
set retBool [CkXml_HasAttribute $name]

Returns true if the node contains an attribute with the specified name.

# name is a string
# value is a string
set retBool [CkXml_HasAttrWithValue $name $value]

Returns true if the node contains attribute with the name and value.

# content is a string
set retBool [CkXml_HasChildWithContent $content]

Returns true if the node has a direct child node containing the exact content string specified.

# tagPath is a string
set retBool [CkXml_HasChildWithTag $tagPath]

Returns 1 if the node has a child with the given tag (or tag path). Otherwise returns 0.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

UpdateChildContent using a Tag Path

# tagPath is a string
# content is a string
set retBool [CkXml_HasChildWithTagAndContent $tagPath $content]

Returns 1 if the node contains child with the given tag (or tag path) and content specified.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

# index is an integer
# tree is a CkXml
CkXml_InsertChildTreeAfter $index $tree

Adds an entire subtree as a child. If the child was a subtree within another Xml document then the subtree is effectively transferred from one XML document to another. The child tree is inserted in a position after the Nth child (of the calling node).

# index is an integer
# tree is a CkXml
CkXml_InsertChildTreeBefore $index $tree

Adds an entire subtree as a child. If the child was a subtree within another Xml document then the subtree is effectively transferred from one XML document to another. The child tree is inserted in a position before the Nth child (of the calling node).

# returns a CkXml
set ret_xml [CkXml_LastChild]

Returns the last Xml child node. A node's children can be enumerated by calling LastChild and then repeatedly calling PreviousSibling, until a NULL is returned.

Returns NULL on failure

Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling

set status [CkXml_LastChild2]

Updates the internal reference of the caller to its last child.

Returns 1 for success, 0 for failure.

Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling

Benefit of XML Methods Having Names Ending in "2"

# sb is a CkStringBuilder
# autoTrim is a boolean
set status [CkXml_LoadSb $sb $autoTrim]

Introduced in version 9.5.0.62

Loads XML from the contents of a StringBuilder object.

Returns 1 for success, 0 for failure.

# xmlData is a string
set status [CkXml_LoadXml $xmlData]

Loads an XML document from a memory buffer and returns 1 if successful. The contents of the calling node are replaced with the root node of the XML document loaded.

Returns 1 for success, 0 for failure.

# xmlData is a string
# autoTrim is a boolean
set status [CkXml_LoadXml2 $xmlData $autoTrim]

Same as LoadXml, but an additional argument controls whether or not leading/trailing whitespace is auto-trimmed from each node's content.

Returns 1 for success, 0 for failure.

# fileName is a string
set status [CkXml_LoadXmlFile $fileName]

Loads an XML document from a file and returns 1 if successful. The contents of the calling node are replaced with the root node of the XML document loaded.

Returns 1 for success, 0 for failure.

# fileName is a string
# autoTrim is a boolean
set status [CkXml_LoadXmlFile2 $fileName $autoTrim]

Same as LoadXmlFile, but an additional argument controls whether or not leading/trailing whitespace is auto-trimmed from each node's content.

Returns 1 for success, 0 for failure.

# returns a CkXml
# tagPath is a string
# content is a string
set ret_xml [CkXml_NewChild $tagPath $content]

Creates a new child having tag and content. The new child is created even if a child with a tag equal to tagPath already exists. (Use FindOrAddNewChild to prevent creating children having the same tags.)

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "colors|primary|red". See the example below for details.

Returns NULL on failure

Creating a New Child Node

NewChild using a Tag Path

# tagPath is a string
# content is a string
CkXml_NewChild2 $tagPath $content

Creates a new child node, but does not return the node that is created. The tagPath can be a tag or a tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "colors|primary|red". See the example below for details.

Creating a New Child Node

XML NewChild2 using a Tag Path

# returns a CkXml
# index is an integer
# tag is a string
# content is a string
set ret_xml [CkXml_NewChildAfter $index $tag $content]

Inserts a new child in a position after the Nth child node.

Returns NULL on failure

# returns a CkXml
# index is an integer
# tag is a string
# content is a string
set ret_xml [CkXml_NewChildBefore $index $tag $content]

Inserts a new child in a position before the Nth child node.

Returns NULL on failure

# tagPath is a string
# value is an integer
CkXml_NewChildInt2 $tagPath $value

Inserts a new child having an integer for content. The tagPath can be a tag or a tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "colors|primary|red". See the example below for details.

Demonstrate the XML NewChildInt2 Method

# returns a CkXml
set ret_xml [CkXml_NextSibling]

Returns the nodes next sibling, or NULL if there are no more.

Returns NULL on failure

Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling

set status [CkXml_NextSibling2]

Updates the internal reference of the caller to its next sibling.

Returns 1 for success, 0 for failure.

More information about XML methods ending in "2"

Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling

Benefit of XML Methods Having Names Ending in "2"

# tagPath is a string
set retInt [CkXml_NumChildrenAt $tagPath]

Introduced in version 9.5.0.64

Returns the number of children for the node indicated by tagPath. Returns -1 if the node at tagPath does not exist.

Demonstrate the XML "I" Property

Demonstrate the XML I, J, and K Properties

Get XML Attribute Value by Path

# tag is a string
set retInt [CkXml_NumChildrenHavingTag $tag]

Returns the number of children having a specific tag name.

Iterate over Direct Children with a Specific Tag

# returns a CkXml
set ret_xml [CkXml_PreviousSibling]

Returns the Xml object that is the node's previous sibling, or NULL if there are no more.

Returns NULL on failure

Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling

set status [CkXml_PreviousSibling2]

Updates the internal reference of the caller to its previous sibling.

Returns 1 for success, 0 for failure.

More information about XML methods ending in "2"

Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling

Benefit of XML Methods Having Names Ending in "2"

# charset is a string
# inData is a CkByteData
set status [CkXml_QEncodeContent $charset $inData]

Sets the node's content with 8bit data that is in a specified multibyte character encoding such as utf-8, shift-jis, big5, etc. The data is first Q-encoded and the content is set to be the Q-encoded string. For example, if called with "gb2312"for the charset, you would get a string that looks something like this: "=?gb2312?Q?=C5=B5=BB=F9?=". Character that are not 7bit are represented as "=XX" where XX is the hexidecimal value of the byte. Use the DecodeContent method to retrieve the byte data from a Q encoded string.

Returns 1 for success, 0 for failure.

set status [CkXml_RemoveAllAttributes]

Removes all attributes from an XML node. Should always return True.

Returns 1 for success, 0 for failure.

CkXml_RemoveAllChildren

Removes all children from the calling node.

# name is a string
set status [CkXml_RemoveAttribute $name]

Removes an attribute by name from and XML node.

Returns 1 for success, 0 for failure.

# tagPath is a string
CkXml_RemoveChild $tagPath

Removes all children with a given tag or tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

Removing / Deleting Child Nodes from XML

RemoveChild using a Tag Path

# index is an integer
CkXml_RemoveChildByIndex $index

Removes the Nth child from the calling node.

Removing / Deleting Child Nodes from XML

# content is a string
CkXml_RemoveChildWithContent $content

Removes all children having the exact content specified.

Removing / Deleting Child Nodes from XML

CkXml_RemoveFromTree

Removes the calling object and its sub-tree from the XML document making it the root of its own tree.

Removing / Deleting Child Nodes from XML

# filename is a string
# unzipFlag is a boolean
# decryptFlag is a boolean
# password is a string
set status [CkXml_SaveBinaryContent $filename $unzipFlag $decryptFlag $password]

Saves a node's binary content to a file.

Returns 1 for success, 0 for failure.

# path is a string
set status [CkXml_SaveLastError $path]

Saves the last-error information (the contents of LastErrorXml) to an XML formatted file.

Returns 1 for success, 0 for failure.

# fileName is a string
set status [CkXml_SaveXml $fileName]

Generates XML representing the tree or subtree rooted at this node and writes it to a file.

Returns 1 for success, 0 for failure.

# returns a CkXml
# afterPtr is a CkXml
# contentPattern is a string
set ret_xml [CkXml_SearchAllForContent $afterPtr $contentPattern]

Returns the first node having content matching the contentPattern. The contentPattern is a case-sensitive string that may contain any number of '*'s, each representing 0 or more occurrences of any character. The search is breadth-first over the sub-tree rooted at the caller. A match is returned only after the search has traversed past the node indicated by afterPtr. To find the 1st occurrence, set afterPtr equal to NULL. (For the ActiveX implementation, the afterPtr should never be NULL. A reference to the caller's node should be passed instead.)

To iterate over matching nodes, the returned node can be passed in afterPtr for the next call to SearchAllForContent, until the method returns NULL.

Returns NULL on failure

XML Tree Traversal Order for Search* Methods

# afterPtr is a CkXml
# contentPattern is a string
set status [CkXml_SearchAllForContent2 $afterPtr $contentPattern]

Same as SearchAllForContent except the internal reference of the caller is updated to point to the search result (instead of returning a new object).

Returns 1 for success, 0 for failure.

# returns a CkXml
# afterPtr is a CkXml
# tag is a string
# attr is a string
# valuePattern is a string
set ret_xml [CkXml_SearchForAttribute $afterPtr $tag $attr $valuePattern]

Returns the first node having a tag equal to tag, an attribute named attr, whose value matches valuePattern. The valuePattern is a case-sensitive string that may contain any number of '*'s, each representing 0 or more occurrences of any character. The search is breadth-first over the sub-tree rooted at the caller. A match is returned only after the search has traversed past the node indicated by afterPtr. To find the 1st occurrence, set afterPtr equal to NULL. (For the ActiveX implementation, the afterPtr should never be NULL. A reference to the caller's node should be passed instead.)

To iterate over matching nodes, the returned node can be passed in afterPtr for the next call to SearchForAttribute, until the method returns NULL.

Returns NULL on failure

XML SearchForAttribute Method

XML Tree Traversal Order for Search* Methods

# afterPtr is a CkXml
# tag is a string
# attr is a string
# valuePattern is a string
set status [CkXml_SearchForAttribute2 $afterPtr $tag $attr $valuePattern]

Same as SearchForAttribute except the internal reference of the caller is updated to point to the search result (instead of returning a new object).

Returns 1 for success, 0 for failure.

# returns a CkXml
# afterPtr is a CkXml
# tag is a string
# contentPattern is a string
set ret_xml [CkXml_SearchForContent $afterPtr $tag $contentPattern]

Returns the first node having a tag equal to tag, whose content matches contentPattern. The contentPattern is a case-sensitive string that may contain any number of '*'s, each representing 0 or more occurrences of any character. The search is breadth-first over the sub-tree rooted at the caller. A match is returned only after the search has traversed past the node indicated by afterPtr. To find the 1st occurrence, set afterPtr equal to NULL. (For the ActiveX implementation, the afterPtr should never be NULL. A reference to the caller's node should be passed instead.)

To iterate over matching nodes, the returned node can be passed in afterPtr for the next call to SearchForContent, until the method returns NULL.

Returns NULL on failure

XML Tree Traversal Order for Search* Methods

# afterPtr is a CkXml
# tag is a string
# contentPattern is a string
set status [CkXml_SearchForContent2 $afterPtr $tag $contentPattern]

Same as SearchForContent except the internal reference of the caller is updated to point to the search result (instead of returning a new object).

Returns 1 for success, 0 for failure.

XML Tree Traversal Order for Search* Methods

# returns a CkXml
# afterPtr is a CkXml
# tag is a string
set ret_xml [CkXml_SearchForTag $afterPtr $tag]

Returns the first node having a tag equal to tag. The search is breadth-first over the sub-tree rooted at the caller. A match is returned only after the search has traversed past the node indicated by afterPtr. To find the 1st occurrence, set afterPtr equal to NULL. (For the ActiveX implementation, the afterPtr should never be NULL. A reference to the caller's node should be passed instead.)

To iterate over matching nodes, the returned node can be passed in afterPtr for the next call to SearchForTag, until the method returns NULL.

Returns NULL on failure

XML SearchForTag Method

XML Tree Traversal Order for Search* Methods

# afterPtr is a CkXml
# tag is a string
set status [CkXml_SearchForTag2 $afterPtr $tag]

Same as SearchForTag except the internal reference of the caller is updated to point to the search result (instead of returning a new object).

Returns 1 for success, 0 for failure.

# inData is a CkByteData
# zipFlag is a boolean
# encryptFlag is a boolean
# password is a string
set status [CkXml_SetBinaryContent $inData $zipFlag $encryptFlag $password]

Sets the node's content to a block of binary data with optional Zip compression and/or AES encryption. The binary data is automatically converted to base64 format whenever XML text is generated. If the zipFlag is True, the data is first compressed. If the encryptFlag is True, the data is AES encrypted using the Rijndael 128-bit symmetric-encryption algorithm.

Returns 1 for success, 0 for failure.

# filename is a string
# zipFlag is a boolean
# encryptFlag is a boolean
# password is a string
set status [CkXml_SetBinaryContentFromFile $filename $zipFlag $encryptFlag $password]

Sets the node's content with binary (or text) data from a file. The file contents can be Zip compressed and/or encrypted, and the result is base-64 encoded.

Returns 1 for success, 0 for failure.

# attrName is a string
# ascending is a boolean
CkXml_SortByAttribute $attrName $ascending

Sorts the direct child nodes by the value of a specified attribute.

# attrName is a string
# ascending is a boolean
CkXml_SortByAttributeInt $attrName $ascending

Sorts the direct child nodes by the value of a specified attribute interpreted as an integer (not lexicographically as strings).

# ascending is a boolean
CkXml_SortByContent $ascending

Sorts the direct child nodes by content.

XML Sort by Content

# ascending is a boolean
CkXml_SortByTag $ascending

Sorts the direct child nodes by tag.

XML Sort by Tag

# sortTag is a string
# attrName is a string
# ascending is a boolean
CkXml_SortRecordsByAttribute $sortTag $attrName $ascending

Sorts the direct child nodes by the content of an attribute in the grandchild nodes.

# sortTag is a string
# ascending is a boolean
CkXml_SortRecordsByContent $sortTag $ascending

Sorts the direct child nodes by the content of the grandchild nodes.

XML Sort Records by Content

# sortTag is a string
# ascending is a boolean
CkXml_SortRecordsByContentInt $sortTag $ascending

Sorts the direct child nodes by the content of the grandchild nodes. For sorting purposes, the content is interpreted as an integer (not lexicographically as for strings).

# node is a CkXml
set status [CkXml_SwapNode $node]

Swaps another node's tag, content, and attributes with this one.

Returns 1 for success, 0 for failure.

# tree is a CkXml
set status [CkXml_SwapTree $tree]

Swaps another node's tag, content, attributes, and children with this one.

Returns 1 for success, 0 for failure.

# tagName is a string
# outStr is a CkString (output)
set status [CkXml_TagContent $tagName $outStr]
set retStr [CkXml_tagContent $myXml $tagName]

Returns the content of the 1st node found in the sub-tree rooted at the caller that has a given tag. (Note: The search for the node having tag ARG is not limited to the direct children of the caller.)

Returns 1 for success, 0 for failure.

# tag is a string
set retBool [CkXml_TagEquals $tag]

Returns 1 if the node's tag equals the specified string.

set status [CkXml_UnzipContent]

Unzip the content of the XML node replacing it's content with the decompressed data.

Returns 1 for success, 0 for failure.

Compress XML Content

set status [CkXml_UnzipTree]

Unzips and recreates the XML node and the entire subtree, restoring it to the state before it was zip compressed.

Returns 1 for success, 0 for failure.

Compress XML Tree

# tagPath is a string
# autoCreate is a boolean
# value is a string
set retBool [CkXml_UpdateAt $tagPath $autoCreate $value]

Introduced in version 9.5.0.64

Updates the content for the node indicated by tagPath. If autoCreate is 1, then nodes along tagPath are auto-created as needed.

Demonstrate the XML UpdateAt Method

# tagPath is a string
# autoCreate is a boolean
# attrName is a string
# attrValue is a string
set retBool [CkXml_UpdateAttrAt $tagPath $autoCreate $attrName $attrValue]

Introduced in version 9.5.0.64

Updates or adds the attribute value for the node indicated by tagPath. If autoCreate is 1, then nodes along tagPath are auto-created as needed.

Demonstrate the XML UpdateAttrAt Method

Xml.UpdateAttrAt Example #2

# attrName is a string
# attrValue is a string
set status [CkXml_UpdateAttribute $attrName $attrValue]

Adds an attribute to the node if it doesn't already exist. Otherwise it updates the existing attribute with the new value.

Returns 1 for success, 0 for failure.

Update an XML Attribute

# attrName is a string
# value is an integer
set status [CkXml_UpdateAttributeInt $attrName $value]

Updates an attribute value. (Call UpdateAttribute if the attribute value is a string.)

Returns 1 for success, 0 for failure.

# tagPath is a string
# value is a string
CkXml_UpdateChildContent $tagPath $value

Replaces the content of a child node. The tagPath can be a tag or tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

UpdateChildContent using a Tag Path

Xml.ChildContent Example #2

# tagPath is a string
# value is an integer
CkXml_UpdateChildContentInt $tagPath $value

Replaces the content of a child node where the content is an integer. The tagPath can be a tag or tag path.

Beginning in version 9.5.0.64, the tagPath can be a tag path. A tag path is a series of tags separated by vertical bar characters. For example: "tagA|tagB|tagC".

set status [CkXml_ZipContent]

Applies Zip compression to the content of an XML node and replaces the content with base64-encoded compressed data.

Returns 1 for success, 0 for failure.

Compress XML Content

set status [CkXml_ZipTree]

Zip compresses the content and entire subtree rooted at the calling XML node and replaces the current content with base64-encoded Zip compressed data. The node and subtree can be restored by calling UnzipTree. Note that the node name and attributes are unaffected.

Returns 1 for success, 0 for failure.

Compress XML Tree