CkXml CkPython Reference Documentation

CkXml

Current Version: 10.1.0

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

Object Creation

obj = chilkat.CkXml()

Properties

Cdata
# boolVal is a boolean
boolVal = xml.get_Cdata();
xml.put_Cdata(boolVal);

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

More Information and Examples
top
Content
# strVal is a string
# ckStr is a CkString
xml.get_Content(ckStr);
strVal = xml.content();
xml.put_Content(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".

top
ContentInt
# intVal is an integer
intVal = xml.get_ContentInt();
xml.put_ContentInt(intVal);

Set/get the content as an integer.

top
DebugLogFilePath
# strVal is a string
# ckStr is a CkString
xml.get_DebugLogFilePath(ckStr);
strVal = xml.debugLogFilePath();
xml.put_DebugLogFilePath(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.

More Information and Examples
top
DocType
# strVal is a string
# ckStr is a CkString
xml.get_DocType(ckStr);
strVal = xml.docType();
xml.put_DocType(strVal);

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

More Information and Examples
top
EmitBom
# boolVal is a boolean
boolVal = xml.get_EmitBom();
xml.put_EmitBom(boolVal);
Introduced in version 9.5.0.44

If True, 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 False. This only applies when writing XML files. It does not apply when getting the XML as a string via the GetXml method.

top
EmitCompact
# boolVal is a boolean
boolVal = xml.get_EmitCompact();
xml.put_EmitCompact(boolVal);
Introduced in version 9.5.0.64

If True, 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 False, which maintains backward compatibility.

More Information and Examples
top
EmitXmlDecl
# boolVal is a boolean
boolVal = xml.get_EmitXmlDecl();
xml.put_EmitXmlDecl(boolVal);

If True, 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 True. If set to False, the XML declaration is not emitted. (The XML declaration is the 1st line of an XML document starting with "<?xml ...".

top
Encoding
# strVal is a string
# ckStr is a CkString
xml.get_Encoding(ckStr);
strVal = xml.encoding();
xml.put_Encoding(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".

top
I
# intVal is an integer
intVal = xml.get_I();
xml.put_I(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..

top
IsBase64
# boolVal is a boolean
boolVal = xml.get_IsBase64();
Introduced in version 9.5.0.76

Returns True if the content contains only those characters allowed in the base64 encoding. A base64 string is composed of characters 'A'..'Z', 'a'..'z', '0'..'9', '+', '/' and it is often padded at the end with up to two '=', to make the length a multiple of 4. Whitespace is ignored.

top
J
# intVal is an integer
intVal = xml.get_J();
xml.put_J(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..

More Information and Examples
top
K
# intVal is an integer
intVal = xml.get_K();
xml.put_K(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..

top
LastErrorHtml
# strVal is a string
# ckStr is a CkString
xml.get_LastErrorHtml(ckStr);
strVal = xml.lastErrorHtml();

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.

top
LastErrorText
# strVal is a string
# ckStr is a CkString
xml.get_LastErrorText(ckStr);
strVal = xml.lastErrorText();

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.

top
LastErrorXml
# strVal is a string
# ckStr is a CkString
xml.get_LastErrorXml(ckStr);
strVal = xml.lastErrorXml();

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.

top
LastMethodSuccess
# boolVal is a boolean
boolVal = xml.get_LastMethodSuccess();
xml.put_LastMethodSuccess(boolVal);

Indicate whether the last method call succeeded or failed. A value of True indicates success, a value of False 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 = True and failure = False.
  • 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 True. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

top
NumAttributes
# intVal is an integer
intVal = xml.get_NumAttributes();

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

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

More Information and Examples
top
NumChildren
# intVal is an integer
intVal = xml.get_NumChildren();

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

top
SortCaseInsensitive
# boolVal is a boolean
boolVal = xml.get_SortCaseInsensitive();
xml.put_SortCaseInsensitive(boolVal);

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

top
Standalone
# boolVal is a boolean
boolVal = xml.get_Standalone();
xml.put_Standalone(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 True adds a standalone="yes" to the XML declaration:

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

top
Tag
# strVal is a string
# ckStr is a CkString
xml.get_Tag(ckStr);
strVal = xml.tag();
xml.put_Tag(strVal);

The XML node's tag, including the namespace prefix.

More Information and Examples
top
TagNsPrefix
# strVal is a string
# ckStr is a CkString
xml.get_TagNsPrefix(ckStr);
strVal = xml.tagNsPrefix();
xml.put_TagNsPrefix(strVal);
Introduced in version 9.5.0.77

The node's namespace prefix, if present. For example, if the tag is "soapenv:Envelope", then this property will return "soapenv".

More Information and Examples
top
TagPath
# strVal is a string
# ckStr is a CkString
xml.get_TagPath(ckStr);
strVal = xml.tagPath();
Introduced in version 9.5.0.77

Returns the path to reach this element from the XML document root. If the caller is the document root, then the empty string is returned.

More Information and Examples
top
TagUnprefixed
# strVal is a string
# ckStr is a CkString
xml.get_TagUnprefixed(ckStr);
strVal = xml.tagUnprefixed();
xml.put_TagUnprefixed(strVal);
Introduced in version 9.5.0.77

The node's tag without the namespace prefix. For example, if the tag is "soapenv:Envelope", then this property will return "Envelope".

More Information and Examples
top
TreeId
# intVal is an integer
intVal = xml.get_TreeId();

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.

top
UncommonOptions
# strVal is a string
# ckStr is a CkString
xml.get_UncommonOptions(ckStr);
strVal = xml.uncommonOptions();
xml.put_UncommonOptions(strVal);
Introduced in version 9.5.0.90

This is a catch-all property to be used for uncommon needs. This property defaults to the empty string and should typically remain empty.

top
Utf8
# boolVal is a boolean
boolVal = xml.get_Utf8();
xml.put_Utf8(boolVal);

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

top
VerboseLogging
# boolVal is a boolean
boolVal = xml.get_VerboseLogging();
xml.put_VerboseLogging(boolVal);

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

top
Version
# strVal is a string
# ckStr is a CkString
xml.get_Version(ckStr);
strVal = xml.version();

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

More Information and Examples
top

Methods

AccumulateTagContent
# tag is a string
# skipTags is a string
# outStr is a CkString (output)
status = xml.AccumulateTagContent(tag, skipTags, outStr);
retStr = xml.accumulateTagContent(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 True for success, False for failure.

More Information and Examples
top
AddAttribute
# name is a string
# value is a string
status = xml.AddAttribute(name, value);

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

Returns True for success, False for failure.

top
AddAttributeInt
# name is a string
# value is an integer
status = xml.AddAttributeInt(name, value);

Adds an integer attribute to a node.

Returns True for success, False for failure.

top
AddChildTree
# tree is a CkXml
status = xml.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 True for success, False for failure.

More Information and Examples
top
AddOrUpdateAttribute
# name is a string
# value is a string
xml.AddOrUpdateAttribute(name, value);

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

More Information and Examples
top
AddOrUpdateAttributeI
# name is a string
# value is an integer
xml.AddOrUpdateAttributeI(name, value);

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

top
AddStyleSheet
# styleSheet is a string
xml.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"?>

top
AddToAttribute
# name is a string
# amount is an integer
xml.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.

More Information and Examples
top
AddToChildContent
# tag is a string
# amount is an integer
xml.AddToChildContent(tag, amount);

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

top
AddToContent
# amount is an integer
xml.AddToContent(amount);

Adds an integer amount to the node's content.

top
AppendToContent
# str is a string
status = xml.AppendToContent(str);

Appends text to the content of an XML node

Returns True for success, False for failure.

top
BEncodeContent
# charset is a string
# inData is a CkByteData
status = xml.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 True for success, False for failure.

top
ChildContentMatches
# tagPath is a string
# pattern is a string
# caseSensitive is a boolean
retBool = xml.ChildContentMatches(tagPath, pattern, caseSensitive);

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

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".

top
ChilkatPath
# pathCmd is a string
# outStr is a CkString (output)
status = xml.ChilkatPath(pathCmd, outStr);
retStr = xml.chilkatPath(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. "++" -- Navigate to the next sibling. (next/previous sibling feature added in v9.5.0.76)
  5. "--" -- Navigate to the previous sibling.
  6. TagName{Content} -- Navigate to the 1st direct child with the given tag having the exact content.
  7. /T/TagName -- Traverse the XML DOM tree (rooted at the caller) and navigate to the 1st node having the given tag.
  8. /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.
  9. /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.
  10. /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 True for success, False for failure.

top
Clear
xml.Clear();

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

top
ContentMatches
# pattern is a string
# caseSensitive is a boolean
retBool = xml.ContentMatches(pattern, caseSensitive);

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

top
Copy
# node is a CkXml
xml.Copy(node);

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

top
CopyRef
# copyFromNode is a CkXml
xml.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.

top
DecodeContent
# outData is a CkByteData (output)
status = xml.DecodeContent(outData);

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

Returns True for success, False for failure.

top
DecodeEntities
# str is a string
# outStr is a CkString (output)
status = xml.DecodeEntities(str, outStr);
retStr = xml.decodeEntities(str);

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

Returns True for success, False for failure.

More Information and Examples
top
DecryptContent
# password is a string
status = xml.DecryptContent(password);

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

Returns True for success, False for failure.

More Information and Examples
top
EncryptContent
# password is a string
status = xml.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 True for success, False for failure.

More Information and Examples
top
ExtractChildByIndex
# returns a CkXml
# index is an integer
ret_xml = xml.ExtractChildByIndex(index);

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

Returns None on failure

top
ExtractChildByName
# returns a CkXml
# tagPath is a string
# attrName is a string
# attrValue is a string
ret_xml = xml.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 None on failure

More Information and Examples
top
FindChild
# returns a CkXml
# tagPath is a string
ret_xml = xml.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 None on failure

top
FindChild2
# tagPath is a string
status = xml.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 True for success, False for failure.

top
FindNextRecord
# returns a CkXml
# tagPath is a string
# contentPattern is a string
ret_xml = xml.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 None on failure

More Information and Examples
top
FindOrAddNewChild
# returns a CkXml
# tagPath is a string
ret_xml = xml.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 None on failure

top
FirstChild
# returns a CkXml
ret_xml = xml.FirstChild();

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

Returns None on failure

top
FirstChild2
status = xml.FirstChild2();

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

Returns True for success, False for failure.

top
GetAttributeName
# index is an integer
# outStr is a CkString (output)
status = xml.GetAttributeName(index, outStr);
retStr = xml.getAttributeName(index);

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

Returns True for success, False for failure.

More Information and Examples
top
GetAttributeValue
# index is an integer
# outStr is a CkString (output)
status = xml.GetAttributeValue(index, outStr);
retStr = xml.getAttributeValue(index);

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

Returns True for success, False for failure.

More Information and Examples
top
GetAttributeValueInt
# index is an integer
retInt = xml.GetAttributeValueInt(index);

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

top
GetAttrValue
# name is a string
# outStr is a CkString (output)
status = xml.GetAttrValue(name, outStr);
retStr = xml.getAttrValue(name);

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

Returns True for success, False for failure.

More Information and Examples
top
GetAttrValueInt
# name is a string
retInt = xml.GetAttrValueInt(name);

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

More Information and Examples
top
GetBinaryContent
# unzipFlag is a boolean
# decryptFlag is a boolean
# password is a string
# outData is a CkByteData (output)
status = xml.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 True for success, False for failure.

top
GetChild
# returns a CkXml
# index is an integer
ret_xml = xml.GetChild(index);

Returns the Nth child of an XML node

Returns None on failure

More Information and Examples
top
GetChild2
# index is an integer
status = xml.GetChild2(index);

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

Returns True for success, False for failure.

top
GetChildAttrValue
# tagPath is a string
# attrName is a string
# outStr is a CkString (output)
status = xml.GetChildAttrValue(tagPath, attrName, outStr);
retStr = xml.getChildAttrValue(tagPath, attrName);
Introduced in version 9.5.0.77

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

Returns True for success, False for failure.

top
GetChildBoolValue
# tagPath is a string
retBool = xml.GetChildBoolValue(tagPath);

Returns False if the node's content is "0", otherwise returns True 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".

More Information and Examples
top
GetChildContent
# tagPath is a string
# outStr is a CkString (output)
status = xml.GetChildContent(tagPath, outStr);
retStr = xml.getChildContent(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 True for success, False for failure.

More Information and Examples
top
GetChildContentByIndex
# index is an integer
# outStr is a CkString (output)
status = xml.GetChildContentByIndex(index, outStr);
retStr = xml.getChildContentByIndex(index);

Returns the content of the Nth child node.

Returns True for success, False for failure.

top
GetChildContentSb
# tagPath is a string
# sb is a CkStringBuilder
status = xml.GetChildContentSb(tagPath, sb);
Introduced in version 9.5.0.76

Returns the content of the XML element at the tagPath. The XML element's content is appended to the sb.

Returns True for success, False for failure.

top
GetChildExact
# returns a CkXml
# tag is a string
# content is a string
ret_xml = xml.GetChildExact(tag, content);

Returns the child having the exact tag and content.

Returns None on failure

top
GetChildIntValue
# tagPath is a string
retInt = xml.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".

More Information and Examples
top
GetChildTag
# index is an integer
# outStr is a CkString (output)
status = xml.GetChildTag(index, outStr);
retStr = xml.getChildTag(index);

Returns the tag name of the Nth child node.

Returns True for success, False for failure.

top
GetChildTagByIndex
# index is an integer
# outStr is a CkString (output)
status = xml.GetChildTagByIndex(index, outStr);
retStr = xml.getChildTagByIndex(index);

Returns the tag name of the Nth child node.

Returns True for success, False for failure.

More Information and Examples
top
GetChildWithAttr
# returns a CkXml
# tagPath is a string
# attrName is a string
# attrValue is a string
ret_xml = xml.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 None on failure

More Information and Examples
top
GetChildWithContent
# returns a CkXml
# content is a string
ret_xml = xml.GetChildWithContent(content);

Returns the first child found having the exact content specified.

Returns None on failure

top
GetChildWithTag
# returns a CkXml
# tagPath is a string
ret_xml = xml.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 None on failure

top
GetNthChildWithTag
# returns a CkXml
# tag is a string
# n is an integer
ret_xml = xml.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 None on failure

top
GetNthChildWithTag2
# tag is a string
# n is an integer
status = xml.GetNthChildWithTag2(tag, n);

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

Returns True for success, False for failure.

top
GetParent
# returns a CkXml
ret_xml = xml.GetParent();

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

Returns None on failure

top
GetParent2
status = xml.GetParent2();

Updates the internal reference of the caller to its parent.

Returns True for success, False for failure.

top
GetRoot
# returns a CkXml
ret_xml = xml.GetRoot();

Returns the root node of the XML document

Returns None on failure

top
GetRoot2
xml.GetRoot2();

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

top
GetSelf
# returns a CkXml
ret_xml = xml.GetSelf();

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

Returns None on failure

top
GetXml
# outStr is a CkString (output)
status = xml.GetXml(outStr);
retStr = xml.getXml();

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 True for success, False for failure.

top
GetXmlBd
# bd is a CkBinData
status = xml.GetXmlBd(bd);
Introduced in version 9.5.0.77

Emits (appends) the XML to the contents of bd.

Returns True for success, False for failure.

top
GetXmlSb
# sb is a CkStringBuilder
status = xml.GetXmlSb(sb);
Introduced in version 9.5.0.62

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

Returns True for success, False for failure.

top
HasAttribute
# name is a string
retBool = xml.HasAttribute(name);

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

top
HasAttrWithValue
# name is a string
# value is a string
retBool = xml.HasAttrWithValue(name, value);

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

top
HasChildWithContent
# content is a string
retBool = xml.HasChildWithContent(content);

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

top
HasChildWithTag
# tagPath is a string
retBool = xml.HasChildWithTag(tagPath);

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

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".

More Information and Examples
top
HasChildWithTagAndContent
# tagPath is a string
# content is a string
retBool = xml.HasChildWithTagAndContent(tagPath, content);

Returns True 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".

top
InsertChildTreeAfter
# index is an integer
# tree is a CkXml
xml.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).

top
InsertChildTreeBefore
# index is an integer
# tree is a CkXml
xml.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).

More Information and Examples
top
LastChild
# returns a CkXml
ret_xml = xml.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 None on failure

top
LastChild2
status = xml.LastChild2();

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

Returns True for success, False for failure.

top
LoadBd
# bd is a CkBinData
# autoTrim is a boolean
status = xml.LoadBd(bd, autoTrim);
Introduced in version 9.5.0.77

Loads XML from the contents of bd. If autoTrim is True, then each element's text content is trimmed of leading and trailing whitespace.

Returns True for success, False for failure.

top
LoadSb
# sb is a CkStringBuilder
# autoTrim is a boolean
status = xml.LoadSb(sb, autoTrim);
Introduced in version 9.5.0.62

Loads XML from the contents of a StringBuilder object.

Returns True for success, False for failure.

More Information and Examples
top
LoadXml
# xmlData is a string
status = xml.LoadXml(xmlData);

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

Returns True for success, False for failure.

top
LoadXml2
# xmlData is a string
# autoTrim is a boolean
status = xml.LoadXml2(xmlData, autoTrim);

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

Returns True for success, False for failure.

More Information and Examples
top
LoadXmlFile
# fileName is a string
status = xml.LoadXmlFile(fileName);

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

Returns True for success, False for failure.

top
LoadXmlFile2
# fileName is a string
# autoTrim is a boolean
status = xml.LoadXmlFile2(fileName, autoTrim);

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

Returns True for success, False for failure.

More Information and Examples
top
NewChild
# returns a CkXml
# tagPath is a string
# content is a string
ret_xml = xml.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 None on failure

top
NewChild2
# tagPath is a string
# content is a string
xml.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.

top
NewChildAfter
# returns a CkXml
# index is an integer
# tag is a string
# content is a string
ret_xml = xml.NewChildAfter(index, tag, content);

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

Returns None on failure

More Information and Examples
top
NewChildBefore
# returns a CkXml
# index is an integer
# tag is a string
# content is a string
ret_xml = xml.NewChildBefore(index, tag, content);

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

Returns None on failure

More Information and Examples
top
NewChildInt2
# tagPath is a string
# value is an integer
xml.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.

More Information and Examples
top
NextInTraversal2
# sbState is a CkStringBuilder
retBool = xml.NextInTraversal2(sbState);
Introduced in version 9.5.0.77

Updates to Xml object's internal reference to the next node in a depth-first traversal. (This method name, NextInTraversal2, ends with "2" to signify that the internal reference is updated. There is no "NextInTraversal" method.)

The sbState contains the current state of the traversal. sbState should be empty when beginning a traversal.

More Information and Examples
top
NextSibling
# returns a CkXml
ret_xml = xml.NextSibling();

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

Returns None on failure

top
NextSibling2
status = xml.NextSibling2();

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

Returns True for success, False for failure.

top
NumChildrenAt
# tagPath is a string
retInt = xml.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.

top
NumChildrenHavingTag
# tag is a string
retInt = xml.NumChildrenHavingTag(tag);

Returns the number of children having a specific tag name.

top
PreviousSibling
# returns a CkXml
ret_xml = xml.PreviousSibling();

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

Returns None on failure

top
PreviousSibling2
status = xml.PreviousSibling2();

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

Returns True for success, False for failure.

top
PruneAttribute
# attrName is a string
retInt = xml.PruneAttribute(attrName);
Introduced in version 9.5.0.77

Recursively descends the XML from this node and removes all occurrences of the specified attribute. Returns the number of attribute occurrences removed.

top
PruneTag
# tag is a string
retInt = xml.PruneTag(tag);
Introduced in version 9.5.0.77

Recursively descends the XML from this node and removes all occurrences of the specified tag, including all descendents of each removed node. Returns the number of tag occurrences removed.

More Information and Examples
top
QEncodeContent
# charset is a string
# inData is a CkByteData
status = xml.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 True for success, False for failure.

top
RemoveAllAttributes
status = xml.RemoveAllAttributes();

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

Returns True for success, False for failure.

top
RemoveAllChildren
xml.RemoveAllChildren();

Removes all children from the calling node.

top
RemoveAttribute
# name is a string
status = xml.RemoveAttribute(name);

Removes an attribute by name from and XML node.

Returns True for success, False for failure.

top
RemoveChild
# tagPath is a string
xml.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".

top
RemoveChildByIndex
# index is an integer
xml.RemoveChildByIndex(index);

Removes the Nth child from the calling node.

More Information and Examples
top
RemoveChildWithContent
# content is a string
xml.RemoveChildWithContent(content);

Removes all children having the exact content specified.

More Information and Examples
top
RemoveFromTree
xml.RemoveFromTree();

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

More Information and Examples
top
RemoveStyleSheet
# attrName is a string
# attrValue is a string
retInt = xml.RemoveStyleSheet(attrName, attrValue);
Introduced in version 9.5.0.77

Removes all XML stylesheets having an attribute with attrName equal to attrValue. Returns the number of stylesheets removed, or -1 if there was an error.

top
SaveBinaryContent
# filename is a string
# unzipFlag is a boolean
# decryptFlag is a boolean
# password is a string
status = xml.SaveBinaryContent(filename, unzipFlag, decryptFlag, password);

Saves a node's binary content to a file.

Returns True for success, False for failure.

top
SaveXml
# fileName is a string
status = xml.SaveXml(fileName);

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

Returns True for success, False for failure.

top
Scrub
# directives is a string
xml.Scrub(directives);
Introduced in version 9.5.0.77

Recursively traverses the XML rooted at the caller and scrubs according to the instructions in the comma separated directives. The currently defined directives are:

  • "AttrTrimEnds" - Leading and trailing whitespace removed from attribute values.
  • "AttrTrimInside" - Replace all tabs, CR's, and LF's with SPACE chars, and removes extra SPACE chars so that no more than one SPACE char in a row exists.
  • "ContentTrimEnds" - Same as AttrTrimEnds but for content.
  • "ContentTrimInside" - Same as AttrTrimInside but for content.
  • "LowercaseAttrs" - Convert all attribute names to lowercase.
  • "LowercaseTags" - Convert all tags to lowercase.
  • "RemoveCtrl" - Remove non-printable us-ascii control chars (us-ascii values <= 31 except for TAB,CR, and LF are removed)

If you have other ideas for useful XML scrubbing directives, send email to support@chilkatsoft.com. It must be general enough such that many developers will find it useful.

More Information and Examples
top
SearchAllForContent
# returns a CkXml
# afterPtr is a CkXml
# contentPattern is a string
ret_xml = xml.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 None. (For the ActiveX implementation, the afterPtr should never be None. 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 None.

Returns None on failure

More Information and Examples
top
SearchAllForContent2
# afterPtr is a CkXml
# contentPattern is a string
status = xml.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 True for success, False for failure.

top
SearchForAttribute
# returns a CkXml
# afterPtr is a CkXml
# tag is a string
# attr is a string
# valuePattern is a string
ret_xml = xml.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 None. (For the ActiveX implementation, the afterPtr should never be None. 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 None.

Returns None on failure

top
SearchForAttribute2
# afterPtr is a CkXml
# tag is a string
# attr is a string
# valuePattern is a string
status = xml.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 True for success, False for failure.

top
SearchForContent
# returns a CkXml
# afterPtr is a CkXml
# tag is a string
# contentPattern is a string
ret_xml = xml.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 None. (For the ActiveX implementation, the afterPtr should never be None. 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 None.

Returns None on failure

More Information and Examples
top
SearchForContent2
# afterPtr is a CkXml
# tag is a string
# contentPattern is a string
status = xml.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 True for success, False for failure.

More Information and Examples
top
SearchForTag
# returns a CkXml
# afterPtr is a CkXml
# tag is a string
ret_xml = xml.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 None. (For the ActiveX implementation, the afterPtr should never be None. 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 None.

Returns None on failure

top
SearchForTag2
# afterPtr is a CkXml
# tag is a string
status = xml.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 True for success, False for failure.

More Information and Examples
top
SetBinaryContent
# inData is a CkByteData
# zipFlag is a boolean
# encryptFlag is a boolean
# password is a string
status = xml.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 True for success, False for failure.

top
SetBinaryContentFromFile
# filename is a string
# zipFlag is a boolean
# encryptFlag is a boolean
# password is a string
status = xml.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 True for success, False for failure.

top
SortByAttribute
# attrName is a string
# ascending is a boolean
xml.SortByAttribute(attrName, ascending);

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

top
SortByAttributeInt
# attrName is a string
# ascending is a boolean
xml.SortByAttributeInt(attrName, ascending);

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

top
SortByContent
# ascending is a boolean
xml.SortByContent(ascending);

Sorts the direct child nodes by content.

More Information and Examples
top
SortByTag
# ascending is a boolean
xml.SortByTag(ascending);

Sorts the direct child nodes by tag.

More Information and Examples
top
SortRecordsByAttribute
# sortTag is a string
# attrName is a string
# ascending is a boolean
xml.SortRecordsByAttribute(sortTag, attrName, ascending);

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

top
SortRecordsByContent
# sortTag is a string
# ascending is a boolean
xml.SortRecordsByContent(sortTag, ascending);

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

More Information and Examples
top
SortRecordsByContentInt
# sortTag is a string
# ascending is a boolean
xml.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).

top
SwapNode
# node is a CkXml
status = xml.SwapNode(node);

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

Returns True for success, False for failure.

top
SwapTree
# tree is a CkXml
status = xml.SwapTree(tree);

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

Returns True for success, False for failure.

top
TagContent
# tagName is a string
# outStr is a CkString (output)
status = xml.TagContent(tagName, outStr);
retStr = xml.tagContent(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 True for success, False for failure.

top
TagEquals
# tag is a string
retBool = xml.TagEquals(tag);

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

top
TagIndex
# tagPath is a string
retInt = xml.TagIndex(tagPath);
Introduced in version 9.5.0.76

Returns the index of the XML node with the given tag. Returns -1 if no node having the specified tag is found at the tagPath.

More Information and Examples
top
TagNsEquals
# ns is a string
retBool = xml.TagNsEquals(ns);
Introduced in version 9.5.0.77

Returns True if the node's tag namespace prefix equals the specified ns.

More Information and Examples
top
TagUnpEquals
# unprefixedTag is a string
retBool = xml.TagUnpEquals(unprefixedTag);
Introduced in version 9.5.0.77

Returns True if the node's unprefixed tag equals the specified string. For example, if the tag is "soapenv:Body", the unprefixed tag is "Body".

More Information and Examples
top
UnzipContent
status = xml.UnzipContent();

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

Returns True for success, False for failure.

More Information and Examples
top
UnzipTree
status = xml.UnzipTree();

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

Returns True for success, False for failure.

More Information and Examples
top
UpdateAt
# tagPath is a string
# autoCreate is a boolean
# value is a string
retBool = xml.UpdateAt(tagPath, autoCreate, value);
Introduced in version 9.5.0.64

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

More Information and Examples
top
UpdateAttrAt
# tagPath is a string
# autoCreate is a boolean
# attrName is a string
# attrValue is a string
retBool = xml.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 True, then nodes along tagPath are auto-created as needed.

top
UpdateAttribute
# attrName is a string
# attrValue is a string
status = xml.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 True for success, False for failure.

More Information and Examples
top
UpdateAttributeInt
# attrName is a string
# value is an integer
status = xml.UpdateAttributeInt(attrName, value);

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

Returns True for success, False for failure.

top
UpdateChildContent
# tagPath is a string
# value is a string
xml.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". The nodes in the tagPath are automatically created as needed.

top
UpdateChildContentInt
# tagPath is a string
# value is an integer
xml.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".

top
ZipContent
status = xml.ZipContent();

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

Returns True for success, False for failure.

More Information and Examples
top
ZipTree
status = xml.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 True for success, False for failure.

More Information and Examples
top