CkXml C++ Class Reference
CkXml
A free non-validating XML parser component with encryption and compression features.
Properties
bool get_Cdata(); bool put_Cdata(bool newVal);
When True, causes an XML node's content to be encapsulated in a CDATA section. Using CDATA in XML
void get_Content(CkString &str); void put_Content(const char *newVal);
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
int get_ContentInt(void); void put_ContentInt(int newVal);
Set/get the content as an integer.
void get_DocType(CkString &str); void put_DocType(const char *newVal);
The DOCTYPE declaration (if any) for the XML document. Setting the XML DOCTYPE
void get_Encoding(CkString &str); void put_Encoding(const char *newVal);
This is the encoding attribute in the XML declaration, such as "utf-8" or "iso-8859-1". If not present, this property returns an empty string. 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.
void LastErrorHtml(CkString &str);
Error information in HTML format for the last method called.
void LastErrorText(CkString &str);
Error information in plain-text format for the last method called.
void LastErrorXml(CkString &str);
Error information in XML format for the last method called.
long get_NumAttributes();
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
long get_NumChildren();
The number of direct child nodes contained under this XML node.
bool get_SortCaseInsensitive(); void put_SortCaseInsensitive(bool newVal);
If true (or 1 for ActiveX), then all Sort* methods use case insensitive sorting.
bool get_Standalone(void); void put_Standalone(bool newVal);
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">
void get_Tag(CkString &str); void put_Tag(const char *newVal);
The XML node's tag. Setting XML Tag and Content
long get_TreeId(void);
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.
bool get_Utf8(void) const; void put_Utf8(bool b);
When set to true, all "const char *" arguments are expected to be utf-8 strings. If set to false, the "const char *" arguments are expected to be ANSI strings.
bool get_Version(CkString &str);
The version of the XML component, such as "2.0.0".
Methods
void AccumulateTagContent(const char * tag, const char * skipTags, CkString & outStr);
Accumulates the content of all nodes having a specific tag into a single result string. SkipTags specifies a set of tags whose are 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.
bool AddAttribute(const char * name, const char * value);
Adds an attribute to the calling node in the XML document. Returns True for success, and False for failure. Adding Attributes to an XML Node AddAttribute - Insert New Attribute in XML Node
bool AddAttributeInt(const char * name, int value);
Adds an integer attribute to a node.
bool AddChildTree(const CkXml * 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.
bool AddChildTree(const CkXml & 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.
void AddOrUpdateAttribute(const char * name, const char * value);
Adds an attribute to an XML node. If an attribute having the specified name already exists, the value is updated. Update an XML Attribute
void AddOrUpdateAttributeI(const char * name, long value);
Adds an integer attribute to an XML node. If an attribute having the specified name already exists, the value is updated.
void AddStyleSheet(const char * 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"?>
void AddToAttribute(const char * name, long amount);
Adds an integer amount to an integer attribute's value. If the attribute does not yet exist, this method behaves the same as AddOrUpdateAttributeI. Update an XML Attribute
void AddToChildContent(const char * tag, long amount);
Adds an integer value to the content of a child node.
void AddToContent(long amount);
Adds an integer amount to the node's content.
bool AppendToContent(const char * str);
Appends text to the content of an XML node
bool BEncodeContent(const char * charset, const CkByteData & db);
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.
bool ChildContentMatches(const char * tag, const char * pattern, bool caseSensitive);
Return true if a child having a specific tag contains content that matches a wildcarded pattern.
bool ChilkatPath(const char * pathCmd, CkString & outStr);
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:
- TagName -- Navigate to the 1st direct child with the given tag.
- TagName[n] -- Navigate to the Nth direct child with the given tag.
- .. -- Navigate up to the parent
- TagName{Content} -- Navigate to the 1st direct child with the given tag having the exact content.
- /T/TagName -- Traverse the XML DOM tree (rooted at the caller) and navigate to the 1st node having the given tag.
- /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.
- /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.
- /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:
- * -- Return the Content of the node.
- (AttrName) -- Return the value of the given attribute.
- $ -- 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. ChilkatPath Sample Code
bool Clear();
Removes all children, attributes, and content from the XML node. Resets the tag name to "unnamed".
bool ContentMatches(const char * pattern, bool caseSensitive);
Return true if the node's content matches a wildcarded pattern.
void Copy(const CkXml & node);
Copies the tag, content, and attributes to the calling node.
void Copy(const CkXml * node);
Copies the tag, content, and attributes to the calling node.
void CopyRef(CkXml & 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.
void CopyRef(CkXml * 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.
bool DecodeContent(CkByteData & outData);
Decodes a node's Q or B-encoded content string and returns the byte data.
bool DecodeEntities(const char * str, CkString & outStr);
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.
bool DecryptContent(const char * password);
Decrypts the content of an XML node that was previously 128-bit AES encrypted with the EncryptContent method. Encrypting and Decrypting Content
bool EncryptContent(const char * password);
Encrypts the content of the calling XML node using 128-bit CBC AES encryption. The base64-encoded encrypted content replaces the original content. Encrypting and Decrypting Content
CkXml * ExtractChildByIndex(long index);
Removes and returns the Nth child of an XML node. The first child is at index 0.
CkXml * ExtractChildByName(const char * tag, const char * attrName, const char * attrValue);
Removes and returns the first child node having a tag equal to the tagName. The attributeName and attrValue may be empty or NULL, in which case the first child matching the tag is removed and returned. If attributeName is specified, then the first child having a tag equal to tagName, and an attribute with attributeName is returned. If attrValue is also specified, then only a child having a tag equal to tagName, and an attribute named attributeName, with a value equal to attrValue is returned.
CkXml * FindChild(const char * tag);
Returns the child having a specified tag. Find Direct Child with Specific Tag
bool FindChild2(const char * tag);
Updates the Xml object's internal reference to point to a child with a specified tag. Find Direct Child with Specific Tag
CkXml * FindNextRecord(const char * tag, const char * 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.
CkXml * FindOrAddNewChild(const char * tag);
First searches for a child having a tag equal to tagName, and if found, returns it. Otherwise creates a new child, sets the tag equal to tagName, and initializes the Content to empty.
CkXml * FirstChild();
Returns the first child. A program can step through the children by calling FirstChild, and then NextSibling repeatedly. Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling
bool FirstChild2();
Updates the internal reference of the caller to point to its first child. More information about XML methods ending in "2" Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling
bool GetAttrValue(const char * name, CkString & outStr);
Find and return the value of an attribute having a specified name. Returns true for success, false for failure. Methods for Getting Attributes
int GetAttrValueInt(const char * name);
Returns an attribute as an integer. Methods for Getting Attributes
bool GetAttributeName(long index, CkString & outStr);
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. Methods for Getting Attributes
bool GetAttributeValue(long index, CkString & outStr);
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. Methods for Getting Attributes
int GetAttributeValueInt(int index);
Returns an attribute as an integer.
bool GetBinaryContent(CkByteData & data, bool unzipFlag, bool decryptFlag, const char * password);
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.
CkXml * GetChild(long index);
Returns the Nth child of an XML node Iterate over Direct Child Nodes by Index
bool GetChild2(long index);
Updates the calling object's internal reference to the Nth child node. Returns true for success, false for failure. More information about XML methods ending in "2" Iterate over Direct Child Nodes by Index
bool GetChildBoolValue(const char * tag);
Returns false if the node's content is "0", otherwise returns true if the node contains a non-zero integer.
bool GetChildContent(const char * tag, CkString & outStr);
Returns the content of a child having a specified tag. Returns true for success, false for failure.
bool GetChildContentByIndex(long index, CkString & outStr);
Returns the content of the Nth child node. Returns true for success, false for failure. Iterate over Direct Child Nodes by Index
CkXml * GetChildExact(const char * tag, const char * content);
Returns the child having the exact tag and content.
bool GetChildIntValue(const char * tag, int & value);
Returns the child integer content for a given tag.
int GetChildIntValue(const char * tag);
Returns the child integer content for a given tag.
bool GetChildTag(long index, CkString & outStr);
Returns the tag name of the Nth child node. Returns true for success, false for failure.
bool GetChildTagByIndex(int index, CkString & outStr);
Returns the tag name of the Nth child node. Returns true for success, false for failure. Iterate over Direct Child Nodes by Index
CkXml * GetChildWithAttr(const char * tag, const char * attrName, const char * attrValue);
To be documented soon.
CkXml * GetChildWithContent(const char * content);
Returns the first child found having the exact content specified.
CkXml * GetChildWithTag(const char * tag);
Returns the Xml child object having a tag matching tagName.
CkXml * GetNthChildWithTag(const char * tag, long 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. Iterate over Direct Children with a Specific Tag
bool GetNthChildWithTag2(const char * tag, long n);
Updates the calling object's internal reference to the Nth child node having a specific tag. Returns true for success, false for failure. Iterate over Direct Children with a Specific Tag
CkXml * GetParent();
Returns the parent of this XML node, or NULL if the node is the root of the tree.
bool GetParent2();
Updates the internal reference of the caller to its parent. More information about XML methods ending in "2"
CkXml * GetRoot();
Returns the root node of the XML document
void GetRoot2();
Updates the internal reference of the caller to the document root. More information about XML methods ending in "2"
CkXml * GetSelf();
To be documented soon...
bool GetXml(CkString & outStr);
Generate the XML text document for the XML tree rooted at this node. Returns true for success, false for failure.
bool HasAttrWithValue(const char * name, const char * value);
Returns true if the node contains attribute with the name and value.
bool HasAttribute(const char * name);
Returns true if the node contains an attribute with the specified name.
bool HasChildWithContent(const char * content);
Returns true if the node has a direct child node containing the exact content string specified.
bool HasChildWithTag(const char * tag);
Returns true (1 for ActiveX) if the node has a direct child with a given tag.
bool HasChildWithTagAndContent(const char * tag, const char * content);
Returns true if the node contains a direct child having the exact tag and content specified.
bool InsertChildTreeAfter(int index, const CkXml & 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).
bool InsertChildTreeBefore(int index, const CkXml & 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).
CkXml * LastChild();
Returns the last Xml child node. A node's children can be enumerated by calling LastChild and then repeatedly calling PreviousSibling, until a NULL is returned. Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling
bool LastChild2();
Updates the internal reference of the caller to its last child. Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling
bool LoadXml(const char * 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.
bool LoadXml2(const char * xmlData, bool autoTrim);
Same as LoadXml, but an additional argument controls whether or not leading/trailing whitespace is auto-trimmed from each node's content. Returns true for success, false for failure.
bool LoadXmlFile(const char * 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.
bool LoadXmlFile2(const char * fileName, bool autoTrim);
Same as LoadXmlFile, but an additional argument controls whether or not leading/trailing whitespace is auto-trimmed from each node's content. Returns true for success, false for failure.
CkXml * NewChild(const char * tag, const char * content);
Creates a new child having tag and content. The new child is created even if a child with a tag equal to tagName already exists. (Use FindOrAddNewChild to prevent creating children having the same tags.) Creating a New Child Node
void NewChild2(const char * tag, const char * content);
Creates a new child but does not return the node that is created. Creating a New Child Node
CkXml * NewChildAfter(int index, const char * tag, const char * content);
Inserts a new child in a position after the Nth child node.
CkXml * NewChildBefore(int index, const char * tag, const char * content);
Inserts a new child in a position before the Nth child node.
void NewChildInt2(const char * tag, int value);
Inserts a new child having an integer for content.
CkXml * NextSibling();
Returns the nodes next sibling, or NULL if there are no more. Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling
bool NextSibling2();
Updates the internal reference of the caller to its next sibling. More information about XML methods ending in "2" Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling
long NumChildrenHavingTag(const char * tag);
Returns the number of children having a specific tag name. Iterate over Direct Children with a Specific Tag
CkXml * PreviousSibling();
Returns the Xml object that is the node's previous sibling, or NULL if there are no more. Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling
bool PreviousSibling2();
Updates the internal reference of the caller to its previous sibling. More information about XML methods ending in "2" Traverse Direct Children via FirstChild / NextSibling, or LastChild / PreviousSibling
bool QEncodeContent(const char * charset, const CkByteData & db);
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.
bool RemoveAllAttributes();
Removes all attributes from an XML node. Should always return True.
void RemoveAllChildren();
Removes all children from the calling node.
bool RemoveAttribute(const char * name);
Removes an attribute by name from and XML node.
void RemoveChild(const char * tag);
Removes all direct children with a given tag. Removing / Deleting Child Nodes from XML
void RemoveChildByIndex(long index);
Removes the Nth child from the calling node. Removing / Deleting Child Nodes from XML
void RemoveChildWithContent(const char * content);
Removes all children having the exact content specified. Removing / Deleting Child Nodes from XML
void 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
bool SaveBinaryContent(const char * filename, bool unzipFlag, bool decryptFlag, const char * password);
Saves a node's binary content to a file.
bool SaveLastError(const char * filename);
Saves the last error information to an XML formatted file.
bool SaveXml(const char * fileName);
Generates XML representing the tree or subtree rooted at this node and writes it to a file.
CkXml * SearchAllForContent(const CkXml * after, const char * contentPattern);
Returns the first node whose content matches the contentPattern, which is a case-sensitive string that can use any number of '*'s to represent 0 or more occurances of any character. The search is breadth-first over the sub-tree rooted at the caller, and the previous node returned can be passed to the next call as afterNode to continue the search after that node. XML Tree Traversal Order for Search* Methods
CkXml * SearchAllForContent(const CkXml & after, const char * contentPattern);
Returns the first node whose content matches the contentPattern, which is a case-sensitive string that can use any number of '*'s to represent 0 or more occurances of any character. The search is breadth-first over the sub-tree rooted at the caller, and the previous node returned can be passed to the next call as afterNode to continue the search after that node. XML Tree Traversal Order for Search* Methods
bool SearchAllForContent2(const CkXml * after, const char * 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). XML Tree Traversal Order for Search* Methods
bool SearchAllForContent2(const CkXml & after, const char * 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). XML Tree Traversal Order for Search* Methods
CkXml * SearchForAttribute(const CkXml * after, const char * tag, const char * attr, const char * valuePattern);
Returns the first node having a tag equal to tagName, and an attribute named attrName whose value matches valuePattern, which is a case-sensitive string that can use any number of '*'s to represent 0 or more occurances of any character. The search is breadth-first over the sub-tree rooted at the caller, and the previous node returned can be passed to the next call as afterNode to continue the search after that node. XML SearchForAttribute Method XML Tree Traversal Order for Search* Methods
CkXml * SearchForAttribute(const CkXml & after, const char * tag, const char * attr, const char * valuePattern);
Returns the first node having a tag equal to tagName, and an attribute named attrName whose value matches valuePattern, which is a case-sensitive string that can use any number of '*'s to represent 0 or more occurances of any character. The search is breadth-first over the sub-tree rooted at the caller, and the previous node returned can be passed to the next call as afterNode to continue the search after that node. XML SearchForAttribute Method XML Tree Traversal Order for Search* Methods
bool SearchForAttribute2(const CkXml * after, const char * tag, const char * attr, const char * 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). XML SearchForAttribute Method XML Tree Traversal Order for Search* Methods
bool SearchForAttribute2(const CkXml & after, const char * tag, const char * attr, const char * 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). XML SearchForAttribute Method XML Tree Traversal Order for Search* Methods
CkXml * SearchForContent(const CkXml * after, const char * tag, const char * contentPattern);
Returns the first node having a tag equal to tagName whose content matches contentPattern, which is a case-sensitive string that can use any number of '*'s to represent 0 or more occurances of any character. The search is breadth-first over the sub-tree rooted at the caller, and the previous node returned can be passed to the next call as afterNode to continue the search after that node. XML Tree Traversal Order for Search* Methods
CkXml * SearchForContent(const CkXml & after, const char * tag, const char * contentPattern);
Returns the first node having a tag equal to tagName whose content matches contentPattern, which is a case-sensitive string that can use any number of '*'s to represent 0 or more occurances of any character. The search is breadth-first over the sub-tree rooted at the caller, and the previous node returned can be passed to the next call as afterNode to continue the search after that node. XML Tree Traversal Order for Search* Methods
bool SearchForContent2(const CkXml * after, const char * tag, const char * 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). XML Tree Traversal Order for Search* Methods
bool SearchForContent2(const CkXml & after, const char * tag, const char * 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). XML Tree Traversal Order for Search* Methods
CkXml * SearchForTag(const CkXml * after, const char * tag);
Returns the first node having a tag equal to tagName. The search is breadth-first over the sub-tree rooted at the caller, and the previous node returned can be passed to the next call as afterNode to continue the search after that node. XML SearchForTag Method XML Tree Traversal Order for Search* Methods
CkXml * SearchForTag(const CkXml & after, const char * tag);
Returns the first node having a tag equal to tagName. The search is breadth-first over the sub-tree rooted at the caller, and the previous node returned can be passed to the next call as afterNode to continue the search after that node. XML SearchForTag Method XML Tree Traversal Order for Search* Methods
bool SearchForTag2(const CkXml * after, const char * 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). XML SearchForTag Method XML Tree Traversal Order for Search* Methods
bool SearchForTag2(const CkXml & after, const char * 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). XML SearchForTag Method XML Tree Traversal Order for Search* Methods
bool SetBinaryContent(const CkByteData & data, bool zipFlag, bool encryptFlag, const char * 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.
bool SetBinaryContent2(const unsigned char * data, unsigned long dataLen, bool zipFlag, bool encryptFlag, const char * password);
To be documented soon...
bool SetBinaryContentFromFile(const char * filename, bool zipFlag, bool encryptFlag, const char * 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.
void SortByAttribute(const char * attrName, long ascending);
Sorts the direct child nodes by the value of a specified attribute.
void SortByAttributeInt(const char * attrName, bool ascending);
Sorts the direct child nodes by the value of a specified attribute interpreted as an integer (not lexicographically as strings).
void SortByContent(long ascending);
Sorts the direct child nodes by content. XML Sort by Content
void SortByTag(long ascending);
Sorts the direct child nodes by tag. XML Sort by Tag
void SortRecordsByAttribute(const char * sortTag, const char * attrName, long ascending);
Sorts the direct child nodes by the content of an attribute in the grandchild nodes.
void SortRecordsByContent(const char * sortTag, long ascending);
Sorts the direct child nodes by the content of the grandchild nodes. XML Sort Records by Content
void SortRecordsByContentInt(const char * sortTag, bool 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).
bool SwapNode(const CkXml * node);
Swaps another node's tag, content, and attributes with this one.
bool SwapNode(const CkXml & node);
Swaps another node's tag, content, and attributes with this one.
bool SwapTree(const CkXml * tree);
Swaps another node's tag, content, attributes, and children with this one.
bool SwapTree(const CkXml & tree);
Swaps another node's tag, content, attributes, and children with this one.
bool TagContent(const char * tag, CkString & outStr);
To be documented soon...
bool TagEquals(const char * tag);
Returns true if the node's tag equals the specified string.
bool UnzipContent();
Unzip the content of the XML node replacing it's content with the decompressed data. Compress XML Content
bool UnzipTree();
Unzips and recreates the XML node and the entire subtree, restoring it to the state before it was zip compressed. Compress XML Tree
bool UpdateAttribute(const char * attrName, const char * attrValue);
Adds an attribute to the node if it doesn't already exist. Otherwise it updates the existing attribute with the new value. Update an XML Attribute
bool UpdateAttributeInt(const char * attrName, int value);
Updates an attribute value. (Call UpdateAttribute if the attribute value is a string.)
void UpdateChildContent(const char * tag, const char * value);
Replaces the content of a child node.
void UpdateChildContentInt(const char * tag, int value);
Replaces the content of a child node where the content is an integer.
bool ZipContent();
Applies Zip compression to the content of an XML node and replaces the content with base64-encoded compressed data. Compress XML Content
bool 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. Compress XML Tree
const char * accumulateTagContent(const char * tag, const char * skipTags);
Accumulates the content of all nodes having a specific tag into a single result string. SkipTags specifies a set of tags whose are 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 a null on failure
const char * attr(const char * name);
Find and return the value of an attribute having a specified name. Returns a null on failure
const char * attrName(long index);
Returns the name of the Nth attribute of an XML node. The first attribute is at index 0. Returns a null on failure
const char * attrValue(long index);
Returns the value of the Nth attribute of an XML node. The first attribute is at index 0. Returns a null on failure
const char * childContent(const char * tag);
Returns the content of a child having a specified tag. Returns a null on failure
const char * chilkatPath(const char * 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:
- TagName -- Navigate to the 1st direct child with the given tag.
- TagName[n] -- Navigate to the Nth direct child with the given tag.
- .. -- Navigate up to the parent
- TagName{Content} -- Navigate to the 1st direct child with the given tag having the exact content.
- /T/TagName -- Traverse the XML DOM tree (rooted at the caller) and navigate to the 1st node having the given tag.
- /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.
- /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.
- /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:
- * -- Return the Content of the node.
- (AttrName) -- Return the value of the given attribute.
- $ -- Update the caller's internal reference to be the node (arrived at by following the series of commands). Returns an empty string.
Returns a null on failure ChilkatPath Sample Code
const char * content();
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".Returns a null on failure Content vs. Children: A common misconception explained. Setting XML Tag and Content
const char * decodeEntities(const char * str);
Utility method to decode HTML entities. It accepts a string containing (potentially) HTML entities and returns a string with the entities decoded. Returns a null on failure
const char * docType();
The DOCTYPE declaration (if any) for the XML document. Returns a null on failure Setting the XML DOCTYPE
const char * encoding();
This is the encoding attribute in the XML declaration, such as "utf-8" or "iso-8859-1". If not present, this property returns an empty string. 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. Returns a null on failure
const char * getAttrValue(const char * name);
Find and return the value of an attribute having a specified name. Returns a null on failure Methods for Getting Attributes
const char * getAttributeName(long index);
Returns the name of the Nth attribute of an XML node. The first attribute is at index 0. Returns a null on failure Methods for Getting Attributes
const char * getAttributeValue(long index);
Returns the value of the Nth attribute of an XML node. The first attribute is at index 0. Returns a null on failure Methods for Getting Attributes
const char * getChildContent(const char * tag);
Returns the content of a child having a specified tag. Returns a null on failure
const char * getChildContentByIndex(long index);
Returns the content of the Nth child node. Returns a null on failure Iterate over Direct Child Nodes by Index
const char * getChildTag(long index);
Returns the tag name of the Nth child node. Returns a null on failure
const char * getChildTagByIndex(int index);
Returns the tag name of the Nth child node. Returns a null on failure Iterate over Direct Child Nodes by Index
const char * getXml();
Generate the XML text document for the XML tree rooted at this node. Returns a null on failure
const char * lastErrorHtml();
Error information in HTML format for the last method called.Returns a null on failure
const char * lastErrorText();
Error information in plain-text format for the last method called.Returns a null on failure
const char * lastErrorXml();
Error information in XML format for the last method called.Returns a null on failure
const char * tag();
The XML node's tag. Returns a null on failure Setting XML Tag and Content
const char * tagContent(const char * tag);
To be documented soon...
const char * version();
The version of the XML component, such as "2.0.0". Returns a null on failure
const char * xml();
Generate the XML text document for the XML tree rooted at this node. Returns a null on failure
|