Xml Lianja Reference Documentation

Xml

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

Object Creation

loObject = createobject("CkXml")

Properties

Cdata As Boolean

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

Using CDATA in XML

Content As Character

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 As Numeric

Set/get the content as an integer.

DebugLogFilePath As Character

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 As Character

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

Setting the XML DOCTYPE

EmitBom As Boolean

Introduced in version 9.5.0.44

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

EmitCompact As Boolean

Introduced in version 9.5.0.64

If .T., 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 .F., which maintains backward compatibility.

XML EmitCompact

EmitXmlDecl As Boolean

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

Encoding As Character

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 As Numeric

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 As Numeric

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 As Numeric

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 As Character (read-only)

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 As Character (read-only)

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 As Character (read-only)

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 As Boolean

Introduced in version 9.5.0.52

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

NumAttributes As Numeric (read-only)

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 As Numeric (read-only)

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

SortCaseInsensitive As Boolean

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

Standalone As Boolean

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

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

Tag As Character

The XML node's tag.

Setting XML Tag and Content

TreeId As Numeric (read-only)

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.

VerboseLogging As Boolean

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

Version As Character (read-only)

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

Methods

AccumulateTagContent(tag As Character, skipTags As Character) As Character

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 .F. on failure

XML Accumulate Tag Content

AddAttribute(name As Character, value As Character) As Boolean

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

Returns .T. for success, .F. for failure.

Adding Attributes to an XML Node

AddAttribute - Insert New Attribute in XML Node

AddAttributeInt(name As Character, value As Numeric) As Boolean

Adds an integer attribute to a node.

Returns .T. for success, .F. for failure.

AddChildTree(tree As CkXml) As Boolean

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 .T. for success, .F. for failure.

AddOrUpdateAttribute(name As Character, value As Character)

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

Update an XML Attribute

AddOrUpdateAttributeI(name As Character, value As Numeric)

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

AddStyleSheet(styleSheet As Character)

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

AddToAttribute(name As Character, amount As Numeric)

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

AddToChildContent(tag As Character, amount As Numeric)

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

AddToContent(amount As Numeric)

Adds an integer amount to the node's content.

AppendToContent(str As Character) As Boolean

Appends text to the content of an XML node

Returns .T. for success, .F. for failure.

ChildContentMatches(tagPath As Character, pattern As Character, caseSensitive As Boolean) As Boolean

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

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

ChilkatPath(pathCmd As Character) As Character

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 .F. on failure

ChilkatPath Sample Code

Get XML Attribute Value by Path

Clear()

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

ContentMatches(pattern As Character, caseSensitive As Boolean) As Boolean

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

Copy(node As CkXml)

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

CopyRef(copyFromNode As CkXml)

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.

DecodeEntities(str As Character) As Character

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

Returns .F. on failure

DecryptContent(password As Character) As Boolean

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

Returns .T. for success, .F. for failure.

Encrypting and Decrypting Content

EncryptContent(password As Character) As Boolean

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

Returns .T. for success, .F. for failure.

Encrypting and Decrypting Content

ExtractChildByIndex(index As Numeric) As CkXml

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

Returns .F. on failure

ExtractChildByName(tagPath As Character, attrName As Character, attrValue As Character) As CkXml

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 .F. on failure

ExtractChildByName using a Tag Path

FindChild(tagPath As Character) As CkXml

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 .F. on failure

Find Direct Child with Specific Tag

Access SOAP Body XML

FindChild2(tagPath As Character) As Boolean

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 .T. for success, .F. for failure.

Find Direct Child with Specific Tag

Benefit of XML Methods Having Names Ending in "2"

FindNextRecord(tagPath As Character, contentPattern As Character) As CkXml

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 .F. on failure

Demonstrate the XML FindNextRecord Method

FindOrAddNewChild(tagPath As Character) As CkXml

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 .F. on failure

FirstChild() As CkXml

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

Returns .F. on failure

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

FirstChild2() As Boolean

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

Returns .T. for success, .F. 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"

GetAttributeName(index As Numeric) As Character

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

Returns .F. on failure

Methods for Getting Attributes

GetAttributeValue(index As Numeric) As Character

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

Returns .F. on failure

Methods for Getting Attributes

GetAttributeValueInt(index As Numeric) As Numeric

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

GetAttrValue(name As Character) As Character

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

Returns .F. on failure

Methods for Getting Attributes

GetAttrValueInt(name As Character) As Numeric

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

Methods for Getting Attributes

GetChild(index As Numeric) As CkXml

Returns the Nth child of an XML node

Returns .F. on failure

Iterate over Direct Child Nodes by Index

GetChild2(index As Numeric) As Boolean

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

Returns .T. for success, .F. 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"

GetChildBoolValue(tagPath As Character) As Boolean

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

