#include "cpl_port.h"
Go to the source code of this file.
Classes | |
struct | _CPLXMLNode |
Typedefs | |
typedef _CPLXMLNode | CPLXMLNode |
Enumerations | |
enum | CPLXMLNodeType { CXT_Element = 0, CXT_Text = 1, CXT_Attribute = 2, CXT_Comment = 3, CXT_Literal = 4 } |
Functions | |
CPLXMLNode * | CPLParseXMLString (const char *) |
void | CPLDestroyXMLNode (CPLXMLNode *) |
CPLXMLNode * | CPLGetXMLNode (CPLXMLNode *poRoot, const char *pszPath) |
CPLXMLNode * | CPLSearchXMLNode (CPLXMLNode *poRoot, const char *pszTarget) |
const char * | CPLGetXMLValue (CPLXMLNode *poRoot, const char *pszPath, const char *pszDefault) |
CPLXMLNode * | CPLCreateXMLNode (CPLXMLNode *poParent, CPLXMLNodeType eType, const char *pszText) |
char * | CPLSerializeXMLTree (CPLXMLNode *psNode) |
void | CPLAddXMLChild (CPLXMLNode *psParent, CPLXMLNode *psChild) |
void | CPLAddXMLSibling (CPLXMLNode *psOlderSibling, CPLXMLNode *psNewSibling) |
CPLXMLNode * | CPLCreateXMLElementAndValue (CPLXMLNode *psParent, const char *pszName, const char *pszValue) |
CPLXMLNode * | CPLCloneXMLTree (CPLXMLNode *psTree) |
int | CPLSetXMLValue (CPLXMLNode *psRoot, const char *pszPath, const char *pszValue) |
void | CPLStripXMLNamespace (CPLXMLNode *psRoot, const char *pszNameSpace, int bRecurse) |
void | CPLCleanXMLElementName (char *) |
CPLXMLNode * | CPLParseXMLFile (const char *pszFilename) |
int | CPLSerializeXMLTreeToFile (CPLXMLNode *psTree, const char *pszFilename) |
|
Document node structure. This C structure is used to hold a single text fragment representing a component of the document when parsed. It should be allocated with the appropriate CPL function, and freed with CPLDestroyXMLNode(). The structure contents should not normally be altered by application code, but may be freely examined by application code. Using the psChild and psNext pointers, a heirarchical tree structure for a document can be represented as a tree of CPLXMLNode structures. |
|
|
|
Add child node to parent. The passed child is added to the list of children of the indicated parent. Normally the child is added at the end of the parents child list, but attributes (CXT_Attribute) will be inserted after any other attributes but before any other element type. Ownership of the child node is effectively assumed by the parent node. If the child has siblings (it's psNext is not NULL) they will be trimmed, but if the child has children they are carried with it.
|
|
Add new sibling. The passed psNewSibling is added to the end of siblings of the psOlderSibling node. That is, it is added to the end of the psNext chain. There is no special handling if psNewSibling is an attribute. If this is required, use CPLAddXMLChild().
|
|
Make string into safe XML token. Modififies a string in place to try and make it into a legal XML token that can be used as an element name. This is accomplished by changing any characters not legal in a token into an underscore. NOTE: This function should implement the rules in section 2.3 of http://www.w3.org/TR/xml11/ but it doesn't yet do that properly. We only do a rough approximation of that.
|
|
Copy tree. Creates a deep copy of a CPLXMLNode tree.
|
|
Create an element and text value. This is function is a convenient short form for: CPLXMLNode *psTextNode; CPLXMLNode *psElementNode; psElementNode = CPLCreateXMLNode( psParent, CXT_Element, pszName ); psTextNode = CPLCreateXMLNode( psElementNode, CXT_Text, pszValue ); return psElementNode; It creates a CXT_Element node, with a CXT_Text child, and attaches the element to the passed parent.
|
|
Create an document tree item. Create a single CPLXMLNode object with the desired value and type, and attach it as a child of the indicated parent.
|
|
Destroy a tree. This function frees resources associated with a CPLXMLNode and all its children nodes.
|
|
Find node by path. Searches the document or subdocument indicated by psRoot for an element (or attribute) with the given path. The path should consist of a set of element names separated by dots, not including the name of the root element (psRoot). If the requested element is not found NULL is returned. Attribute names may only appear as the last item in the path. The search is done from the root nodes children, but all intermediate nodes in the path must be specified. Seaching for "name" would only find a name element or attribute if it is a direct child of the root, not at any level in the subdocument. If the pszPath is prefixed by "=" then the search will begin with the root node, and it's siblings, instead of the root nodes children. This is particularly useful when searching within a whole document which is often prefixed by one or more "junk" nodes like the <?xml> declaration.
|
|
Fetch element/attribute value. Searches the document for the element/attribute value associated with the path. The corresponding node is internally found with CPLGetXMLNode() (see there for details on path handling). Once found, the value is considered to be the first CXT_Text child of the node. If the attribute/element search fails, or if the found node has not value then the passed default value is returned. The returned value points to memory within the document tree, and should not be altered or freed.
|
|
Parse XML file into tree. The named file is opened, loaded into memory as a big string, and parsed with CPLParseXMLString(). Errors in reading the file or parsing the XML will be reported by CPLError().
|
|
Parse an XML string into tree form. The passed document is parsed into a CPLXMLNode tree representation. If the document is not well formed XML then NULL is returned, and errors are reported via CPLError(). No validation beyond wellformedness is done. The CPLParseXMLFile() convenience function can be used to parse from a file. The returned document tree is is owned by the caller and should be freed with CPLDestroyXMLNode() when no longer needed. If the document has more than one "root level" element then those after the first will be attached to the first as siblings (via the psNext pointers) even though there is no common parent. A document with no XML structure (no angle brackets for instance) would be considered well formed, and returned as a single CXT_Text node.
|
|
Search for a node in document. Searches the children (and potentially siblings) of the documented passed in for the named element or attribute. To search following siblings as well as children, prefix the pszElement name with an equal sign. This function does an in-order traversal of the document tree. So it will first match against the current node, then it's first child, that childs first child, and so on. Use CPLGetXMLNode() to find a specific child, or along a specific node path.
|
|
Convert tree into string document. This function converts a CPLXMLNode tree representation of a document into a flat string representation. White space indentation is used visually preserve the tree structure of the document. The returned document becomes owned by the caller and should be freed with CPLFree() when no longer needed.
|
|
Write document tree to a file. The passed document tree is converted into one big string (with CPLSerializeXMLTree()) and then written to the named file. Errors writing the file will be reported by CPLError(). The source document tree is not altered. If the output file already exists it will be overwritten.
|
|
Set element value by path. Find (or create) the target element or attribute specified in the path, and assign it the indicated value. Any path elements that do not already exist will be created. The target nodes value (the first CXT_Text child) will be replaced with the provided value. If the target node is an attribute instead of an element, the last separator should be a "#" instead of the normal period path separator. Example: CPLSetXMLValue( "Citation.Id.Description", "DOQ dataset" ); CPLSetXMLValue( "Citation.Id.Description#name", "doq" );
|
|
Strip indicated namespaces. The subdocument (psRoot) is recursively examined, and any elements with the indicated namespace prefix will have the namespace prefix stripped from the element names. If the passed namespace is NULL, then all namespace prefixes will be stripped. Nodes other than elements should remain unaffected. The changes are made "in place", and should not alter any node locations, only the pszValue field of affected nodes.
|