GetChildContent(tagPath As Character) As Character

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 .F. on failure

Demonstrate the XML "I" Property

GetChildContentByIndex(index As Numeric) As Character

Returns the content of the Nth child node.

Returns .F. on failure

Iterate over Direct Child Nodes by Index

SQS List Queues

GetChildExact(tag As Character, content As Character) As CkXml

Returns the child having the exact tag and content.

Returns .F. on failure

GetChildIntValue(tagPath As Character) As Numeric

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

GetChildTag(index As Numeric) As Character

Returns the tag name of the Nth child node.

Returns .F. on failure

GetChildTagByIndex(index As Numeric) As Character

Returns the tag name of the Nth child node.

Returns .F. on failure

Iterate over Direct Child Nodes by Index

GetChildWithAttr(tagPath As Character, attrName As Character, attrValue As Character) As CkXml

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 .F. on failure

XML GetChildWithAttr

GetChildWithContent(content As Character) As CkXml

Returns the first child found having the exact content specified.

Returns .F. on failure

GetChildWithTag(tagPath As Character) As CkXml

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 .F. on failure

GetNthChildWithTag(tag As Character, n As Numeric) As CkXml

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 .F. on failure

Iterate over Direct Children with a Specific Tag

GetNthChildWithTag2(tag As Character, n As Numeric) As Boolean

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

Returns .T. for success, .F. for failure.

Iterate over Direct Children with a Specific Tag

Benefit of XML Methods Having Names Ending in "2"

GetParent() As CkXml

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

Returns .F. on failure

GetParent2() As Boolean

Updates the internal reference of the caller to its parent.

Returns .T. for success, .F. for failure.

More information about XML methods ending in "2"

Benefit of XML Methods Having Names Ending in "2"

GetRoot() As CkXml

Returns the root node of the XML document

Returns .F. on failure

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"

GetSelf() As CkXml

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

Returns .F. on failure

GetXml() As Character

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 .F. on failure

GetXmlSb(sb As CkStringBuilder) As Boolean

Introduced in version 9.5.0.62

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

Returns .T. for success, .F. for failure.

HasAttribute(name As Character) As Boolean

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

HasAttrWithValue(name As Character, value As Character) As Boolean

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

HasChildWithContent(content As Character) As Boolean

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

HasChildWithTag(tagPath As Character) As Boolean

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

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

HasChildWithTagAndContent(tagPath As Character, content As Character) As Boolean

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

InsertChildTreeAfter(index As Numeric, tree As CkXml)

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

InsertChildTreeBefore(index As Numeric, tree As CkXml)

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

LastChild() As CkXml

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 .F. on failure

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

LastChild2() As Boolean

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

Returns .T. for success, .F. for failure.

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

Benefit of XML Methods Having Names Ending in "2"

LoadSb(sb As CkStringBuilder, autoTrim As Boolean) As Boolean

Introduced in version 9.5.0.62

Loads XML from the contents of a StringBuilder object.

Returns .T. for success, .F. for failure.

LoadXml(xmlData As Character) As Boolean

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

Returns .T. for success, .F. for failure.

LoadXml2(xmlData As Character, autoTrim As Boolean) As Boolean

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

Returns .T. for success, .F. for failure.

LoadXmlFile(fileName As Character) As Boolean

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

Returns .T. for success, .F. for failure.

LoadXmlFile2(fileName As Character, autoTrim As Boolean) As Boolean

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

Returns .T. for success, .F. for failure.

NewChild(tagPath As Character, content As Character) As CkXml

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 .F. on failure

Creating a New Child Node

NewChild using a Tag Path

NewChild2(tagPath As Character, content As Character)

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

NewChildAfter(index As Numeric, tag As Character, content As Character) As CkXml

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

Returns .F. on failure

NewChildBefore(index As Numeric, tag As Character, content As Character) As CkXml

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

Returns .F. on failure

NewChildInt2(tagPath As Character, value As Numeric)

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

NextSibling() As CkXml

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

Returns .F. on failure

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

NextSibling2() As Boolean

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

Returns .T. for success, .F. 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"

NumChildrenAt(tagPath As Character) As Numeric

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

NumChildrenHavingTag(tag As Character) As Numeric

Returns the number of children having a specific tag name.

Iterate over Direct Children with a Specific Tag

PreviousSibling() As CkXml

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

Returns .F. on failure

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

PreviousSibling2() As Boolean

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

Returns .T. for success, .F. 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"

RemoveAllAttributes() As Boolean

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

Returns .T. for success, .F. for failure.

RemoveAllChildren()

Removes all children from the calling node.

RemoveAttribute(name As Character) As Boolean

Removes an attribute by name from and XML node.

Returns .T. for success, .F. for failure.

RemoveChild(tagPath As Character)

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

RemoveChildByIndex(index As Numeric)

Removes the Nth child from the calling node.

Removing / Deleting Child Nodes from XML

RemoveChildWithContent(content As Character)

Removes all children having the exact content specified.

Removing / Deleting Child Nodes from XML

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

SaveBinaryContent(filename As Character, unzipFlag As Boolean, decryptFlag As Boolean, password As Character) As Boolean

Saves a node's binary content to a file.

Returns .T. for success, .F. for failure.

SaveLastError(path As Character) As Boolean

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

Returns .T. for success, .F. for failure.

SaveXml(fileName As Character) As Boolean

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

Returns .T. for success, .F. for failure.

SearchAllForContent(afterPtr As CkXml, contentPattern As Character) As CkXml

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 .F.. (For the ActiveX implementation, the afterPtr should never be .F.. 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 .F..

Returns .F. on failure

XML Tree Traversal Order for Search* Methods

SearchAllForContent2(afterPtr As CkXml, contentPattern As Character) As Boolean

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 .T. for success, .F. for failure.

SearchForAttribute(afterPtr As CkXml, tag As Character, attr As Character, valuePattern As Character) As CkXml

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 .F.. (For the ActiveX implementation, the afterPtr should never be .F.. 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 .F..

Returns .F. on failure

XML SearchForAttribute Method

XML Tree Traversal Order for Search* Methods

SearchForAttribute2(afterPtr As CkXml, tag As Character, attr As Character, valuePattern As Character) As Boolean

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 .T. for success, .F. for failure.

SearchForContent(afterPtr As CkXml, tag As Character, contentPattern As Character) As CkXml

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 .F.. (For the ActiveX implementation, the afterPtr should never be .F.. 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 .F..

Returns .F. on failure

XML Tree Traversal Order for Search* Methods

SearchForContent2(afterPtr As CkXml, tag As Character, contentPattern As Character) As Boolean

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 .T. for success, .F. for failure.

XML Tree Traversal Order for Search* Methods

SearchForTag(afterPtr As CkXml, tag As Character) As CkXml

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 .F.. (For the ActiveX implementation, the afterPtr should never be .F.. 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 .F..

Returns .F. on failure

XML SearchForTag Method

XML Tree Traversal Order for Search* Methods

SearchForTag2(afterPtr As CkXml, tag As Character) As Boolean

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 .T. for success, .F. for failure.

SetBinaryContentFromFile(filename As Character, zipFlag As Boolean, encryptFlag As Boolean, password As Character) As Boolean

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 .T. for success, .F. for failure.

SortByAttribute(attrName As Character, ascending As Boolean)

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

SortByAttributeInt(attrName As Character, ascending As Boolean)

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

SortByContent(ascending As Boolean)

Sorts the direct child nodes by content.

XML Sort by Content

SortByTag(ascending As Boolean)

Sorts the direct child nodes by tag.

XML Sort by Tag

SortRecordsByAttribute(sortTag As Character, attrName As Character, ascending As Boolean)

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

SortRecordsByContent(sortTag As Character, ascending As Boolean)

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

XML Sort Records by Content

SortRecordsByContentInt(sortTag As Character, ascending As Boolean)

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

SwapNode(node As CkXml) As Boolean

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

Returns .T. for success, .F. for failure.

SwapTree(tree As CkXml) As Boolean

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

Returns .T. for success, .F. for failure.

TagContent(tagName As Character) As Character

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 .F. on failure

TagEquals(tag As Character) As Boolean

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

UnzipContent() As Boolean

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

Returns .T. for success, .F. for failure.

Compress XML Content

UnzipTree() As Boolean

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

Returns .T. for success, .F. for failure.

Compress XML Tree

UpdateAt(tagPath As Character, autoCreate As Boolean, value As Character) As Boolean

Introduced in version 9.5.0.64

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

Demonstrate the XML UpdateAt Method

UpdateAttrAt(tagPath As Character, autoCreate As Boolean, attrName As Character, attrValue As Character) As Boolean

Introduced in version 9.5.0.64

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

Demonstrate the XML UpdateAttrAt Method

Xml.UpdateAttrAt Example #2

UpdateAttribute(attrName As Character, attrValue As Character) As Boolean

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

Returns .T. for success, .F. for failure.

Update an XML Attribute

UpdateAttributeInt(attrName As Character, value As Numeric) As Boolean

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

Returns .T. for success, .F. for failure.

UpdateChildContent(tagPath As Character, value As Character)

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

UpdateChildContentInt(tagPath As Character, value As Numeric)

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

ZipContent() As Boolean

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

Returns .T. for success, .F. for failure.

Compress XML Content

ZipTree() As Boolean

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 .T. for success, .F. for failure.

Compress XML Tree