diff --git a/ixml/inc/ixml.h b/ixml/inc/ixml.h index c7a549e..d24403d 100644 --- a/ixml/inc/ixml.h +++ b/ixml/inc/ixml.h @@ -1,4 +1,4 @@ -/******************************************************************************* +/************************************************************************** * * Copyright (c) 2000-2003 Intel Corporation * All rights reserved. @@ -6,12 +6,12 @@ * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * - * * Redistributions of source code must retain the above copyright notice, + * - Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright notice, + * - Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * * Neither name of Intel Corporation nor the names of its contributors + * - Neither name of Intel Corporation nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -27,36 +27,33 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - ******************************************************************************/ - -#ifndef _IXML_H_ -#define _IXML_H_ + **************************************************************************/ -#include -#include -#include +#ifndef IXML_H +#define IXML_H -#ifdef WIN32 - #ifndef UPNP_STATIC_LIB - #ifdef LIBUPNP_EXPORTS - /* set up declspec for dll export to make functions visible to library users */ - #define EXPORT_SPEC __declspec(dllexport) - #else - #define EXPORT_SPEC __declspec(dllimport) - #endif - #else - #define EXPORT_SPEC - #endif -#else - #define EXPORT_SPEC -#endif +/*! + * \file + * + * \defgroup XMLAPI XML API + * + * @{ + */ + + +#include "UpnpGlobal.h" /* For EXPORT_SPEC */ + typedef int BOOL; -#define DOMString char * +/*! + * \brief The type of DOM strings. + */ +#define DOMString char * +/*typedef char *DOMString;*/ #ifndef TRUE @@ -79,7 +76,10 @@ typedef int BOOL; #define INOUT #endif -/**@name DOM Interfaces + +/*! + * \name DOM Interfaces + * * The Document Object Model consists of a set of objects and interfaces * for accessing and manipulating documents. IXML does not implement all * the interfaces documented in the DOM2-Core recommendation but defines @@ -88,66 +88,59 @@ typedef int BOOL; * * For a complete discussion on the object model, the object hierarchy, * etc., refer to section 1.1 of the DOM2-Core recommendation. + * + * @{ */ -/*! @{ */ - -/*================================================================ -* -* DOM node type -* -* -*=================================================================*/ -typedef enum -{ - eINVALID_NODE = 0, - eELEMENT_NODE = 1, - eATTRIBUTE_NODE = 2, - eTEXT_NODE = 3, - eCDATA_SECTION_NODE = 4, - eENTITY_REFERENCE_NODE = 5, - eENTITY_NODE = 6, - ePROCESSING_INSTRUCTION_NODE = 7, - eCOMMENT_NODE = 8, - eDOCUMENT_NODE = 9, - eDOCUMENT_TYPE_NODE = 10, - eDOCUMENT_FRAGMENT_NODE = 11, - eNOTATION_NODE = 12, +/*! + * \brief The type of the DOM node + */ +typedef enum { + eINVALID_NODE = 0, + eELEMENT_NODE = 1, + eATTRIBUTE_NODE = 2, + eTEXT_NODE = 3, + eCDATA_SECTION_NODE = 4, + eENTITY_REFERENCE_NODE = 5, + eENTITY_NODE = 6, + ePROCESSING_INSTRUCTION_NODE = 7, + eCOMMENT_NODE = 8, + eDOCUMENT_NODE = 9, + eDOCUMENT_TYPE_NODE = 10, + eDOCUMENT_FRAGMENT_NODE = 11, + eNOTATION_NODE = 12, } IXML_NODE_TYPE; -/*================================================================ -* -* error code -* -* -*=================================================================*/ -typedef enum -{ /* see DOM spec */ - IXML_INDEX_SIZE_ERR = 1, - IXML_DOMSTRING_SIZE_ERR = 2, - IXML_HIERARCHY_REQUEST_ERR = 3, - IXML_WRONG_DOCUMENT_ERR = 4, - IXML_INVALID_CHARACTER_ERR = 5, - IXML_NO_DATA_ALLOWED_ERR = 6, - IXML_NO_MODIFICATION_ALLOWED_ERR = 7, - IXML_NOT_FOUND_ERR = 8, - IXML_NOT_SUPPORTED_ERR = 9, - IXML_INUSE_ATTRIBUTE_ERR = 10, - IXML_INVALID_STATE_ERR = 11, - IXML_SYNTAX_ERR = 12, - IXML_INVALID_MODIFICATION_ERR = 13, - IXML_NAMESPACE_ERR = 14, - IXML_INVALID_ACCESS_ERR = 15, - IXML_SUCCESS = 0, - IXML_NO_SUCH_FILE = 101, - IXML_INSUFFICIENT_MEMORY = 102, - IXML_FILE_DONE = 104, - IXML_INVALID_PARAMETER = 105, - IXML_FAILED = 106, - IXML_INVALID_ITEM_NUMBER = 107, +/*! + * \brief Error codes returned by the XML API, see the DOM spec + */ +typedef enum { + IXML_SUCCESS = 0, + IXML_INDEX_SIZE_ERR = 1, + IXML_DOMSTRING_SIZE_ERR = 2, + IXML_HIERARCHY_REQUEST_ERR = 3, + IXML_WRONG_DOCUMENT_ERR = 4, + IXML_INVALID_CHARACTER_ERR = 5, + IXML_NO_DATA_ALLOWED_ERR = 6, + IXML_NO_MODIFICATION_ALLOWED_ERR = 7, + IXML_NOT_FOUND_ERR = 8, + IXML_NOT_SUPPORTED_ERR = 9, + IXML_INUSE_ATTRIBUTE_ERR = 10, + IXML_INVALID_STATE_ERR = 11, + IXML_SYNTAX_ERR = 12, + IXML_INVALID_MODIFICATION_ERR = 13, + IXML_NAMESPACE_ERR = 14, + IXML_INVALID_ACCESS_ERR = 15, + + IXML_NO_SUCH_FILE = 101, + IXML_INSUFFICIENT_MEMORY = 102, + IXML_FILE_DONE = 104, + IXML_INVALID_PARAMETER = 105, + IXML_FAILED = 106, + IXML_INVALID_ITEM_NUMBER = 107, } IXML_ERRORCODE; @@ -155,1767 +148,1684 @@ typedef enum #define TEXTNODENAME "#text" #define CDATANODENAME "#cdata-section" -/*================================================================ -* -* DOM data structures -* -* -*=================================================================*/ + typedef struct _IXML_Document *Docptr; -typedef struct _IXML_Node *Nodeptr; + +typedef struct _IXML_Node *Nodeptr; + + +/*! + * \brief Data structure common to all types of nodes. + */ typedef struct _IXML_Node { - DOMString nodeName; - DOMString nodeValue; - IXML_NODE_TYPE nodeType; - DOMString namespaceURI; - DOMString prefix; - DOMString localName; - BOOL readOnly; - - Nodeptr parentNode; - Nodeptr firstChild; - Nodeptr prevSibling; - Nodeptr nextSibling; - Nodeptr firstAttr; - Docptr ownerDocument; - + DOMString nodeName; + DOMString nodeValue; + IXML_NODE_TYPE nodeType; + DOMString namespaceURI; + DOMString prefix; + DOMString localName; + BOOL readOnly; + + Nodeptr parentNode; + Nodeptr firstChild; + Nodeptr prevSibling; + Nodeptr nextSibling; + Nodeptr firstAttr; + Docptr ownerDocument; } IXML_Node; + +/*! + * \brief Data structure representing the DOM Document. + */ typedef struct _IXML_Document { - IXML_Node n; + IXML_Node n; } IXML_Document; + +/*! + * \brief Data structure representing a CDATA section node. + */ typedef struct _IXML_CDATASection { - IXML_Node n; + IXML_Node n; } IXML_CDATASection; + +/*! + * \brief Data structure representing an Element node. + */ typedef struct _IXML_Element { - IXML_Node n; - DOMString tagName; - + IXML_Node n; + DOMString tagName; } IXML_Element; + +/*! + * \brief Data structure representing an Attribute node. + */ typedef struct _IXML_ATTR { - IXML_Node n; - BOOL specified; - IXML_Element *ownerElement; + IXML_Node n; + BOOL specified; + IXML_Element *ownerElement; } IXML_Attr; + +/*! + * \brief Data structure representing a Text node. + */ typedef struct _IXML_Text { - IXML_Node n; + IXML_Node n; } IXML_Text; + +/*! + * \brief Data structure representing a list of nodes. + */ typedef struct _IXML_NodeList { - IXML_Node *nodeItem; - struct _IXML_NodeList *next; + IXML_Node *nodeItem; + struct _IXML_NodeList *next; } IXML_NodeList; +/*! + * \brief Data structure representing a list of named nodes. + */ typedef struct _IXML_NamedNodeMap { - IXML_Node *nodeItem; - struct _IXML_NamedNodeMap *next; + IXML_Node *nodeItem; + struct _IXML_NamedNodeMap *next; } IXML_NamedNodeMap; +/* @} DOM Interfaces */ + + + #ifdef __cplusplus extern "C" { #endif -/*================================================================ -* -* NODE interfaces -* -* -*=================================================================*/ -/**@name Interface {\it Node} - * The {\bf Node} interface forms the primary datatype for all other DOM - * objects. Every other interface is derived from this interface, inheriting - * its functionality. For more information, refer to DOM2-Core page 34. +/*! + * \name Interface Node + * + * The \b Node interface forms the primary datatype for all other DOM + * objects. Every other interface is derived from this interface, inheriting + * its functionality. For more information, refer to DOM2-Core page 34. + * + * @{ */ -/*! @{ */ - - /** Returns the name of the {\bf Node}, depending on what type of - * {\bf Node} it is, in a read-only string. Refer to the table in the - * DOM2-Core for a description of the node names for various interfaces. - * - * @return [const DOMString] A constant {\bf DOMString} of the node name. - */ - -EXPORT_SPEC const DOMString -ixmlNode_getNodeName(IXML_Node *nodeptr - /** Pointer to the node to retrieve the name. */ - ); - - /** Returns the value of the {\bf Node} as a string. Note that this string - * is not a copy and modifying it will modify the value of the {\bf Node}. - * - * @return [DOMString] A {\bf DOMString} of the {\bf Node} value. - */ - -EXPORT_SPEC const DOMString -ixmlNode_getNodeValue(IXML_Node *nodeptr - /** Pointer to the {\bf Node} to retrieve the value. */ - ); - - /** Assigns a new value to a {\bf Node}. The {\bf newNodeValue} string is - * duplicated and stored in the {\bf Node} so that the original does not - * have to persist past this call. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: The {\bf Node*} is not a valid - * pointer. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ - -EXPORT_SPEC int -ixmlNode_setNodeValue(IXML_Node *nodeptr, - /** The {\bf Node} to which to assign a new value. */ - const char *newNodeValue - /** The new value of the {\bf Node}. */ - ); - - /** Retrieves the type of a {\bf Node}. The defined {\bf Node} constants - * are: - * \begin{itemize} - * \item {\tt eATTRIBUTE_NODE} - * \item {\tt eCDATA_SECTION_NODE} - * \item {\tt eCOMMENT_NODE} - * \item {\tt eDOCUMENT_FRAGMENT_NODE} - * \item {\tt eDOCUMENT_NODE} - * \item {\tt eDOCUMENT_TYPE_NODE} - * \item {\tt eELEMENT_NODE} - * \item {\tt eENTITY_NODE} - * \item {\tt eENTITY_REFERENCE_NODE} - * \item {\tt eNOTATION_NODE} - * \item {\tt ePROCESSING_INSTRUCTION_NODE} - * \item {\tt eTEXT_NODE} - * \end{itemize} - * - * @return [const unsigned short] An integer representing the type of the - * {\bf Node}. - */ - -EXPORT_SPEC unsigned short -ixmlNode_getNodeType(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the type. */ - ); - - /** Retrieves the parent {\bf Node} for a {\bf Node}. - * - * @return [Node*] A pointer to the parent {\bf Node} or {\tt NULL} if the - * {\bf Node} has no parent. - */ - -EXPORT_SPEC IXML_Node* -ixmlNode_getParentNode(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the - parent. */ - ); - - /** Retrieves the list of children of a {\bf Node} in a {\bf NodeList} - * structure. If a {\bf Node} has no children, {\bf ixmlNode_getChildNodes} - * returns a {\bf NodeList} structure that contains no {\bf Node}s. - * - * @return [NodeList*] A {\bf NodeList} of the children of the {\bf Node}. - */ - -EXPORT_SPEC IXML_NodeList* -ixmlNode_getChildNodes(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the - children. */ - ); - - /** Retrieves the first child {\bf Node} of a {\bf Node}. - * - * @return [Node*] A pointer to the first child {\bf Node} or {\tt NULL} - * if the {\bf Node} does not have any children. - */ - -EXPORT_SPEC IXML_Node* -ixmlNode_getFirstChild(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the first - child. */ -); - - /** Retrieves the last child {\bf Node} of a {\bf Node}. - * - * @return [Node*] A pointer to the last child {\bf Node} or {\tt NULL} if - * the {\bf Node} does not have any children. - */ - -EXPORT_SPEC IXML_Node* -ixmlNode_getLastChild(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the last - child. */ - ); - - /** Retrieves the sibling {\bf Node} immediately preceding this {\bf Node}. - * - * @return [Node*] A pointer to the previous sibling {\bf Node} or - * {\tt NULL} if no such {\bf Node} exists. - */ - -EXPORT_SPEC IXML_Node* -ixmlNode_getPreviousSibling(IXML_Node *nodeptr - /** The {\bf Node} for which to retrieve the - previous sibling. */ - ); - - /** Retrieves the sibling {\bf Node} immediately following this {\bf Node}. - * - * @return [Node*] A pointer to the next sibling {\bf Node} or {\tt NULL} - * if no such {\bf Node} exists. - */ - -EXPORT_SPEC IXML_Node* -ixmlNode_getNextSibling(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the next - sibling. */ - ); - - /** Retrieves the attributes of a {\bf Node}, if it is an {\bf Element} node, - * in a {\bf NamedNodeMap} structure. - * - * @return [NamedNodeMap*] A {\bf NamedNodeMap} of the attributes or - * {\tt NULL}. - */ - -EXPORT_SPEC IXML_NamedNodeMap* -ixmlNode_getAttributes(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the - attributes. */ - ); - - /** Retrieves the document object associated with this {\bf Node}. This - * owner document {\bf Node} allows other {\bf Node}s to be created in the - * context of this document. Note that {\bf Document} nodes do not have - * an owner document. - * - * @return [Document*] A pointer to the owning {\bf Document} or - * {\tt NULL}, if the {\bf Node} does not have an owner. - */ - -EXPORT_SPEC IXML_Document* -ixmlNode_getOwnerDocument(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the - owner document. */ - ); - - /** Retrieves the namespace URI for a {\bf Node} as a {\bf DOMString}. Only - * {\bf Node}s of type {\tt eELEMENT_NODE} or {\tt eATTRIBUTE_NODE} can - * have a namespace URI. {\bf Node}s created through the {\bf Document} - * interface will only contain a namespace if created using - * {\bf ixmlDocument_createElementNS}. - * - * @return [const DOMString] A {\bf DOMString} representing the URI of the - * namespace or {\tt NULL}. - */ - -EXPORT_SPEC const DOMString -ixmlNode_getNamespaceURI(IXML_Node *nodeptr - /** The {\bf Node} for which to retrieve the - namespace. */ - ); - - /** Retrieves the namespace prefix, if present. The prefix is the name - * used as an alias for the namespace URI for this element. Only - * {\bf Node}s of type {\tt eELEMENT_NODE} or {\tt eATTRIBUTE_NODE} can have - * a prefix. {\bf Node}s created through the {\bf Document} interface will - * only contain a prefix if created using {\bf ixmlDocument_createElementNS}. - * - * @return [DOMString] A {\bf DOMString} representing the namespace prefix - * or {\tt NULL}. - */ - -EXPORT_SPEC const DOMString -ixmlNode_getPrefix(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the prefix. */ - ); - - /** Retrieves the local name of a {\bf Node}, if present. The local name is - * the tag name without the namespace prefix. Only {\bf Node}s of type - * {\tt eELEMENT_NODE} or {\tt eATTRIBUTE_NODE} can have a local name. - * {\Bf Node}s created through the {\bf Document} interface will only - * contain a local name if created using {\bf ixmlDocument_createElementNS}. - * - * @return [const DOMString] A {\bf DOMString} representing the local name - * of the {\bf Element} or {\tt NULL}. - */ - -EXPORT_SPEC const DOMString -ixmlNode_getLocalName(IXML_Node *nodeptr - /** The {\bf Node} from which to retrieve the local - name. */ - ); - - /** Inserts a new child {\bf Node} before the existing child {\bf Node}. - * {\bf refChild} can be {\tt NULL}, which inserts {\bf newChild} at the - * end of the list of children. Note that the {\bf Node} (or {\bf Node}s) - * in {\bf newChild} must already be owned by the owner document (or have no - * owner at all) of {\bf nodeptr} for insertion. If not, the {\bf Node} - * (or {\bf Node}s) must be imported into the document using - * {\bf ixmlDocument_importNode}. If {\bf newChild} is already in the tree, - * it is removed first. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf nodeptr} or - * {\bf newChild} is {\tt NULL}. - * \item {\tt IXML_HIERARCHY_REQUEST_ERR}: The type of the {\bf Node} - * does not allow children of the type of {\bf newChild}. - * \item {\tt IXML_WRONG_DOCUMENT_ERR}: {\bf newChild} has an owner - * document that does not match the owner of {\bf nodeptr}. - * \item {\tt IXML_NO_MODIFICATION_ALLOWED_ERR}: {\bf nodeptr} is - * read-only or the parent of the {\bf Node} being inserted is - * read-only. - * \item {\tt IXML_NOT_FOUND_ERR}: {\bf refChild} is not a child of - * {\bf nodeptr}. - * \end{itemize} - */ - -EXPORT_SPEC int -ixmlNode_insertBefore(IXML_Node *nodeptr, - /** The parent of the {\bf Node} before which to - insert the new child. */ - IXML_Node* newChild, - /** The {\bf Node} to insert into the tree. */ - IXML_Node* refChild - /** The reference child where the new {\bf Node} - should be inserted. The new {\bf Node} will - appear directly before the reference child. */ - ); - - /** Replaces an existing child {\bf Node} with a new child {\bf Node} in - * the list of children of a {\bf Node}. If {\bf newChild} is already in - * the tree, it will first be removed. {\bf returnNode} will contain the - * {\bf oldChild} {\bf Node}, appropriately removed from the tree (i.e. it - * will no longer have an owner document). - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMTER: Either {\bf nodeptr}, {\bf - * newChild}, or {\bf oldChild} is {\tt NULL}. - * \item {\tt IXML_HIERARCHY_REQUEST_ERR}: The {\bf newChild} is not - * a type of {\bf Node} that can be inserted into this tree or - * {\bf newChild} is an ancestor of {\bf nodePtr}. - * \item {\tt IXML_WRONG_DOCUMENT_ERR}: {\bf newChild} was created from - * a different document than {\bf nodeptr}. - * \item {\tt IXML_NO_MODIFICATION_ALLOWED_ERR}: {\bf nodeptr} or - * its parent is read-only. - * \item {\tt IXML_NOT_FOUND_ERR}: {\bf oldChild} is not a child of - * {\bf nodeptr}. - * \end{itemize} - */ - -EXPORT_SPEC int -ixmlNode_replaceChild(IXML_Node *nodeptr, - /** The parent of the {\bf Node} which contains the - child to replace. */ - IXML_Node* newChild, - /** The child with which to replace {\bf oldChild}. */ - IXML_Node* oldChild, - /** The child to replace with {\bf newChild}. */ - IXML_Node** returnNode - /** Pointer to a {\bf Node} to place the removed {\bf - oldChild} {\bf Node}. */ - ); - - /** Removes a child from the list of children of a {\bf Node}. - * {\bf returnNode} will contain the {\bf oldChild} {\bf Node}, - * appropriately removed from the tree (i.e. it will no longer have an - * owner document). - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf nodeptr} or - * {\bf oldChild} is {\tt NULL}. - * \item {\tt IXML_NO_MODIFICATION_ALLOWED_ERR}: {\bf nodeptr} or its - * parent is read-only. - * \item {\tt IXML_NOT_FOUND_ERR}: {\bf oldChild} is not among the - * children of {\bf nodeptr}. - * \end{itemize} - */ - -EXPORT_SPEC int -ixmlNode_removeChild(IXML_Node *nodeptr, - /** The parent of the child to remove. */ - IXML_Node* oldChild, - /** The child {\bf Node} to remove. */ - IXML_Node **returnNode - /** Pointer to a {\bf Node} to place the removed {\bf - oldChild} {\bf Node}. */ - ); - - /** Appends a child {\bf Node} to the list of children of a {\bf Node}. If - * {\bf newChild} is already in the tree, it is removed first. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf nodeptr} or - * {\bf newChild} is {\tt NULL}. - * \item {\tt IXML_HIERARCHY_REQUEST_ERR}: {\bf newChild} is of a type - * that cannot be added as a child of {\bf nodeptr} or - * {\bf newChild} is an ancestor of {\bf nodeptr}. - * \item {\tt IXML_WRONG_DOCUMENT_ERR}: {\bf newChild} was created from - * a different document than {\bf nodeptr}. - * \item {\tt IXML_NO_MODIFICATION_ALLOWED_ERR}: {\bf nodeptr} is a - * read-only {\bf Node}. - */ - -EXPORT_SPEC int -ixmlNode_appendChild(IXML_Node *nodeptr, - /** The {\bf Node} in which to append the new child. */ - IXML_Node* newChild - /** The new child to append. */ - ); - - /** Queries whether or not a {\bf Node} has children. - * - * @return [BOOL] {\tt TRUE} if the {\bf Node} has one or more children - * otherwise {\tt FALSE}. - */ - -EXPORT_SPEC BOOL -ixmlNode_hasChildNodes(IXML_Node *nodeptr - /** The {\bf Node} to query for children. */ - ); - - /** Clones a {\bf Node}. The new {\bf Node} does not have a parent. The - * {\bf deep} parameter controls whether the subtree of the {\bf Node} is - * also cloned. For details on cloning specific types of {\bf Node}s, - * refer to the DOM2-Core recommendation. - * - * @return [Node*] A clone of {\bf nodeptr} or {\tt NULL}. - */ - -EXPORT_SPEC IXML_Node* -ixmlNode_cloneNode(IXML_Node *nodeptr, - /** The {\bf Node} to clone. */ - BOOL deep - /** {\tt TRUE} to clone the subtree also or {\tt FALSE} - to clone only {\bf nodeptr}. */ - ); - - /** Queries whether this {\bf Node} has attributes. Note that only - * {\bf Element} nodes have attributes. - * - * @return [BOOL] {\tt TRUE} if the {\bf Node} has attributes otherwise - * {\tt FALSE}. - */ - -EXPORT_SPEC BOOL -ixmlNode_hasAttributes(IXML_Node *nodeptr - /** The {\bf Node} to query for attributes. */ - ); - - /** Frees a {\bf Node} and all {\bf Node}s in its subtree. - * - * @return [void] This function does not return a value. - */ - -EXPORT_SPEC void -ixmlNode_free(IXML_Node *nodeptr - /** The {\bf Node} to free. */ - ); - -/*! @} */ - -/*================================================================ -* -* Attribute interfaces -* -* -*=================================================================*/ - -/**@name Interface {\it Attr} - * The {\bf Attr} interface represents an attribute of an {\bf Element}. - * The document type definition (DTD) or schema usually dictate the - * allowable attributes and values for a particular element. For more - * information, refer to the {\it Interface Attr} section in the DOM2-Core. +/*! + * \brief Returns the name of the \b Node, depending on what type of + * \b Node it is, in a read-only string. + * + * Refer to the table in the + * DOM2-Core for a description of the node names for various interfaces. + * + * \return A constant \b DOMString of the node name. */ -/*! @{ */ +EXPORT_SPEC const DOMString ixmlNode_getNodeName( + /*! [in] Pointer to the node to retrieve the name. */ + IXML_Node *nodeptr); - /** Frees an {\bf Attr} node. - * - * @return [void] This function does not return a value. - */ - -EXPORT_SPEC void -ixmlAttr_free(IXML_Attr *attrNode - /** The {\bf Attr} node to free. */ - ); - -/*! @} */ +/*! + * \brief Returns the value of the \b Node as a string. + * + * Note that this string is not a copy and modifying it will modify the value + * of the \b Node. + * + * \return A \b DOMString of the \b Node value. + */ +EXPORT_SPEC const DOMString ixmlNode_getNodeValue( + /*! [in] Pointer to the \b Node to retrieve the value. */ + IXML_Node *nodeptr); -/*================================================================ -* -* CDATASection interfaces -* -* -*=================================================================*/ +/*! + * \brief Assigns a new value to a \b Node. + * + * The \b newNodeValue string is duplicated and stored in the \b Node so that + * the original does not have to persist past this call. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: The Node * is not a valid pointer. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists to + * complete this operation. + */ +EXPORT_SPEC int ixmlNode_setNodeValue( + /*! [in] The \b Node to which to assign a new value. */ + IXML_Node *nodeptr, + /*! [in] The new value of the \b Node. */ + const char *newNodeValue); -/**@name Interface {\it CDATASection} - * The {\bf CDATASection} is used to escape blocks of text containing + +/*! + * \brief Retrieves the type of a \b Node. + * + * \return An enum IXML_NODE_TYPE representing the type of the \b Node. + */ +EXPORT_SPEC unsigned short ixmlNode_getNodeType( + /*! [in] The \b Node from which to retrieve the type. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the parent \b Node for a \b Node. + * + * \return A pointer to the parent \b Node or \c NULL if the \b Node has no + * parent. + */ +EXPORT_SPEC IXML_Node *ixmlNode_getParentNode( + /*! [in] The \b Node from which to retrieve the parent. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the list of children of a \b Node in a \b NodeList + * structure. + * + * If a \b Node has no children, \b ixmlNode_getChildNodes + * returns a \b NodeList structure that contains no \b Nodes. + * + * \return A \b NodeList of the children of the \b Node. + */ +EXPORT_SPEC IXML_NodeList *ixmlNode_getChildNodes( + /*! [in] The \b Node from which to retrieve the children. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the first child \b Node of a \b Node. + * + * \return A pointer to the first child \b Node or \c NULL if the \b Node does + * not have any children. + */ +EXPORT_SPEC IXML_Node *ixmlNode_getFirstChild( + /*! [in] The \b Node from which to retrieve the first child. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the last child \b Node of a \b Node. + * + * \return A pointer to the last child \b Node or \c NULL if the \b Node does + * not have any children. + */ +EXPORT_SPEC IXML_Node *ixmlNode_getLastChild( + /*! [in] The \b Node from which to retrieve the last child. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the sibling \b Node immediately preceding this \b Node. + * + * \return A pointer to the previous sibling \b Node or \c NULL if no such + * \b Node exists. + */ +EXPORT_SPEC IXML_Node *ixmlNode_getPreviousSibling( + /*! [in] The \b Node for which to retrieve the previous sibling. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the sibling \b Node immediately following this \b Node. + * + * \return A pointer to the next sibling \b Node or \c NULL if no such + * \b Node exists. + */ +EXPORT_SPEC IXML_Node *ixmlNode_getNextSibling( + /*! [in] The \b Node from which to retrieve the next sibling. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the attributes of a \b Node, if it is an \b Element node, + * in a \b NamedNodeMap structure. + * + * \return A \b NamedNodeMap of the attributes or \c NULL. + */ +EXPORT_SPEC IXML_NamedNodeMap *ixmlNode_getAttributes( + /*! [in] The \b Node from which to retrieve the attributes. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the document object associated with this \b Node. + * + * This owner document \b Node allows other \b Nodes to be created in the + * context of this document. Note that \b Document nodes do not have an + * owner document. + * + * \return A pointer to the owning \b Document or \c NULL, if the \b Node + * does not have an owner. + */ +EXPORT_SPEC IXML_Document *ixmlNode_getOwnerDocument( + /*! [in] The \b Node from which to retrieve the owner document. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the namespace URI for a \b Node as a \b DOMString. + * + * Only \b Nodes of type \c eELEMENT_NODE or \c eATTRIBUTE_NODE can have a + * namespace URI. \b Nodes created through the \b Document interface will + * only contain a namespace if created using \b ixmlDocument_createElementNS. + * + * \return A \b DOMString representing the URI of the namespace or \c NULL. + */ +EXPORT_SPEC const DOMString ixmlNode_getNamespaceURI( + /*! [in] The \b Node for which to retrieve the namespace. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the namespace prefix, if present. + * + * The prefix is the name used as an alias for the namespace URI for this + * element. Only \b Nodes of type \c eELEMENT_NODE or \c eATTRIBUTE_NODE can + * have a prefix. \b Nodes created through the \b Document interface will only + * contain a prefix if created using \b ixmlDocument_createElementNS. + * + * \return A \b DOMString representing the namespace prefix or \c NULL. + */ +EXPORT_SPEC const DOMString +ixmlNode_getPrefix( + /*! The \b Node from which to retrieve the prefix. */ + IXML_Node *nodeptr); + + +/*! + * \brief Retrieves the local name of a \b Node, if present. + * + * The local name is the tag name without the namespace prefix. Only \b Nodes + * of type \c eELEMENT_NODE or \c eATTRIBUTE_NODE can have a local name. + * \b Nodes created through the \b Document interface will only contain a local + * name if created using \b ixmlDocument_createElementNS. + * + * \return A \b DOMString representing the local name of the \b Element or + * \c NULL. + */ +EXPORT_SPEC const DOMString ixmlNode_getLocalName( + /*! [in] The \b Node from which to retrieve the local name. */ + IXML_Node *nodeptr); + +/*! + * \brief Inserts a new child \b Node before the existing child \b Node. + * + * \b refChild can be \c NULL, which inserts \b newChild at the + * end of the list of children. Note that the \b Node (or \b Nodes) + * in \b newChild must already be owned by the owner document (or have no + * owner at all) of \b nodeptr for insertion. If not, the \b Node + * (or \b Nodes) must be imported into the document using + * \b ixmlDocument_importNode. If \b newChild is already in the tree, + * it is removed first. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b nodeptr or + * \b newChild is \c NULL. + * \li \c IXML_HIERARCHY_REQUEST_ERR: The type of the \b Node + * does not allow children of the type of \b newChild. + * \li \c IXML_WRONG_DOCUMENT_ERR: \b newChild has an owner + * document that does not match the owner of \b nodeptr. + * \li \c IXML_NO_MODIFICATION_ALLOWED_ERR: \b nodeptr is + * read-only or the parent of the \b Node being inserted is + * read-only. + * \li \c IXML_NOT_FOUND_ERR: \b refChild is not a child of + * \b nodeptr. + */ +EXPORT_SPEC int ixmlNode_insertBefore( + /*! [in] The parent of the \b Node before which to insert the new child. */ + IXML_Node *nodeptr, + /*! [in] The \b Node to insert into the tree. */ + IXML_Node * newChild, + /*! [in] The reference child where the new \b Node should be inserted. + * The new \b Node will appear directly before the reference child. */ + IXML_Node * refChild); + + +/*! + * \brief Replaces an existing child \b Node with a new child \b Node in the + * list of children of a \b Node. + * + * If \b newChild is already in the tree, it will first be removed. + * \b returnNode will contain the \b oldChild \b Node, appropriately removed + * from the tree (i.e. it will no longer have an owner document). + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMTER: Either \b nodeptr, \b newChild, + * or \b oldChild is \c NULL. + * \li \c IXML_HIERARCHY_REQUEST_ERR: The \b newChild is not + * a type of \b Node that can be inserted into this tree or + * \b newChild is an ancestor of \b nodePtr. + * \li \c IXML_WRONG_DOCUMENT_ERR: \b newChild was created from + * a different document than \b nodeptr. + * \li \c IXML_NO_MODIFICATION_ALLOWED_ERR: \b nodeptr or + * its parent is read-only. + * \li \c IXML_NOT_FOUND_ERR: \b oldChild is not a child of + * \b nodeptr. + */ +EXPORT_SPEC int ixmlNode_replaceChild( + /*! [in] The parent of the \b Node which contains the child to replace. */ + IXML_Node *nodeptr, + /*! [in] The child with which to replace \b oldChild. */ + IXML_Node *newChild, + /*! [in] The child to replace with \b newChild. */ + IXML_Node *oldChild, + /*! [out] Pointer to a \b Node to place the removed \b oldChild \b Node. */ + IXML_Node **returnNode); + + +/*! + * \brief Removes a child from the list of children of a \b Node. + * + * \b returnNode will contain the \b oldChild \b Node, + * appropriately removed from the tree (i.e. it will no longer have an + * owner document). + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b nodeptr or + * \b oldChild is \c NULL. + * \li \c IXML_NO_MODIFICATION_ALLOWED_ERR: \b nodeptr or its + * parent is read-only. + * \li \c IXML_NOT_FOUND_ERR: \b oldChild is not among the + * children of \b nodeptr. + */ +EXPORT_SPEC int ixmlNode_removeChild( + /*! [in] The parent of the child to remove. */ + IXML_Node *nodeptr, + /*! [in] The child \b Node to remove. */ + IXML_Node *oldChild, + /*! [out] Pointer to a \b Node to place the removed \b oldChild \b Node. */ + IXML_Node **returnNode); + + +/*! + * \brief Appends a child \b Node to the list of children of a \b Node. + * + * If \b newChild is already in the tree, it is removed first. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b nodeptr or + * \b newChild is \c NULL. + * \li \c IXML_HIERARCHY_REQUEST_ERR: \b newChild is of a type + * that cannot be added as a child of \b nodeptr or + * \b newChild is an ancestor of \b nodeptr. + * \li \c IXML_WRONG_DOCUMENT_ERR: \b newChild was created from + * a different document than \b nodeptr. + * \li \c IXML_NO_MODIFICATION_ALLOWED_ERR: \b nodeptr is a + * read-only \b Node. + */ +EXPORT_SPEC int ixmlNode_appendChild( + /*! [in] The \b Node in which to append the new child. */ + IXML_Node *nodeptr, + /*! [in] The new child to append. */ + IXML_Node * newChild); + + +/*! + * \brief Queries whether or not a \b Node has children. + * + * \return \c TRUE if the \b Node has one or more children otherwise \c FALSE. + */ +EXPORT_SPEC BOOL ixmlNode_hasChildNodes( + /*! [in] The \b Node to query for children. */ + IXML_Node *nodeptr); + + +/*! + * \brief Clones a \b Node. + * + * The new \b Node does not have a parent. The \b deep parameter controls + * whether the subtree of the \b Node is also cloned. + * + * For details on cloning specific types of \b Nodes, refer to the + * DOM2-Core recommendation. + * + * \return A clone of \b nodeptr or \c NULL. + */ +EXPORT_SPEC IXML_Node *ixmlNode_cloneNode( + /*! [in] The \b Node to clone. */ + IXML_Node *nodeptr, + /*! [in] \c TRUE to clone the subtree also or \c FALSE to clone only + * \b nodeptr. */ + BOOL deep); + + +/*! + * \brief Queries whether this \b Node has attributes. + * + * Note that only \b Element nodes have attributes. + * + * \return \c TRUE if the \b Node has attributes otherwise \c FALSE. + */ +EXPORT_SPEC BOOL ixmlNode_hasAttributes( + /*! [in] The \b Node to query for attributes. */ + IXML_Node *nodeptr); + + +/*! + * \brief Frees a \b Node and all \b Nodes in its subtree. + */ +EXPORT_SPEC void ixmlNode_free( + /*! [in] The \b Node tree to free. */ + IXML_Node *nodeptr); + +/* @} Interface Node */ + + + +/*! + * \name Interface Attr + * + * The \b Attr interface represents an attribute of an \b Element. The document + * type definition (DTD) or schema usually dictate the allowable attributes and + * values for a particular element. + * + * For more information, refer to the Interface Attr section in the + * DOM2-Core. + * + * @{ + */ + + +/*! + * \brief Frees an \b Attr node. + */ +EXPORT_SPEC void ixmlAttr_free( + /*! The \b Attr node to free. */ + IXML_Attr *attrNode); + + +/* @} Interface Attr */ + + + +/*! + * \name Interface CDATASection + * + * The \b CDATASection is used to escape blocks of text containing * characters that would otherwise be regarded as markup. CDATA sections * cannot be nested. Their primary purpose is for including material such - * XML fragments, without needing to escape all the delimiters. For more - * information, refer to the {\it Interface CDATASection} section in the - * DOM2-Core. + * XML fragments, without needing to escape all the delimiters. + * + * For more information, refer to the Interface CDATASection section + * in the DOM2-Core. + * + * @{ */ -/*! @{ */ - /** Initializes a {\bf CDATASection} node. - * - * @return [void] This function does not return a value. - */ - -EXPORT_SPEC void -ixmlCDATASection_init(IXML_CDATASection *nodeptr - /** The {\bf CDATASection} node to initialize. */ - ); - - - /** Frees a {\bf CDATASection} node. - * - * @return [void] This function does not return a value. - */ - -EXPORT_SPEC void -ixmlCDATASection_free(IXML_CDATASection *nodeptr - /** The {\bf CDATASection} node to free. */ - ); - -/*! @} */ - -/*================================================================ -* -* Document interfaces -* -* -*=================================================================*/ - -/**@name Interface {\it Document} - * The {\bf Document} interface represents the entire XML document. - * In essence, it is the root of the document tree and provides the - * primary interface to the elements of the document. For more information, - * refer to the {\it Interface Document} section in the DOM2Core. +/*! + * \brief Initializes a \b CDATASection node. */ -/*! @{ */ - - /** Initializes a {\bf Document} node. - * - * @return [void] This function does not return a value. - */ - -EXPORT_SPEC void -ixmlDocument_init(IXML_Document *nodeptr - /** The {\bf Document} node to initialize. */ - ); - - /** Creates a new empty {\bf Document} node. The - * {\bf ixmlDocument_createDocumentEx} API differs from the {\bf - * ixmlDocument_createDocument} API in that it returns an error code - * describing the reason for the failure rather than just {\tt NULL}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ - -EXPORT_SPEC int ixmlDocument_createDocumentEx(IXML_Document** doc - /** Pointer to a {\bf Document} where the - new object will be stored. */ - ); +EXPORT_SPEC void ixmlCDATASection_init( + /*! [in] The CDATA Section Node to iniatialize. */ + IXML_CDATASection *nodeptr); - /** Creates a new empty {\bf Document} node. - * - * @return [Document*] A pointer to the new {\bf Document} or {\tt NULL} on - * failure. - */ - -EXPORT_SPEC IXML_Document* ixmlDocument_createDocument(); - - /** Creates a new {\bf Element} node with the given tag name. The new - * {\bf Element} node has a {\tt nodeName} of {\bf tagName} and - * the {\tt localName}, {\tt prefix}, and {\tt namespaceURI} set - * to {\tt NULL}. To create an {\bf Element} with a namespace, - * see {\bf ixmlDocument_createElementNS}. - * - * The {\bf ixmlDocument_createElementEx} API differs from the {\bf - * ixmlDocument_createElement} API in that it returns an error code - * describing the reason for failure rather than just {\tt NULL}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf doc} or - * {\bf tagName} is {\tt NULL}. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ - -EXPORT_SPEC int -ixmlDocument_createElementEx(IXML_Document *doc, - /** The owner {\bf Document} of the new node. */ - const DOMString tagName, - /** The tag name of the new {\bf Element} - node. */ - IXML_Element **rtElement - /** Pointer to an {\bf Element} where the new - object will be stored. */ - ); - - /** Creates a new {\bf Element} node with the given tag name. The new - * {\bf Element} node has a {\tt nodeName} of {\bf tagName} and - * the {\tt localName}, {\tt prefix}, and {\tt namespaceURI} set - * to {\tt NULL}. To create an {\bf Element} with a namespace, - * see {\bf ixmlDocument_createElementNS}. - * - * @return [Document*] A pointer to the new {\bf Element} or {\tt NULL} on - * failure. - */ - -EXPORT_SPEC IXML_Element* -ixmlDocument_createElement(IXML_Document *doc, - /** The owner {\bf Document} of the new node. */ - const DOMString tagName - /** The tag name of the new {\bf Element} node. */ - ); +/*! + * \brief Frees a \b CDATASection node. + */ +EXPORT_SPEC void ixmlCDATASection_free( + /*! The \b CDATASection node to free. */ + IXML_CDATASection *nodeptr); - /** Creates a new {\bf Text} node with the given data. - * The {\bf ixmlDocument_createTextNodeEx} API differs from the {\bf - * ixmlDocument_createTextNode} API in that it returns an error code - * describing the reason for failure rather than just {\tt NULL}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf doc} or {\bf data} - * is {\tt NULL}. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ - -EXPORT_SPEC int -ixmlDocument_createTextNodeEx(IXML_Document *doc, - /** The owner {\bf Document} of the new node. */ - const DOMString data, - /** The data to associate with the new {\bf - Text} node. */ - IXML_Node** textNode - /** A pointer to a {\bf Node} where the new - object will be stored. */ - ); +/* @} Interface CDATASection */ - /** Creates a new {\bf Text} node with the given data. - * - * @return [Node*] A pointer to the new {\bf Node} or {\tt NULL} on failure. - */ -EXPORT_SPEC IXML_Node* -ixmlDocument_createTextNode(IXML_Document *doc, - /** The owner {\bf Document} of the new node. */ - const DOMString data - /** The data to associate with the new {\bf Text} - node. */ - ); - - /** Creates a new {\bf CDATASection} node with given data. - * - * The {\bf ixmlDocument_createCDATASectionEx} API differs from the {\bf - * ixmlDocument_createCDATASection} API in that it returns an error code - * describing the reason for failure rather than just {\tt NULL}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf doc} or {\bd data} - * is {\tt NULL}. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ - -EXPORT_SPEC int -ixmlDocument_createCDATASectionEx(IXML_Document *doc, - /** The owner {\bf Document} of the new - node. */ - const DOMString data, - /** The data to associate with the new - {\bf CDATASection} node. */ - IXML_CDATASection** cdNode - /** A pointer to a {\bf Node} where the - new object will be stored. */ - ); +/*! + * \name Interface Document + * + * The \b Document interface represents the entire XML document. In essence, it + * is the root of the document tree and provides the primary interface to the + * elements of the document. + * + * For more information, refer to the Interface Document section in + * the DOM2Core. + * + * @{ + */ - /** Creates a new {\bf CDATASection} node with given data. - * - * @return [CDATASection*] A pointer to the new {\bf CDATASection} or - * {\tt NULL} on failure. - */ - -EXPORT_SPEC IXML_CDATASection* -ixmlDocument_createCDATASection(IXML_Document *doc, - /** The owner {\bf Document} of the new - node. */ - const DOMString data - /** The data to associate with the new {\bf - CDATASection} node. */ - ); - - /** Creates a new {\bf Attr} node with the given name. - * - * @return [Attr*] A pointer to the new {\bf Attr} or {\tt NULL} on failure. - */ - -EXPORT_SPEC IXML_Attr* -ixmlDocument_createAttribute(IXML_Document *doc, - /** The owner {\bf Document} of the new node. */ - const char *name - /** The name of the new attribute. */ - ); +/*! + * \brief Initializes a \b Document node. + */ +EXPORT_SPEC void ixmlDocument_init( + /*! [in] The \b Document node to initialize. */ + IXML_Document *nodeptr); - /** Creates a new {\bf Attr} node with the given name. - * - * The {\bf ixmlDocument_createAttributeEx} API differs from the {\bf - * ixmlDocument_createAttribute} API in that it returns an error code - * describing the reason for failure rather than just {\tt NULL}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf doc} or {\bf name} - * is {\tt NULL}. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ - -EXPORT_SPEC int -ixmlDocument_createAttributeEx(IXML_Document *doc, - /** The owner {\bf Document} of the new - node. */ - const char *name, - /** The name of the new attribute. */ - IXML_Attr** attrNode - /** A pointer to a {\bf Attr} where the new - object will be stored. */ - ); +/*! + * \brief Creates a new empty \b Document node. + * + * The \b ixmlDocument_createDocumentEx API differs from the + * \b ixmlDocument_createDocument API in that it returns an error code + * describing the reason for the failure rather than just \c NULL. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete this operation. + */ +EXPORT_SPEC int ixmlDocument_createDocumentEx( + /*! [out] Pointer to a \b Document where the new object will be stored. */ + IXML_Document **doc); - /** Returns a {\bf NodeList} of all {\bf Elements} that match the given - * tag name in the order in which they were encountered in a preorder - * traversal of the {\bf Document} tree. - * - * @return [NodeList*] A pointer to a {\bf NodeList} containing the - * matching items or {\tt NULL} on an error. - */ - -EXPORT_SPEC IXML_NodeList* -ixmlDocument_getElementsByTagName(IXML_Document *doc, - /** The {\bf Document} to search. */ - const DOMString tagName - /** The tag name to find. */ - ); - -/* introduced in DOM level 2 */ - - /** Creates a new {\bf Element} node in the given qualified name and - * namespace URI. - * - * The {\bf ixmlDocument_createElementNSEx} API differs from the {\bf - * ixmlDocument_createElementNS} API in that it returns an error code - * describing the reason for failure rather than just {\tt NULL}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf doc}, - * {\bf namespaceURI}, or {\bf qualifiedName} is {\tt NULL}. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ - -EXPORT_SPEC int -ixmlDocument_createElementNSEx(IXML_Document *doc, - /** The owner {\bf Document} of the new - node. */ - const DOMString namespaceURI, - /** The namespace URI for the new {\bf - Element}. */ - const DOMString qualifiedName, - /** The qualified name of the new {\bf - Element}. */ - IXML_Element** rtElement - /** A pointer to an {\bf Element} where the - new object will be stored. */ - ); +/*! + * \brief Creates a new empty \b Document node. + * + * \return A pointer to the new \b Document object with the nodeName set to + * "#document" or \c NULL on failure. + */ +EXPORT_SPEC IXML_Document *ixmlDocument_createDocument(); - /** Creates a new {\bf Element} node in the given qualified name and - * namespace URI. - * - * @return [Element*] A pointer to the new {\bf Element} or {\tt NULL} on - * failure. - */ +/*! + * \brief Creates a new \b Element node with the given tag name. + * + * The new \b Element node has a \c nodeName of \b tagName and the + * \c localName, \c prefix, and \c namespaceURI set to \c NULL. To create an + * \b Element with a namespace, see \b ixmlDocument_createElementNS. + * + * The \b ixmlDocument_createElementEx API differs from the \b + * ixmlDocument_createElement API in that it returns an error code + * describing the reason for failure rather than just \c NULL. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b doc or + * \b tagName is \c NULL. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete this operation. + */ +EXPORT_SPEC int ixmlDocument_createElementEx( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The tag name of the new \b Element node. */ + const DOMString tagName, + /*! [out] Pointer to an \b Element where the new object will be stored. */ + IXML_Element **rtElement); -EXPORT_SPEC IXML_Element* -ixmlDocument_createElementNS(IXML_Document *doc, - /** The owner {\bf Document} of the new node. */ - const DOMString namespaceURI, - /** The namespace URI for the new {\bf - Element}. */ - const DOMString qualifiedName - /** The qualified name of the new {\bf - Element}. */ - ); - /** Creates a new {\bf Attr} node with the given qualified name and - * namespace URI. - * - * The {\bf ixmlDocument_createAttributeNSEx} API differs from the {\bf - * ixmlDocument_createAttributeNS} API in that it returns an error code - * describing the reason for failure rather than just {\tt NULL}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf doc}, - * {\bf namespaceURI}, or {\bf qualifiedName} is {\tt NULL}. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ +/*! + * \brief Creates a new \b Element node with the given tag name. + * + * The new \b Element node has a \c nodeName of \b tagName and the + * \c localName, \c prefix, and \c namespaceURI set to \c NULL. To create an + * \b Element with a namespace, see \b ixmlDocument_createElementNS. + * + * \return A pointer to the new \b Element object with the node name set to + * tagName, and localName, prefix and namespaceURI set to \c NULL, or \c NULL + * on failure. + */ +EXPORT_SPEC IXML_Element *ixmlDocument_createElement( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The tag name of the new \b Element node (case-sensitive). */ + const DOMString tagName); -EXPORT_SPEC int -ixmlDocument_createAttributeNSEx(IXML_Document *doc, - /** The owner {\bf Document} of the new - {\bf Attr}. */ - const DOMString namespaceURI, - /** The namespace URI for the attribute. */ - const DOMString qualifiedName, - /** The qualified name of the attribute. */ - IXML_Attr** attrNode - /** A pointer to an {\bf Attr} where the - new object will be stored. */ - ); - /** Creates a new {\bf Attr} node with the given qualified name and - * namespace URI. - * - * @return [Attr*] A pointer to the new {\bf Attr} or {\tt NULL} on failure. - */ +/*! + * \brief Creates a new \b Text node with the given data. + * + * The \b ixmlDocument_createTextNodeEx() API differs from the + * \b ixmlDocument_createTextNode API in that it returns an error code + * describing the reason for failure rather than just \c NULL. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b doc or \b data + * is \c NULL. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete this operation. + */ +EXPORT_SPEC int ixmlDocument_createTextNodeEx( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The data to associate with the new \b Text node. + * It is stored in nodeValue field.*/ + const DOMString data, + /*! [out] A pointer to a \b Node where the new object will be stored. */ + IXML_Node **textNode); -EXPORT_SPEC IXML_Attr* -ixmlDocument_createAttributeNS(IXML_Document *doc, - /** The owner {\bf Document} of the new - {\bf Attr}. */ - const DOMString namespaceURI, - /** The namespace URI for the attribute. */ - const DOMString qualifiedName - /** The qualified name of the attribute. */ - ); - /** Returns a {\bf NodeList} of {\bf Elements} that match the given - * local name and namespace URI in the order they are encountered - * in a preorder traversal of the {\bf Document} tree. Either - * {\bf namespaceURI} or {\bf localName} can be the special {\tt "*"} - * character, which matches any namespace or any local name respectively. - * - * @return [NodeList*] A pointer to a {\bf NodeList} containing the - * matching items or {\tt NULL} on an error. - */ +/*! + * \brief Creates a new \b Text node with the given data. + * + * \return A pointer to the new \b Node or \c NULL on failure. + */ +EXPORT_SPEC IXML_Node *ixmlDocument_createTextNode( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The data to associate with the new \b Text node. It is stored in + * the nodeValue field. */ + const DOMString data); -EXPORT_SPEC IXML_NodeList* -ixmlDocument_getElementsByTagNameNS(IXML_Document* doc, - /** The {\bf Document} to search. */ - const DOMString namespaceURI, - /** The namespace of the elements to - find or {\tt "*"} to match any - namespace. */ - const DOMString localName - /** The local name of the elements to - find or {\tt "*"} to match any local - name. */ - ); - /** Returns the {\bf Element} whose {\tt ID} matches that given id. - * - * @return [Element*] A pointer to the matching {\bf Element} or - * {\tt NULL} on an error. - */ +/*! + * \brief Creates a new \b CDATASection node with given data. + * + * The \b ixmlDocument_createCDATASectionEx API differs from the \b + * ixmlDocument_createCDATASection API in that it returns an error code + * describing the reason for failure rather than just \c NULL. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b doc or \b data + * is \c NULL. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete this operation. + */ +EXPORT_SPEC int ixmlDocument_createCDATASectionEx( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The data to associate with the new \b CDATASection node. */ + const DOMString data, + /*! [out] A pointer to a \b Node where the new object will be stored. */ + IXML_CDATASection** cdNode); -EXPORT_SPEC IXML_Element* -ixmlDocument_getElementById(IXML_Document* doc, - /** The owner {\bf Document} of the {\bf - Element}. */ - const DOMString tagName - /** The name of the {\bf Element}.*/ - ); - /** Frees a {\bf Document} object and all {\bf Node}s associated with it. - * Any {\bf Node}s extracted via any other interface function, e.g. - * {\bf ixmlDocument_GetElementById}, become invalid after this call unless - * explicitly cloned. - * - * @return [void] This function does not return a value. - */ +/*! + * \brief Creates a new \b CDATASection node with given data. + * + * \return A pointer to the new \b CDATASection or \c NULL on failure. + */ +EXPORT_SPEC IXML_CDATASection *ixmlDocument_createCDATASection( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The data to associate with the new \b CDATASection node. */ + const DOMString data); -EXPORT_SPEC void -ixmlDocument_free(IXML_Document* doc - /** The {\bf Document} to free. */ - ); - /** Imports a {\bf Node} from another {\bf Document} into this - * {\bf Document}. The new {\bf Node} does not a have parent node: it is a - * clone of the original {\bf Node} with the {\tt ownerDocument} set to - * {\bf doc}. The {\bf deep} parameter controls whether all the children - * of the {\bf Node} are imported. Refer to the DOM2-Core recommendation - * for details on importing specific node types. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf doc} or - * {\bf importNode} is not a valid pointer. - * \item {\tt IXML_NOT_SUPPORTED_ERR}: {\bf importNode} is a - * {\bf Document}, which cannot be imported. - * \item {\tt IXML_FAILED}: The import operation failed because the - * {\bf Node} to be imported could not be cloned. - * \end{itemize} - */ +/*! + * \brief Creates a new \b Attr node with the given name. + * + * \return A pointer to the new \b Attr object with the nodeName attribute + * set to the given name, and the localName, prefix and namespaceURI set + * to NULL or \c NULL on failure. + * + * The value of the attribute is the empty string. + */ +EXPORT_SPEC IXML_Attr *ixmlDocument_createAttribute( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The name of the new attribute. */ + const char *name); -EXPORT_SPEC int -ixmlDocument_importNode(IXML_Document* doc, - /** The {\bf Document} into which to import. */ - IXML_Node* importNode, - /** The {\bf Node} to import. */ - BOOL deep, - /** {\tt TRUE} to import all children of {\bf - importNode} or {\tt FALSE} to import only the - root node. */ - IXML_Node** rtNode - /** A pointer to a new {\bf Node} owned by {\bf - doc}. */ - ); -/*! @} */ -/*================================================================ -* -* Element interfaces -* -* -*=================================================================*/ +/*! + * \brief Creates a new \b Attr node with the given name. + * + * The \b ixmlDocument_createAttributeEx API differs from the \b + * ixmlDocument_createAttribute API in that it returns an error code + * describing the reason for failure rather than just \c NULL. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b doc or \b name + * is \c NULL. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete this operation. + */ +EXPORT_SPEC int ixmlDocument_createAttributeEx( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The name of the new attribute. */ + const char *name, + /*! [out] A pointer to a \b Attr where the new object will be stored. */ + IXML_Attr **attrNode); -/**@name Interface {\it Element} - * The {\bf Element} interface represents an element in an XML document. - * Only {\bf Element}s are allowed to have attributes, which are stored in the - * {\tt attributes} member of a {\bf Node}. The {\bf Element} interface - * extends the {\bf Node} interface and adds more operations to manipulate + +/*! + * \brief Returns a \b NodeList of all \b Elements that match the given + * tag name in the order in which they were encountered in a preorder + * traversal of the \b Document tree. + * + * \return A pointer to a \b NodeList containing the matching items or \c NULL + * on an error. + */ +EXPORT_SPEC IXML_NodeList *ixmlDocument_getElementsByTagName( + /*! [in] The \b Document to search. */ + IXML_Document *doc, + /*! [in] The tag name to find. The special value "*" matches all tags.*/ + const DOMString tagName); + + +/* + * introduced in DOM level 2 + */ + + +/*! + * \brief Creates a new \b Element node in the given qualified name and + * namespace URI. + * + * The \b ixmlDocument_createElementNSEx API differs from the \b + * ixmlDocument_createElementNS API in that it returns an error code + * describing the reason for failure rather than just \c NULL. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b doc, + * \b namespaceURI, or \b qualifiedName is \c NULL. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete this operation. + */ +EXPORT_SPEC int ixmlDocument_createElementNSEx( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The namespace URI for the new \b Element. */ + const DOMString namespaceURI, + /*! [in] The qualified name of the new \b Element. */ + const DOMString qualifiedName, + /*! [out] A pointer to an \b Element where the new object will be stored. */ + IXML_Element **rtElement); + + +/*! + * \brief Creates a new \b Element node in the given qualified name and + * namespace URI. + * + * \return A pointer to the new \b Element object with tagName qualifiedName, + * prefix and localName extraced from qualfiedName, nodeName of qualfiedName, + * namespaceURI of namespaceURI or \c NULL on failure. + */ +EXPORT_SPEC IXML_Element *ixmlDocument_createElementNS( + /*! [in] The owner \b Document of the new node. */ + IXML_Document *doc, + /*! [in] The namespace URI for the new \b Element. */ + const DOMString namespaceURI, + /*! [in] The qualified name of the new \b Element. */ + const DOMString qualifiedName); + + +/*! + * \brief Creates a new \b Attr node with the given qualified name and + * namespace URI. + * + * The \b ixmlDocument_createAttributeNSEx API differs from the \b + * ixmlDocument_createAttributeNS API in that it returns an error code + * describing the reason for failure rather than just \c NULL. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b doc, + * \b namespaceURI, or \b qualifiedName is \c NULL. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete this operation. + */ +EXPORT_SPEC int ixmlDocument_createAttributeNSEx( + /*! [in] The owner \b Document of the new \b Attr. */ + IXML_Document *doc, + /*! [in] The namespace URI for the attribute. */ + const DOMString namespaceURI, + /*! [in] The qualified name of the attribute. */ + const DOMString qualifiedName, + /*! [out] A pointer to an \b Attr where the new object will be stored. */ + IXML_Attr **attrNode); + + +/*! + * \brief Creates a new \b Attribute node with the given qualified name and + * namespace URI. + * + * \return A pointer to the new \b Attr node with the given namespaceURI and + * qualifiedName. The prefix and localname are extracted from + * the qualifiedName. The node value is empty. Or \c NULL on failure. + */ +EXPORT_SPEC IXML_Attr *ixmlDocument_createAttributeNS( + /*! [in] The owner \b Document of the new \b Attribute. */ + IXML_Document *doc, + /*! [in] The namespace URI for the attribute. */ + const DOMString namespaceURI, + /*! [in] The qualified name of the attribute. */ + const DOMString qualifiedName); + + +/*! + * \brief Returns a \b NodeList of \b Elements that match the given + * local name and namespace URI in the order they are encountered + * in a preorder traversal of the \b Document tree. + * + * Either \b namespaceURI or \b localName can be the special "*" + * character, which matches any namespace or any local name respectively. + * + * \return A pointer to a \b NodeList containing the matching items or \c NULL + * on an error. + */ +EXPORT_SPEC IXML_NodeList *ixmlDocument_getElementsByTagNameNS( + /*! [in] The \b Document to search. */ + IXML_Document *doc, + /*! [in] The namespace of the elements to find or "*" to match any + * namespace. */ + const DOMString namespaceURI, + /*! [in] The local name of the elements to find or "*" to match any + * local name. */ + const DOMString localName); + + +/*! + * \brief Returns the \b Element whose \c ID matches that given id. + * + * \return A pointer to the matching \b Element or \c NULL on an error. + */ +EXPORT_SPEC IXML_Element *ixmlDocument_getElementById( + /*! [in] The owner \b Document of the \b Element. */ + IXML_Document *doc, + /*! [in] The name of the \b Element.*/ + const DOMString tagName); + + +/*! + * \brief Frees a \b Document object and all \b Nodes associated with it. + * + * Any \b Nodes extracted via any other interface function, e.g. + * \b ixmlDocument_GetElementById, become invalid after this call unless + * explicitly cloned. + */ +EXPORT_SPEC void ixmlDocument_free( + /*! [in] The \b Document to free. */ + IXML_Document *doc); + + +/*! + * \brief Imports a \b Node from another \b Document into this \b Document. + * + * The returned new \b Node does not a have parent node (parentNode is null): + * it is a clone of the original \b Node with the \c ownerDocument set to + * \b doc. The source node is not altered or removed from the original + * document. + * + * For all nodes, importing a node creates a node object owned by the + * importing document, with attribute values identical to the source + * node's nodeName and nodeType, plus the attributes related to namespaces + * (prefix, localName, and namespaceURI). + * + * As in the cloneNode operation on a node, the source node is not altered. + * + * The \b deep parameter controls whether all the children of the \b Node are + * imported. + * + * Refer to the DOM2-Core recommendation for details on importing specific + * node types. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b doc or + * \b importNode is not a valid pointer. + * \li \c IXML_NOT_SUPPORTED_ERR: \b importNode is a + * \b Document, which cannot be imported. + * \li \c IXML_FAILED: The import operation failed because the + * \b Node to be imported could not be cloned. + */ +EXPORT_SPEC int ixmlDocument_importNode( + /*! [in] The \b Document into which to import. */ + IXML_Document *doc, + /*! [in] The \b Node to import. */ + IXML_Node * importNode, + /*! [in] \c TRUE to import all children of \b importNode or \c FALSE to + * import only the root node. */ + BOOL deep, + /*! [out] A pointer to a new \b Node owned by \b doc. */ + IXML_Node **rtNode); + + +/* @} Interface Document */ + + + + +/*! + * \name Interface Element + * + * The \b Element interface represents an element in an XML document. + * Only \b Elements are allowed to have attributes, which are stored in the + * \c attributes member of a \b Node. The \b Element interface + * extends the \b Node interface and adds more operations to manipulate * attributes. + * + * @{ */ -/*! @{ */ - - /** Initializes a {\bf IXML_Element} node. - * - * @return [void] This function does not return a value. - */ - -EXPORT_SPEC void ixmlElement_init(IXML_Element *element - /** The {\bf Element} to initialize.*/ - ); - /** Returns the name of the tag as a constant string. - * - * @return [const DOMString] A {\bf DOMString} representing the name of the - * {\bf Element}. - */ +/*! + * \brief Initializes a \b IXML_Element node. + */ +EXPORT_SPEC void ixmlElement_init( + /*! [in] The \b Element to initialize.*/ + IXML_Element *element); -EXPORT_SPEC const DOMString -ixmlElement_getTagName(IXML_Element* element - /** The {\bf Element} from which to retrieve the - name. */ - ); - /** Retrieves an attribute of an {\bf Element} by name. - * - * @return [DOMString] A {\bf DOMString} representing the value of the - * attribute. - */ +/*! + * \brief Returns the name of the tag as a constant string. + * + * \return The name of the \b Element. + */ +EXPORT_SPEC const DOMString ixmlElement_getTagName( + /*! [in] The \b Element from which to retrieve the name. */ + IXML_Element *element); -EXPORT_SPEC const DOMString -ixmlElement_getAttribute(IXML_Element* element, - /** The {\bf Element} from which to retrieve the - attribute. */ - const DOMString name - /** The name of the attribute to retrieve. */ - ); - /** Adds a new attribute to an {\bf Element}. If an attribute with the same - * name already exists, the attribute value will be updated with the - * new value in {\bf value}. - * - * @return [int] An integer representing of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf element}, - * {\bf name}, or {\bf value} is {\tt NULL}. - * \item {\tt IXML_INVALID_CHARACTER_ERR}: {\bf name} contains an - * illegal character. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete the operation. - * \end{itemize} - */ +/*! + * \brief Retrieves an attribute of an \b Element by name. + * + * \return The value of the attribute, or \b NULL if that attribute +* does not have a specified value. + */ +EXPORT_SPEC const DOMString ixmlElement_getAttribute( + /*! [in] The \b Element from which to retrieve the attribute. */ + IXML_Element* element, + /*! [in] The name of the attribute to retrieve. */ + const DOMString name); -EXPORT_SPEC int -ixmlElement_setAttribute(IXML_Element* element, - /** The {\bf Element} on which to set the - attribute. */ - const DOMString name, - /** The name of the attribute. */ - const DOMString value - /** The value of the attribute. Note that this is - a non-parsed string and any markup must be - escaped. */ - ); - /** Removes an attribute by name. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf element} or - * {\bf name} is {\tt NULL}. - * \end{itemize} - */ +/*! + * \brief Adds a new attribute to an \b Element. + * + * If an attribute with the same name already exists in the element, the + * attribute value will be updated with the new value parameter. Otherwise, + * a new attribute is inserted into the element. + * + * \return An integer representing of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b element, + * \b name, or \b value is \c NULL. + * \li \c IXML_INVALID_CHARACTER_ERR: \b name contains an + * illegal character. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete the operation. + */ +EXPORT_SPEC int ixmlElement_setAttribute( + /*! [in] The \b Element on which to set the attribute. */ + IXML_Element *element, + /*! [in] The name of the attribute. */ + const DOMString name, + /*! [in] The value of the attribute. Note that this is a non-parsed string + * and any markup must be escaped. */ + const DOMString value); -EXPORT_SPEC int -ixmlElement_removeAttribute(IXML_Element* element, - /** The {\bf Element} from which to remove the - attribute. */ - const DOMString name - /** The name of the attribute to remove. */ - ); - /** Retrieves an attribute node by name. See - * {\bf ixmlElement_getAttributeNodeNS} to retrieve an attribute node using - * a qualified name or namespace URI. - * - * @return [Attr*] A pointer to the attribute matching {\bf name} or - * {\tt NULL} on an error. - */ +/*! + * \brief Removes an attribute value by name. The attribute node is not removed. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b element or + * \b name is \c NULL. + */ +EXPORT_SPEC int ixmlElement_removeAttribute( + /*! [in] The \b Element from which to remove the attribute. */ + IXML_Element *element, + /*! [in] The name of the attribute to remove. */ + const DOMString name); -EXPORT_SPEC IXML_Attr* -ixmlElement_getAttributeNode(IXML_Element* element, - /** The {\bf Element} from which to get the - attribute node. */ - const DOMString name - /** The name of the attribute node to find. */ - ); - /** Adds a new attribute node to an {\bf Element}. If an attribute already - * exists with {\bf newAttr} as a name, it will be replaced with the - * new one and the old one will be returned in {\bf rtAttr}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf element} or - * {\bf newAttr} is {\tt NULL}. - * \item {\tt IXML_WRONG_DOCUMENT_ERR}: {\bf newAttr} does not belong - * to the same one as {\bf element}. - * \item {\tt IXML_INUSE_ATTRIBUTE_ERR}: {\bf newAttr} is already - * an attribute of another {\bf Element}. - * \end{itemize} - */ +/*! + * \brief Retrieves an attribute node by name. + * See \b ixmlElement_getAttributeNodeNS to retrieve an attribute node using + * a qualified name or namespace URI. + * + * \return A pointer to the attribute matching \b name or \c NULL on if there + * is no such attribute. + */ +EXPORT_SPEC IXML_Attr *ixmlElement_getAttributeNode( + /*! [in] The \b Element from which to get the attribute node. */ + IXML_Element *element, + /*! [in] The name of the attribute node to find. */ + const DOMString name); -EXPORT_SPEC int -ixmlElement_setAttributeNode(IXML_Element* element, - /** The {\bf Element} in which to add the new - attribute. */ - IXML_Attr* newAttr, - /** The new {\bf Attr} to add. */ - IXML_Attr** rtAttr - /** A pointer to an {\bf Attr} where the old - {\bf Attr} will be stored. This will have - a {\tt NULL} if no prior node - existed. */ - ); - /** Removes the specified attribute node from an {\bf Element}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf element} or - * {\bf oldAttr} is {\tt NULL}. - * \item {\tt IXML_NOT_FOUND_ERR}: {\bf oldAttr} is not among the list - * attributes of {\bf element}. - * \end{itemize} - */ +/*! + * \brief Adds a new attribute node to an \b Element. + * + * If an attribute already exists with \b newAttr as a name, it will be + * replaced with the new one and the old one will be returned in \b rtAttr. + * + * \return If successfull, the replaced attribute node is returned in rtAttr, + * otherwise, \b NULL is returned in this pointer. The function return value + * is an integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b element or + * \b newAttr is \c NULL. + * \li \c IXML_WRONG_DOCUMENT_ERR: \b newAttr does not belong + * to the same one as \b element. + * \li \c IXML_INUSE_ATTRIBUTE_ERR: \b newAttr is already + * an attribute of another \b Element. + */ +EXPORT_SPEC int ixmlElement_setAttributeNode( + /*! [in] The \b Element in which to add the new attribute. */ + IXML_Element *element, + /*! [in] The new \b Attr to add. */ + IXML_Attr* newAttr, + /*! [out] A pointer to an \b Attr where the old \b Attr will be stored. + * This will have a \c NULL if no prior node existed. */ + IXML_Attr** rtAttr); -EXPORT_SPEC int -ixmlElement_removeAttributeNode(IXML_Element* element, - /** The {\bf Element} from which to remove - the attribute. */ - IXML_Attr* oldAttr, - /** The attribute to remove from the {\bf - Element}. */ - IXML_Attr** rtAttr - /** A pointer to an attribute in which to - place the removed attribute. */ - ); - /** Returns a {\bf NodeList} of all {\it descendant} {\bf Elements} with - * a given tag name, in the order in which they are encountered in a - * pre-order traversal of this {\bf Element} tree. - * - * @return [NodeList*] A {\bf NodeList} of the matching {\bf Element}s or - * {\tt NULL} on an error. - */ +/*! + * \brief Removes the specified attribute node from an \b Element. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b element or + * \b oldAttr is \c NULL. + * \li \c IXML_NOT_FOUND_ERR: \b oldAttr is not among the list + * attributes of \b element. + */ +EXPORT_SPEC int ixmlElement_removeAttributeNode( + /*! [in] The \b Element from which to remove the attribute. */ + IXML_Element *element, + /*! [in] The attribute to remove from the \b Element. */ + IXML_Attr* oldAttr, + /*! [out] A pointer to an attribute in which to place the removed attribute. */ + IXML_Attr** rtAttr); -EXPORT_SPEC IXML_NodeList* -ixmlElement_getElementsByTagName(IXML_Element* element, - /** The {\bf Element} from which to start - the search. */ - const DOMString tagName - /** The name of the tag for which to - search. */ - ); -/* introduced in DOM 2 */ +/*! + * \brief Returns a \b NodeList of all \em descendant \b Elements with + * a given tag name, in the order in which they are encountered in a + * pre-order traversal of this \b Element tree. + * + * \return A \b NodeList of the matching \b Elements or \c NULL on an error. + */ +EXPORT_SPEC IXML_NodeList *ixmlElement_getElementsByTagName( + /*! [in] The \b Element from which to start the search. */ + IXML_Element *element, + /*! [in] The name of the tag for which to search. */ + const DOMString tagName); - /** Retrieves an attribute value using the local name and namespace URI. - * - * @return [DOMString] A {\bf DOMString} representing the value of the - * matching attribute. - */ -EXPORT_SPEC const DOMString -ixmlElement_getAttributeNS(IXML_Element* element, - /** The {\bf Element} from which to get the - attribute value. */ - const DOMString namespaceURI, - /** The namespace URI of the attribute. */ - const DOMString localname - /** The local name of the attribute. */ - ); +/* + * Introduced in DOM 2 + */ - /** Adds a new attribute to an {\bf Element} using the local name and - * namespace URI. If another attribute matches the same local name and - * namespace, the prefix is changed to be the prefix part of the - * {\tt qualifiedName} and the value is changed to {\bf value}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf element}, - * {\bf namespaceURI}, {\bf qualifiedName}, or {\bf value} is - * {\tt NULL}. - * \item {\tt IXML_INVALID_CHARACTER_ERR}: {\bf qualifiedName} contains - * an invalid character. - * \item {\tt IXML_NAMESPACE_ERR}: Either the {\bf qualifiedName} or - * {\bf namespaceURI} is malformed. Refer to the DOM2-Core for - * possible reasons. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exist - * to complete the operation. - * \item {\tt IXML_FAILED}: The operation could not be completed. - * \end{itemize} - */ -EXPORT_SPEC int -ixmlElement_setAttributeNS(IXML_Element* element, - /** The {\bf Element} on which to set the - attribute. */ - const DOMString namespaceURI, - /** The namespace URI of the new attribute. */ - const DOMString qualifiedName, - /** The qualified name of the attribute. */ - const DOMString value - /** The new value for the attribute. */ - ); +/*! + * \brief Retrieves an attribute value using the local name and namespace URI. + * + * \return A \b DOMString representing the value of the matching attribute, or + * \b NULL if that attribute does not have the specified value. + */ +EXPORT_SPEC const DOMString ixmlElement_getAttributeNS( + /*! [in] The \b Element from which to get the attribute value. */ + IXML_Element *element, + /*! [in] The namespace URI of the attribute. */ + const DOMString namespaceURI, + /*! [in] The local name of the attribute. */ + const DOMString localname); - /** Removes an attribute using the namespace URI and local name. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf element}, - * {\bf namespaceURI}, or {\bf localName} is {\tt NULL}. - * \end{itemize} - */ -EXPORT_SPEC int -ixmlElement_removeAttributeNS(IXML_Element* element, - /** The {\bf Element} from which to remove the - the attribute. */ - const DOMString namespaceURI, - /** The namespace URI of the attribute. */ - const DOMString localName - /** The local name of the attribute.*/ - ); +/*! + * \brief Adds a new attribute to an \b Element using the local name and + * namespace URI. + * + * If another attribute matches the same local name and namespace, the prefix + * is changed to be the prefix part of the \c qualifiedName and the value is + * changed to \b value. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b element, + * \b namespaceURI, \b qualifiedName, or \b value is + * \c NULL. + * \li \c IXML_INVALID_CHARACTER_ERR: \b qualifiedName contains + * an invalid character. + * \li \c IXML_NAMESPACE_ERR: Either the \b qualifiedName or + * \b namespaceURI is malformed. Refer to the DOM2-Core for + * possible reasons. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exist + * to complete the operation. + * \li \c IXML_FAILED: The operation could not be completed. + */ +EXPORT_SPEC int ixmlElement_setAttributeNS( + /*! [in] The \b Element on which to set the attribute. */ + IXML_Element *element, + /*! [in] The namespace URI of the new attribute. */ + const DOMString namespaceURI, + /*! [in] The qualified name of the attribute. */ + const DOMString qualifiedName, + /*! [in] The new value for the attribute. */ + const DOMString value); - /** Retrieves an {\bf Attr} node by local name and namespace URI. - * - * @return [Attr*] A pointer to an {\bf Attr} or {\tt NULL} on an error. - */ -EXPORT_SPEC IXML_Attr* -ixmlElement_getAttributeNodeNS(IXML_Element* element, - /** The {\bf Element} from which to get the - attribute. */ - const DOMString namespaceURI, - /** The namespace URI of the attribute. */ - const DOMString localName - /** The local name of the attribute. */ - ); +/*! + * \brief Removes an attribute using the namespace URI and local name. + * + * The replacing attribute has the same namespace URI and local name, as well + * as the original prefix. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b element, + * \b namespaceURI, or \b localName is \c NULL. + */ +EXPORT_SPEC int ixmlElement_removeAttributeNS( + /*! [in] The \b Element from which to remove the the attribute. */ + IXML_Element *element, + /*! [in] The namespace URI of the attribute. */ + const DOMString namespaceURI, + /*! [in] The local name of the attribute.*/ + const DOMString localName); - /** Adds a new attribute node. If an attribute with the same local name - * and namespace URI already exists in the {\bf Element}, the existing - * attribute node is replaced with {\bf newAttr} and the old returned in - * {\bf rcAttr}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: Either {\bf element} or - * {\bf newAttr} is {\tt NULL}. - * \item {\tt IXML_WRONG_DOCUMENT_ERR}: {\bf newAttr} does not belong - * to the same document as {\bf element}. - * \item {\tt IXML_INUSE_ATTRIBUTE_ERR}: {\bf newAttr} already is an - * attribute of another {\bf Element}. - * \end{itemize} - */ -EXPORT_SPEC int -ixmlElement_setAttributeNodeNS(IXML_Element* element, - /** The {\bf Element} in which to add the - attribute node. */ - IXML_Attr* newAttr, - /** The new {\bf Attr} to add. */ - IXML_Attr** rcAttr - /** A pointer to the replaced {\bf Attr}, if - it exists. */ - ); +/*! + * \brief Retrieves an \b Attr node by local name and namespace URI. + * + * \return A pointer to an \b Attribute node with the specified attribute + * local name and namespace URI or \c NULL if there is no such attribute. + */ +EXPORT_SPEC IXML_Attr *ixmlElement_getAttributeNodeNS( + /*! [in] The \b Element from which to get the attribute. */ + IXML_Element *element, + /*! [in] The namespace URI of the attribute. */ + const DOMString namespaceURI, + /*! [in] The local name of the attribute. */ + const DOMString localName); - /** Returns a {\bf NodeList} of all {\it descendant} {\bf Elements} with a - * given tag name, in the order in which they are encountered in the - * pre-order traversal of the {\bf Element} tree. - * - * @return [NodeList*] A {\bf NodeList} of matching {\bf Element}s or - * {\tt NULL} on an error. - */ -EXPORT_SPEC IXML_NodeList* -ixmlElement_getElementsByTagNameNS(IXML_Element* element, - /** The {\bf Element} from which to start - the search. */ - const DOMString namespaceURI, - /** The namespace URI of the {\bf - Element}s to find. */ - const DOMString localName - /** The local name of the {\bf Element}s - to find. */ - ); +/*! + * \brief Adds a new attribute node to the element node specified. + * + * If an attribute with the same local name and namespace URI already exists in + * the \b Element, the existing attribute node is replaced with \b newAttr and + * the old returned in \b rcAttr. + * + * \return The output parameter rcAttr receives the replaced attribute node if + * the newAttr attribute replaces an existing attribute with the same local name + * and namespace, otherwise rcAttr receives \b NULL. + * + * The function return value is an integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: Either \b element or + * \b newAttr is \c NULL. + * \li \c IXML_WRONG_DOCUMENT_ERR: \b newAttr does not belong + * to the same document as \b element. + * \li \c IXML_INUSE_ATTRIBUTE_ERR: \b newAttr already is an + * attribute of another \b Element. + */ +EXPORT_SPEC int ixmlElement_setAttributeNodeNS( + /*! [in] The \b Element in which to add the attribute node. */ + IXML_Element *element, + /*! [in] The new \b Attr to add. */ + IXML_Attr *newAttr, + /*! [out] A pointer to the replaced \b Attr, if it exists. */ + IXML_Attr **rcAttr); - /** Queries whether the {\bf Element} has an attribute with the given name - * or a default value. - * - * @return [BOOL] {\tt TRUE} if the {\bf Element} has an attribute with - * this name or has a default value for that attribute, - * otherwise {\tt FALSE}. - */ -EXPORT_SPEC BOOL -ixmlElement_hasAttribute(IXML_Element* element, - /** The {\bf Element} on which to check for an - attribute. */ - const DOMString name - /** The name of the attribute for which to check. */ - ); +/*! + * \brief Returns a \b NodeList of all \em descendant \b Elements with a + * given local name and namespace in the order in which they are encountered in + * the pre-order traversal of the \b Element tree. + * + * \return A \b NodeList of matching \b Elements or \c NULL on an error. + */ +EXPORT_SPEC IXML_NodeList *ixmlElement_getElementsByTagNameNS( + /*! [in] The \b Element from which to start the search. */ + IXML_Element *element, + /*! [in] The namespace URI of the \b Elements to find. The special value + * "*" matches all namespaces. */ + const DOMString namespaceURI, + /*! [in] The local name of the \b Elements to find. The special value "*" + * matches all local names. */ + const DOMString localName); - /** Queries whether the {\bf Element} has an attribute with the given - * local name and namespace URI or has a default value for that attribute. - * - * @return [BOOL] {\tt TRUE} if the {\bf Element} has an attribute with - * the given namespace and local name or has a default - * value for that attribute, otherwise {\tt FALSE}. - */ -EXPORT_SPEC BOOL -ixmlElement_hasAttributeNS(IXML_Element* element, - /** The {\bf Element} on which to check for the - attribute. */ - const DOMString namespaceURI, - /** The namespace URI of the attribute. */ - const DOMString localName - /** The local name of the attribute. */ - ); +/*! + * \brief Queries whether the \b Element has an attribute with the given name + * or a default value. + * + * \return \c TRUE if the \b Element has an attribute with this name or has a + * default value for that attribute, otherwise \c FALSE. + */ +EXPORT_SPEC BOOL ixmlElement_hasAttribute( + /*! [in] The \b Element on which to check for an attribute. */ + IXML_Element *element, + /*! [in] The name of the attribute for which to check. */ + const DOMString name); - /** Frees the given {\bf Element} and any subtree of the {\bf Element}. - * - * @return [void] This function does not return a value. - */ -EXPORT_SPEC void -ixmlElement_free(IXML_Element* element - /** The {\bf Element} to free. */ - ); +/*! + * \brief Queries whether the \b Element has an attribute with the given + * local name and namespace URI or has a default value for that attribute. + * + * \return \c TRUE if the \b Element has an attribute with the given namespace + * and local name or has a default value for that attribute, otherwise \c FALSE. + */ +EXPORT_SPEC BOOL ixmlElement_hasAttributeNS( + /*! [in] The \b Element on which to check for the attribute. */ + IXML_Element *element, + /*! [in] The namespace URI of the attribute. */ + const DOMString namespaceURI, + /*! [in] The local name of the attribute. */ + const DOMString localName); -/*! @} */ -/*================================================================ -* -* NamedNodeMap interfaces -* -* -*=================================================================*/ +/*! + * \brief Frees the given \b Element and any subtree of the \b Element. + */ +EXPORT_SPEC void ixmlElement_free( + /*! [in] The \b Element to free. */ + IXML_Element *element); -/**@name Interface {\it NamedNodeMap} - * A {\bf NamedNodeMap} object represents a list of objects that can be - * accessed by name. A {\bf NamedNodeMap} maintains the objects in - * no particular order. The {\bf Node} interface uses a {\bf NamedNodeMap} + +/* @} Interface Element */ + + + +/*! + * \name Interface NamedNodeMap + * + * A \b NamedNodeMap object represents a list of objects that can be + * accessed by name. A \b NamedNodeMap maintains the objects in + * no particular order. The \b Node interface uses a \b NamedNodeMap * to maintain the attributes of a node. + * + * @{ */ -/*! @{ */ - /** Returns the number of items contained in this {\bf NamedNodeMap}. - * - * @return [unsigned long] The number of nodes in this map. - */ -EXPORT_SPEC unsigned long -ixmlNamedNodeMap_getLength(IXML_NamedNodeMap *nnMap - /** The {\bf NamedNodeMap} from which to retrieve - the size. */ - ); +/*! + * \brief Returns the number of items contained in this \b NamedNodeMap. + * + * \return The number of nodes in this map. + */ +EXPORT_SPEC unsigned long ixmlNamedNodeMap_getLength( + /*! [in] The \b NamedNodeMap from which to retrieve the size. */ + IXML_NamedNodeMap *nnMap); - /** Retrieves a {\bf Node} from the {\bf NamedNodeMap} by name. - * - * @return [Node*] A {\bf Node} or {\tt NULL} if there is an error. - */ -EXPORT_SPEC IXML_Node* -ixmlNamedNodeMap_getNamedItem(IXML_NamedNodeMap *nnMap, - /** The {\bf NamedNodeMap} to search. */ - const DOMString name - /** The name of the {\bf Node} to find. */ - ); +/*! + * \brief Retrieves a \b Node from the \b NamedNodeMap by name. + * + * \return A Node with the specified nodeName, or \b NULL if it + * does not identify any node in this map. + */ +EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_getNamedItem( + /*! [in] The \b NamedNodeMap to search. */ + IXML_NamedNodeMap *nnMap, + /*! [in] The name of the \b Node to find. */ + const DOMString name); - /** Adds a new {\bf Node} to the {\bf NamedNodeMap} using the {\bf Node} - * name attribute. - * - * @return [Node*] The old {\bf Node} if the new {\bf Node} replaces it or - * {\tt NULL} if the {\bf Node} was not in the - * {\bf NamedNodeMap} before. - */ -EXPORT_SPEC IXML_Node* -ixmlNamedNodeMap_setNamedItem(IXML_NamedNodeMap *nnMap, - /** The {\bf NamedNodeMap} in which to add the - new {\bf Node}. */ - IXML_Node *arg - /** The new {\bf Node} to add to the {\bf - NamedNodeMap}. */ - ); +/*! + * \brief Adds a new \b Node to the \b NamedNodeMap using the \b Node name + * attribute. + * + * \return The old \b Node if the new \b Node replaces it or \c NULL if the + * \b Node was not in the \b NamedNodeMap before. + */ +EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_setNamedItem( + /*! The \b NamedNodeMap in which to add the new \b Node. */ + IXML_NamedNodeMap *nnMap, + /*! The new \b Node to add to the \b NamedNodeMap. */ + IXML_Node *arg); - /** Removes a {\bf Node} from a {\bf NamedNodeMap} specified by name. - * - * @return [Node*] A pointer to the {\bf Node}, if found, or {\tt NULL} if - * it wasn't. - */ -EXPORT_SPEC IXML_Node* -ixmlNamedNodeMap_removeNamedItem(IXML_NamedNodeMap *nnMap, - /** The {\bf NamedNodeMap} from which to - remove the item. */ - const DOMString name - /** The name of the item to remove. */ - ); +/*! + * \brief Removes a \b Node from a \b NamedNodeMap specified by name. + * + * \return A pointer to the \b Node, if found, or \c NULL if it wasn't. + */ +EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_removeNamedItem( + /*! The \b NamedNodeMap from which to remove the item. */ + IXML_NamedNodeMap *nnMap, + /*! The name of the item to remove. */ + const DOMString name); - /** Retrieves a {\bf Node} from a {\bf NamedNodeMap} specified by a - * numerical index. - * - * @return [Node*] A pointer to the {\bf Node}, if found, or {\tt NULL} if - * it wasn't. - */ -EXPORT_SPEC IXML_Node* -ixmlNamedNodeMap_item(IXML_NamedNodeMap *nnMap, - /** The {\bf NamedNodeMap} from which to remove the - {\bf Node}. */ - unsigned long index - /** The index into the map to remove. */ - ); +/*! + * \brief Retrieves the indexth item in the map. If index is greater than or + * equal to the number of nodes in this map, this returns \b NULL. + * + * \return The node at the indexth position in the map, or \b NULL if that is + * not a valid index. + */ +EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_item( + /*! [in] The \b NamedNodeMap from which to remove the \b Node. */ + IXML_NamedNodeMap *nnMap, + /*! [in] The index into the map to remove. */ + unsigned long index); -/* introduced in DOM level 2 */ - /** Retrieves a {\bf Node} from a {\bf NamedNodeMap} specified by - * namespace URI and local name. - * - * @return [Node*] A pointer to the {\bf Node}, if found, or {\tt NULL} if - * it wasn't - */ +/* + * Introduced in DOM level 2 + */ -EXPORT_SPEC IXML_Node* -ixmlNamedNodeMap_getNamedItemNS(IXML_NamedNodeMap *nnMap, - /** The {\bf NamedNodeMap} from which to - remove the {\bf Node}. */ - const DOMString *namespaceURI, - /** The namespace URI of the {\bf Node} to - remove. */ - const DOMString localName - /** The local name of the {\bf Node} to - remove. */ - ); - /** Adds a new {\bf Node} to the {\bf NamedNodeMap} using the {\bf Node} - * local name and namespace URI attributes. - * - * @return [Node*] The old {\bf Node} if the new {\bf Node} replaces it or - * {\tt NULL} if the {\bf Node} was not in the - * {\bf NamedNodeMap} before. - */ +/*! + * \brief Retrieves a \b Node from a \b NamedNodeMap specified by namespace + * URI and local name. + * + * \return A pointer to the \b Node, if found, or \c NULL if it wasn't + */ +EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_getNamedItemNS( + /*! The \b NamedNodeMap from which to remove the \b Node. */ + IXML_NamedNodeMap *nnMap, + /*! The namespace URI of the \b Node to remove. */ + const DOMString *namespaceURI, + /*! The local name of the \b Node to remove. */ + const DOMString localName); -EXPORT_SPEC IXML_Node* -ixmlNamedNodeMap_setNamedItemNS(IXML_NamedNodeMap *nnMap, - /** The {\bf NamedNodeMap} in which to add - the {\bf Node}. */ - IXML_Node *arg - /** The {\bf Node} to add to the map. */ - ); - /** Removes a {\bf Node} from a {\bf NamedNodeMap} specified by - * namespace URI and local name. - * - * @return [Node*] A pointer to the {\bf Node}, if found, or {\tt NULL} if - * it wasn't. - */ +/*! + * \brief Adds a new \b Node to the \b NamedNodeMap using the \b Node + * local name and namespace URI attributes. + * + * \return The old \b Node if the new \b Node replaces it or \c NULL if the + * \b Node was not in the \b NamedNodeMap before. + */ +EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_setNamedItemNS( + /*! The \b NamedNodeMap in which to add the \b Node. */ + IXML_NamedNodeMap *nnMap, + /*! The \b Node to add to the map. */ + IXML_Node *arg); -EXPORT_SPEC IXML_Node* -ixmlNamedNodeMap_removeNamedItemNS(IXML_NamedNodeMap *nnMap, - /** The {\bf NamedNodeMap} from which to - remove the {\bf Node}. */ - const DOMString namespaceURI, - /** The namespace URI of the {\bf Node} - to remove. */ - const DOMString localName - /** The local name of the {\bf Node} to - remove. */ - ); - /** Frees a {\bf NamedNodeMap}. The {\bf Node}s inside the map are not - * freed, just the {\bf NamedNodeMap} object. - * - * @return [void] This function does not return a value. - */ +/*! + * \brief Removes a \b Node from a \b NamedNodeMap specified by + * namespace URI and local name. + * + * \return A pointer to the \b Node, if found, or \c NULL if it wasn't. + */ +EXPORT_SPEC IXML_Node *ixmlNamedNodeMap_removeNamedItemNS( + /*! The \b NamedNodeMap from which to remove the \b Node. */ + IXML_NamedNodeMap *nnMap, + /*! The namespace URI of the \b Node to remove. */ + const DOMString namespaceURI, + /*! The local name of the \b Node to remove. */ + const DOMString localName); -EXPORT_SPEC void -ixmlNamedNodeMap_free(IXML_NamedNodeMap *nnMap - /** The {\bf NamedNodeMap to free}. */ - ); -/*! @} */ +/*! \brief Frees a \b NamedNodeMap. + * + * The \b Nodes inside the map are not freed, just the \b NamedNodeMap object. + */ +EXPORT_SPEC void ixmlNamedNodeMap_free( + /*! [in] The \b NamedNodeMap to free. */ + IXML_NamedNodeMap *nnMap); -/*================================================================ -* -* NodeList interfaces -* -* -*=================================================================*/ -/**@name Interface {\it NodeList} - * The {\bf NodeList} interface abstracts an ordered collection of +/* @} Interface NodeMap */ + + + +/*! + * \name Interface NodeList + * + * The \b NodeList interface abstracts an ordered collection of * nodes. Note that changes to the underlying nodes will change - * the nodes contained in a {\bf NodeList}. The DOM2-Core refers to - * this as being {\it live}. + * the nodes contained in a \b NodeList. The DOM2-Core refers to + * this as being \em live. + * + * @{ */ -/*! @{ */ - /** Retrieves a {\bf Node} from a {\bf NodeList} specified by a - * numerical index. - * - * @return [Node*] A pointer to a {\bf Node} or {\tt NULL} if there was an - * error. - */ -EXPORT_SPEC IXML_Node* -ixmlNodeList_item(IXML_NodeList *nList, - /** The {\bf NodeList} from which to retrieve the {\bf - Node}. */ - unsigned long index - /** The index into the {\bf NodeList} to retrieve. */ - ); +/*! + * \brief Retrieves a \b Node from a \b NodeList specified by a + * numerical index. + * + * \return A pointer to a \b Node or \c NULL if there was an error. + */ +EXPORT_SPEC IXML_Node *ixmlNodeList_item( + /*! [in] The \b NodeList from which to retrieve the \b Node. */ + IXML_NodeList *nList, + /*! [in] The index into the \b NodeList to retrieve. */ + unsigned long index); - /** Returns the number of {\bf Nodes} in a {\bf NodeList}. - * - * @return [unsigned long] The number of {\bf Nodes} in the {\bf NodeList}. - */ -EXPORT_SPEC unsigned long -ixmlNodeList_length(IXML_NodeList *nList - /** The {\bf NodeList} for which to retrieve the - number of {\bf Nodes}. */ - ); +/*! + * \brief Returns the number of \b Nodes in a \b NodeList. + * + * \return The number of \b Nodes in the \b NodeList. + */ +EXPORT_SPEC unsigned long ixmlNodeList_length( + /*! [in] The \b NodeList for which to retrieve the number of \b Nodes. */ + IXML_NodeList *nList); - /** Frees a {\bf NodeList} object. Since the underlying {\bf Nodes} are - * references, they are not freed using this operating. This only - * frees the {\bf NodeList} object. - * - * @return [void] This function does not return a value. - */ -EXPORT_SPEC void -ixmlNodeList_free(IXML_NodeList *nList - /** The {\bf NodeList} to free. */ - ); +/*! + * \brief Frees a \b NodeList object. + * + * Since the underlying \b Nodes are references, they are not freed using this + * operation. This only frees the \b NodeList object. + */ +EXPORT_SPEC void ixmlNodeList_free( + /*! [in] The \b NodeList to free. */ + IXML_NodeList *nList); -/*! @} */ /* Interface NodeList */ -/*! @} */ /* DOM Interfaces */ -/**@name IXML API +/* @} Interface NodeList */ + + + +/*! + * \name IXML API + * * The IXML API contains utility functions that are not part of the standard - * DOM interfaces. They include functions to create a DOM structure from a - * file or buffer, create an XML file from a DOM structure, and manipulate + * DOM interfaces. They include functions to create a DOM structure from a + * file or buffer, create an XML file from a DOM structure, and manipulate * DOMString objects. + * + * @{ */ -/*! @{ */ - -/*================================================================ -* -* ixml interfaces -* -* -*=================================================================*/ - - /** Renders a {\bf Node} and all sub-elements into an XML document - * representation. The caller is required to free the {\bf DOMString} - * returned from this function using {\bf ixmlFreeDOMString} when it - * is no longer required. - * - * Note that this function can be used for any {\bf Node}-derived - * interface. The difference between {\bf ixmlPrintDocument} and - * {\bf ixmlPrintNode} is {\bf ixmlPrintDocument} includes the XML prolog - * while {\bf ixmlPrintNode} only produces XML elements. An XML - * document is not well formed unless it includes the prolog - * and at least one element. - * - * This function introduces lots of white space to print the - * {\bf DOMString} in readable format. - * - * @return [DOMString] A {\bf DOMString} with the XML document representation - * of the DOM tree or {\tt NULL} on an error. - */ - -EXPORT_SPEC DOMString -ixmlPrintDocument(IXML_Document *doc); - - /** Renders a {\bf Node} and all sub-elements into an XML text - * representation. The caller is required to free the {\bf DOMString} - * returned from this function using {\bf ixmlFreeDOMString} when it - * is no longer required. - * - * Note that this function can be used for any {\bf Node}-derived - * interface. A similar {\bf ixmlPrintDocument} function is defined - * to avoid casting when printing whole documents. This function - * introduces lots of white space to print the {\bf DOMString} in readable - * format. - * - * @return [DOMString] A {\bf DOMString} with the XML text representation - * of the DOM tree or {\tt NULL} on an error. - */ - -EXPORT_SPEC DOMString -ixmlPrintNode(IXML_Node *doc - /** The root of the {\bf Node} tree to render to XML text. */ - ); - - /** Renders a {\bf Node} and all sub-elements into an XML document - * representation. The caller is required to free the {\bf DOMString} - * returned from this function using {\bf ixmlFreeDOMString} when it - * is no longer required. - * - * Note that this function can be used for any {\bf Node}-derived - * interface. The difference between {\bf ixmlDocumenttoString} and - * {\bf ixmlNodetoString} is {\bf ixmlDocumenttoString} includes the XML - * prolog while {\bf ixmlNodetoString} only produces XML elements. An XML - * document is not well formed unless it includes the prolog - * and at least one element. - * - * @return [DOMString] A {\bf DOMString} with the XML text representation - * of the DOM tree or {\tt NULL} on an error. - */ - -EXPORT_SPEC DOMString -ixmlDocumenttoString(IXML_Document *doc); - - /** Renders a {\bf Node} and all sub-elements into an XML text - * representation. The caller is required to free the {\bf DOMString} - * returned from this function using {\bf ixmlFreeDOMString} when it - * is no longer required. - * - * Note that this function can be used for any {\bf Node}-derived - * interface. The difference between {\bf ixmlNodetoString} and - * {\bf ixmlDocumenttoString} is {\bf ixmlNodetoString} does not include - * the XML prolog, it only produces XML elements. - * - * @return [DOMString] A {\bf DOMString} with the XML text representation - * of the DOM tree or {\tt NULL} on an error. - */ - -EXPORT_SPEC DOMString -ixmlNodetoString(IXML_Node *doc - /** The root of the {\bf Node} tree to render to XML text. */ - ); - /** Makes the XML parser more tolerant to malformed text. - * - * If {\bf errorChar} is 0 (default), the parser is strict about XML - * encoding : invalid UTF-8 sequences or "&" entities are rejected, and - * the parsing aborts. - * If {\bf errorChar} is not 0, the parser is relaxed : invalid UTF-8 - * characters are replaced by the {\bf errorChar}, and invalid "&" entities - * are left untranslated. The parsing is then allowed to continue. - */ -EXPORT_SPEC void -ixmlRelaxParser(char errorChar); +/*! + * \brief Renders a \b Node and all sub-elements into an XML document + * representation. + * + * The caller is required to free the \b DOMString + * returned from this function using \b ixmlFreeDOMString when it + * is no longer required. + * + * Note that this function can be used for any \b Node-derived + * interface. The difference between \b ixmlPrintDocument and + * \b ixmlPrintNode is \b ixmlPrintDocument includes the XML prolog + * while \b ixmlPrintNode only produces XML elements. An XML + * document is not well formed unless it includes the prolog + * and at least one element. + * + * This function introduces lots of white space to print the + * \b DOMString in readable format. + * + * \return A \b DOMString with the XML document representation + * of the DOM tree or \c NULL on an error. + */ +EXPORT_SPEC DOMString ixmlPrintDocument( + /*! [in] The document node to print. */ + IXML_Document *doc); - /** Parses an XML text buffer converting it into an IXML DOM representation. - * - * @return [Document*] A {\bf Document} if the buffer correctly parses or - * {\tt NULL} on an error. - */ -EXPORT_SPEC IXML_Document* -ixmlParseBuffer(const char *buffer - /** The buffer that contains the XML text to convert to a - {\bf Document}. */ - ); +/*! + * \brief Renders a \b Node and all sub-elements into an XML text + * representation. + * + * The caller is required to free the \b DOMString + * returned from this function using \b ixmlFreeDOMString when it + * is no longer required. + * + * Note that this function can be used for any \b Node-derived + * interface. A similar \b ixmlPrintDocument function is defined + * to avoid casting when printing whole documents. This function + * introduces lots of white space to print the \b DOMString in readable + * format. + * + * \return A \b DOMString with the XML text representation of the DOM tree or + * \c NULL on an error. + */ +EXPORT_SPEC DOMString ixmlPrintNode( + /*! [in] The root of the \b Node tree to render to XML text. */ + IXML_Node *doc +); - /** Parses an XML text buffer converting it into an IXML DOM representation. - * - * The {\bf ixmlParseBufferEx} API differs from the {\bf ixmlParseBuffer} - * API in that it returns an error code representing the actual failure - * rather than just {\tt NULL}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: The {\bf buffer} is not a valid - * pointer. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ +/*! + * \brief Renders a \b Node and all sub-elements into an XML document + * representation. + * + * The caller is required to free the \b DOMString + * returned from this function using \b ixmlFreeDOMString when it + * is no longer required. + * + * Note that this function can be used for any \b Node-derived + * interface. The difference between \b ixmlDocumenttoString and + * \b ixmlNodetoString is \b ixmlDocumenttoString includes the XML + * prolog while \b ixmlNodetoString only produces XML elements. An XML + * document is not well formed unless it includes the prolog + * and at least one element. + * + * \return A \b DOMString with the XML text representation of the DOM tree or + * \c NULL on an error. + */ +EXPORT_SPEC DOMString ixmlDocumenttoString( + /*! [in] The root of the \b Node tree to render to XML text. */ + IXML_Document *doc); -EXPORT_SPEC int -ixmlParseBufferEx(const char *buffer, - /** The buffer that contains the XML text to convert to a - {\bf Document}. */ - IXML_Document** doc - /** A point to store the {\bf Document} if file correctly - parses or {\bf NULL} on an error. */ - ); - /** Parses an XML text file converting it into an IXML DOM representation. - * - * @return [Document*] A {\bf Document} if the file correctly parses or - * {\tt NULL} on an error. - */ +/*! + * \brief Renders a \b Node and all sub-elements into an XML text + * representation. The caller is required to free the \b DOMString + * returned from this function using \b ixmlFreeDOMString when it + * is no longer required. + * + * Note that this function can be used for any \b Node-derived + * interface. The difference between \b ixmlNodetoString and + * \b ixmlDocumenttoString is \b ixmlNodetoString does not include + * the XML prolog, it only produces XML elements. + * + * \return A \b DOMString with the XML text representation of the DOM tree or + * \c NULL on an error. + */ +EXPORT_SPEC DOMString ixmlNodetoString( + /*! [in] The root of the \b Node tree to render to XML text. */ + IXML_Node *doc); -EXPORT_SPEC IXML_Document* -ixmlLoadDocument(const char* xmlFile - /** The filename of the XML text to convert to a {\bf - Document}. */ - ); - /** Parses an XML text file converting it into an IXML DOM representation. - * - * The {\bf ixmlLoadDocumentEx} API differs from the {\bf ixmlLoadDocument} - * API in that it returns a an error code representing the actual failure - * rather than just {\tt NULL}. - * - * @return [int] An integer representing one of the following: - * \begin{itemize} - * \item {\tt IXML_SUCCESS}: The operation completed successfully. - * \item {\tt IXML_INVALID_PARAMETER}: The {\bf xmlFile} is not a valid - * pointer. - * \item {\tt IXML_INSUFFICIENT_MEMORY}: Not enough free memory exists - * to complete this operation. - * \end{itemize} - */ +/*! + * \brief Makes the XML parser more tolerant to malformed text. + */ +EXPORT_SPEC void ixmlRelaxParser( + /*! [in] If \b errorChar is 0 (default), the parser is strict about XML + * encoding : invalid UTF-8 sequences or "&" entities are rejected, and + * the parsing aborts. + * + * If \b errorChar is not 0, the parser is relaxed: invalid UTF-8 + * characters are replaced by the \b errorChar, and invalid "&" entities + * are left untranslated. The parsing is then allowed to continue. + */ + char errorChar); -EXPORT_SPEC int -ixmlLoadDocumentEx(const char* xmlFile, - /** The filename of the XML text to convert to a {\bf - Document}. */ - IXML_Document** doc - /** A pointer to the {\bf Document} if file correctly - parses or {\bf NULL} on an error. */ - ); - /** Clones an existing {\bf DOMString}. - * - * @return [DOMString] A new {\bf DOMString} that is a duplicate of the - * original or {\tt NULL} if the operation could not - * be completed. - */ +/*! + * \brief Parses an XML text buffer converting it into an IXML DOM representation. + * + * \return A \b Document if the buffer correctly parses or \c NULL on an error. + */ +EXPORT_SPEC IXML_Document *ixmlParseBuffer( + /*! [in] The buffer that contains the XML text to convert to a \b Document. */ + const char *buffer); -EXPORT_SPEC DOMString -ixmlCloneDOMString(const DOMString src - /** The source {\bf DOMString} to clone. */ - ); - /** Frees a {\bf DOMString}. - * - * @return [void] This function does not return a value. - */ +/*! + * \brief Parses an XML text buffer converting it into an IXML DOM representation. + * + * The \b ixmlParseBufferEx API differs from the \b ixmlParseBuffer + * API in that it returns an error code representing the actual failure + * rather than just \c NULL. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: The \b buffer is not a valid + * pointer. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete this operation. + */ +EXPORT_SPEC int ixmlParseBufferEx( + /*! [in] The buffer that contains the XML text to convert to a \b Document. */ + const char *buffer, + /*! [out] A point to store the \b Document if file correctly parses or \b NULL on an error. */ + IXML_Document** doc); + + +/*! + * \brief Parses an XML text file converting it into an IXML DOM representation. + * + * \return A \b Document if the file correctly parses or \c NULL on an error. + */ +EXPORT_SPEC IXML_Document *ixmlLoadDocument( + /*! [in] The filename of the XML text to convert to a \b Document. */ + const char* xmlFile); + + +/*! + * \brief Parses an XML text file converting it into an IXML DOM representation. + * + * The \b ixmlLoadDocumentEx API differs from the \b ixmlLoadDocument + * API in that it returns a an error code representing the actual failure + * rather than just \c NULL. + * + * \return An integer representing one of the following: + * \li \c IXML_SUCCESS: The operation completed successfully. + * \li \c IXML_INVALID_PARAMETER: The \b xmlFile is not a valid + * pointer. + * \li \c IXML_INSUFFICIENT_MEMORY: Not enough free memory exists + * to complete this operation. + */ +EXPORT_SPEC int ixmlLoadDocumentEx( + /*! [in] The filename of the XML text to convert to a \b Document. */ + const char *xmlFile, + /*! [out] A pointer to the \b Document if file correctly parses or \b NULL + * on an error. */ + IXML_Document **doc); + + +/*! + * \brief Clones an existing \b DOMString. + * + * \return A new \b DOMString that is a duplicate of the original or \c NULL + * if the operation could not be completed. + */ +EXPORT_SPEC DOMString ixmlCloneDOMString( + /*! [in] The source \b DOMString to clone. */ + const DOMString src); + + +/*! + * \brief Frees a \b DOMString. + */ +EXPORT_SPEC void ixmlFreeDOMString( + /*! [in] The \b DOMString to free. */ + DOMString buf); + + +/* @} IXML API */ -EXPORT_SPEC void -ixmlFreeDOMString(DOMString buf - /** The {\bf DOMString} to free. */ - ); #ifdef __cplusplus } #endif -/*! @} */ /* IXML API */ -#endif /* _IXML_H_ */ +/* @} XMLAPI XML API */ + + +#endif /* IXML_H */ diff --git a/ixml/src/attr.c b/ixml/src/attr.c index 4f0732d..80e199e 100644 --- a/ixml/src/attr.c +++ b/ixml/src/attr.c @@ -1,60 +1,53 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/******************************************************************************* + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + #include "ixmlparser.h" -/*================================================================ -* Function: Attr_init -* Initializes an attribute node -* External function. -* -*=================================================================*/ -void -ixmlAttr_init( IN IXML_Attr * attr ) + +#include + + +void ixmlAttr_init(IN IXML_Attr *attr) { - if( attr != NULL ) { - memset( attr, 0, sizeof( IXML_Attr ) ); - } + if (attr != NULL) { + memset(attr, 0, sizeof (IXML_Attr)); + } } -/*================================================================ -* Function: Attr_free -* Frees an attribute node. -* external function. -* -*=================================================================*/ -void -ixmlAttr_free( IN IXML_Attr * attr ) + +void ixmlAttr_free(IN IXML_Attr *attr) { - if( attr != NULL ) { - ixmlNode_free( ( IXML_Node * ) attr ); - } + if (attr != NULL) { + ixmlNode_free((IXML_Node *)attr); + } } + diff --git a/ixml/src/document.c b/ixml/src/document.c index 1f7f530..8fee1f0 100644 --- a/ixml/src/document.c +++ b/ixml/src/document.c @@ -1,804 +1,584 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/******************************************************************************* + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + + +/*! + * \file + */ + + +#include "ixmldebug.h" +#include "ixmlparser.h" + #include #include +#include -#include "ixmlparser.h" -/*================================================================ -* ixmlDocument_init -* It initialize the document structure. -* External function. -* -*=================================================================*/ -void -ixmlDocument_init( IN IXML_Document * doc ) +void ixmlDocument_init(IXML_Document *doc) { - memset( doc, 0, sizeof( IXML_Document ) ); + memset(doc, 0, sizeof(IXML_Document)); } -/*================================================================ -* ixmlDocument_free -* It frees the whole document tree. -* External function. -* -*=================================================================*/ -void -ixmlDocument_free( IN IXML_Document * doc ) -{ - if( doc != NULL ) { - ixmlNode_free( ( IXML_Node * ) doc ); - } +void ixmlDocument_free(IXML_Document *doc) +{ + if (doc != NULL) { + ixmlNode_free((IXML_Node *)doc); + } } -/*================================================================ -* ixmlDocument_setOwnerDocument -* -* When this function is called first time, nodeptr is the root -* of the subtree, so it is not necessay to do two steps -* recursion. -* -* Internal function called by ixmlDocument_importNode -* -*=================================================================*/ -void -ixmlDocument_setOwnerDocument( IN IXML_Document * doc, - IN IXML_Node * nodeptr ) + +/*! + * When this function is called first time, nodeptr is the root of the subtree, + * so it is not necessay to do two steps recursion. + * + * Internal function called by ixmlDocument_importNode + */ +static void ixmlDocument_setOwnerDocument( + /*! [in] The document node. */ + IXML_Document *doc, + /*! [in] \todo documentation. */ + IXML_Node *nodeptr) { - if( nodeptr != NULL ) { - nodeptr->ownerDocument = doc; - ixmlDocument_setOwnerDocument( doc, - ixmlNode_getFirstChild( nodeptr ) ); - ixmlDocument_setOwnerDocument( doc, - ixmlNode_getNextSibling - ( nodeptr ) ); - } + if (nodeptr != NULL) { + nodeptr->ownerDocument = doc; + ixmlDocument_setOwnerDocument( + doc, ixmlNode_getFirstChild(nodeptr)); + ixmlDocument_setOwnerDocument( + doc, ixmlNode_getNextSibling(nodeptr)); + } } -/*================================================================ -* ixmlDocument_importNode -* Imports a node from another document to this document. The -* returned node has no parent; (parentNode is null). The source -* node is not altered or removed from the original document; -* this method creates a new copy of the source node. - -* For all nodes, importing a node creates a node object owned -* by the importing document, with attribute values identical to -* the source node's nodeName and nodeType, plus the attributes -* related to namespaces (prefix, localName, and namespaceURI). -* As in the cloneNode operation on a node, the source node is -* not altered. -* -* External function. -* -*=================================================================*/ -int -ixmlDocument_importNode( IN IXML_Document * doc, - IN IXML_Node * importNode, - IN BOOL deep, - OUT IXML_Node ** rtNode ) + +int ixmlDocument_importNode( + IXML_Document *doc, + IXML_Node *importNode, + BOOL deep, + IXML_Node **rtNode) { - unsigned short nodeType; - IXML_Node *newNode; + unsigned short nodeType; + IXML_Node *newNode; - *rtNode = NULL; + *rtNode = NULL; - if( ( doc == NULL ) || ( importNode == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (doc == NULL || importNode == NULL) { + return IXML_INVALID_PARAMETER; + } - nodeType = ixmlNode_getNodeType( importNode ); - if( nodeType == eDOCUMENT_NODE ) { - return IXML_NOT_SUPPORTED_ERR; - } + nodeType = ixmlNode_getNodeType(importNode); + if (nodeType == eDOCUMENT_NODE) { + return IXML_NOT_SUPPORTED_ERR; + } - newNode = ixmlNode_cloneNode( importNode, deep ); - if( newNode == NULL ) { - return IXML_FAILED; - } + newNode = ixmlNode_cloneNode(importNode, deep); + if (newNode == NULL) { + return IXML_FAILED; + } - ixmlDocument_setOwnerDocument( doc, newNode ); - *rtNode = newNode; + ixmlDocument_setOwnerDocument(doc, newNode); + *rtNode = newNode; - return IXML_SUCCESS; + return IXML_SUCCESS; } -/*================================================================ -* ixmlDocument_createElementEx -* Creates an element of the type specified. -* External function. -* Parameters: -* doc: pointer to document -* tagName: The name of the element, it is case-sensitive. -* Return Value: -* IXML_SUCCESS -* IXML_INVALID_PARAMETER: if either doc or tagName is NULL -* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations. -* -*=================================================================*/ -int -ixmlDocument_createElementEx( IN IXML_Document * doc, - IN const DOMString tagName, - OUT IXML_Element ** rtElement ) + +int ixmlDocument_createElementEx( + IXML_Document *doc, + const DOMString tagName, + IXML_Element **rtElement) { + int errCode = IXML_SUCCESS; + IXML_Element *newElement = NULL; - int errCode = IXML_SUCCESS; - IXML_Element *newElement = NULL; + if (doc == NULL || tagName == NULL) { + errCode = IXML_INVALID_PARAMETER; + goto ErrorHandler; + } - if( ( doc == NULL ) || ( tagName == NULL ) ) { - errCode = IXML_INVALID_PARAMETER; - goto ErrorHandler; - } + newElement = (IXML_Element *) malloc(sizeof(IXML_Element)); + if (newElement == NULL) { + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - newElement = ( IXML_Element * ) malloc( sizeof( IXML_Element ) ); - if( newElement == NULL ) { - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + ixmlElement_init(newElement); + newElement->tagName = strdup(tagName); + if (newElement->tagName == NULL) { + ixmlElement_free(newElement); + newElement = NULL; + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } + // set the node fields + newElement->n.nodeType = eELEMENT_NODE; + newElement->n.nodeName = strdup(tagName); + if (newElement->n.nodeName == NULL) { + ixmlElement_free(newElement); + newElement = NULL; + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - ixmlElement_init( newElement ); - newElement->tagName = strdup( tagName ); - if( newElement->tagName == NULL ) { - ixmlElement_free( newElement ); - newElement = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } - // set the node fields - newElement->n.nodeType = eELEMENT_NODE; - newElement->n.nodeName = strdup( tagName ); - if( newElement->n.nodeName == NULL ) { - ixmlElement_free( newElement ); - newElement = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + newElement->n.ownerDocument = doc; - newElement->n.ownerDocument = doc; - - ErrorHandler: - *rtElement = newElement; - return errCode; +ErrorHandler: + *rtElement = newElement; + return errCode; } -/*================================================================ -* ixmlDocument_createElement -* Creates an element of the type specified. -* External function. -* Parameters: -* doc: pointer to document -* tagName: The name of the element, it is case-sensitive. -* Return Value: -* A new element object with the nodeName set to tagName, and -* localName, prefix and namespaceURI set to null. -* -*=================================================================*/ -IXML_Element * -ixmlDocument_createElement( IN IXML_Document * doc, - IN const DOMString tagName ) + +IXML_Element *ixmlDocument_createElement( + IXML_Document *doc, + const DOMString tagName) { - IXML_Element *newElement = NULL; - - ixmlDocument_createElementEx( doc, tagName, &newElement ); - return newElement; + IXML_Element *newElement = NULL; + ixmlDocument_createElementEx(doc, tagName, &newElement); + return newElement; } -/*================================================================ -* ixmlDocument_createDocumentEx -* Creates an document object -* Internal function. -* Parameters: -* rtDoc: the document created or NULL on failure -* Return Value: -* IXML_SUCCESS -* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations. -* -*=================================================================*/ -int -ixmlDocument_createDocumentEx( OUT IXML_Document ** rtDoc ) + +int ixmlDocument_createDocumentEx(IXML_Document **rtDoc) { - IXML_Document *doc; - int errCode = IXML_SUCCESS; + IXML_Document *doc; + int errCode = IXML_SUCCESS; - doc = NULL; - doc = ( IXML_Document * ) malloc( sizeof( IXML_Document ) ); - if( doc == NULL ) { - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + doc = NULL; + doc = (IXML_Document *)malloc(sizeof (IXML_Document)); + if (doc == NULL) { + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - ixmlDocument_init( doc ); + ixmlDocument_init(doc); - doc->n.nodeName = strdup( DOCUMENTNODENAME ); - if( doc->n.nodeName == NULL ) { - ixmlDocument_free( doc ); - doc = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + doc->n.nodeName = strdup(DOCUMENTNODENAME); + if (doc->n.nodeName == NULL) { + ixmlDocument_free(doc); + doc = NULL; + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - doc->n.nodeType = eDOCUMENT_NODE; - doc->n.ownerDocument = doc; + doc->n.nodeType = eDOCUMENT_NODE; + doc->n.ownerDocument = doc; - ErrorHandler: - *rtDoc = doc; - return errCode; +ErrorHandler: + *rtDoc = doc; + return errCode; } -/*================================================================ -* ixmlDocument_createDocument -* Creates an document object -* Internal function. -* Parameters: -* none -* Return Value: -* A new document object with the nodeName set to "#document". -* -*=================================================================*/ -IXML_Document * -ixmlDocument_createDocument() + +IXML_Document *ixmlDocument_createDocument() { - IXML_Document *doc = NULL; + IXML_Document *doc = NULL; - ixmlDocument_createDocumentEx( &doc ); - - return doc; + ixmlDocument_createDocumentEx(&doc); + return doc; } -/*================================================================ -* ixmlDocument_createTextNodeEx -* Creates an text node. -* External function. -* Parameters: -* data: text data for the text node. It is stored in nodeValue field. -* Return Value: -* IXML_SUCCESS -* IXML_INVALID_PARAMETER: if either doc or data is NULL -* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations. -* -*=================================================================*/ -int -ixmlDocument_createTextNodeEx( IN IXML_Document * doc, - IN const char *data, - OUT IXML_Node ** textNode ) + +int ixmlDocument_createTextNodeEx( + IXML_Document *doc, + const DOMString data, + IXML_Node **textNode) { - IXML_Node *returnNode; - int rc = IXML_SUCCESS; + IXML_Node *returnNode; + int rc = IXML_SUCCESS; - returnNode = NULL; - if( ( doc == NULL ) || ( data == NULL ) ) { - rc = IXML_INVALID_PARAMETER; - goto ErrorHandler; - } + returnNode = NULL; + if (doc == NULL || data == NULL) { + rc = IXML_INVALID_PARAMETER; + goto ErrorHandler; + } - returnNode = ( IXML_Node * ) malloc( sizeof( IXML_Node ) ); - if( returnNode == NULL ) { - rc = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } - // initialize the node - ixmlNode_init( returnNode ); + returnNode = (IXML_Node *)malloc(sizeof (IXML_Node)); + if (returnNode == NULL) { + rc = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } + // initialize the node + ixmlNode_init(returnNode); - returnNode->nodeName = strdup( TEXTNODENAME ); - if( returnNode->nodeName == NULL ) { - ixmlNode_free( returnNode ); - returnNode = NULL; - rc = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } - // add in node value - if( data != NULL ) { - returnNode->nodeValue = strdup( data ); - if( returnNode->nodeValue == NULL ) { - ixmlNode_free( returnNode ); - returnNode = NULL; - rc = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } - } + returnNode->nodeName = strdup(TEXTNODENAME); + if (returnNode->nodeName == NULL) { + ixmlNode_free(returnNode); + returnNode = NULL; + rc = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } + // add in node value + if (data != NULL) { + returnNode->nodeValue = strdup(data); + if (returnNode->nodeValue == NULL) { + ixmlNode_free(returnNode); + returnNode = NULL; + rc = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } + } - returnNode->nodeType = eTEXT_NODE; - returnNode->ownerDocument = doc; - - ErrorHandler: - *textNode = returnNode; - return rc; + returnNode->nodeType = eTEXT_NODE; + returnNode->ownerDocument = doc; +ErrorHandler: + *textNode = returnNode; + return rc; } -/*================================================================ -* ixmlDocument_createTextNode -* Creates an text node. -* External function. -* Parameters: -* data: text data for the text node. It is stored in nodeValue field. -* Return Value: -* The new text node. -* -*=================================================================*/ -IXML_Node * -ixmlDocument_createTextNode( IN IXML_Document * doc, - IN const char *data ) + +IXML_Node *ixmlDocument_createTextNode( + IXML_Document *doc, + const DOMString data) { - IXML_Node *returnNode = NULL; + IXML_Node *returnNode = NULL; - ixmlDocument_createTextNodeEx( doc, data, &returnNode ); + ixmlDocument_createTextNodeEx(doc, data, &returnNode); - return returnNode; + return returnNode; } -/*================================================================ -* ixmlDocument_createAttributeEx -* Creates an attribute of the given name. -* External function. -* Parameters: -* name: The name of the Attribute node. -* Return Value: -* IXML_SUCCESS -* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations. -* -================================================================*/ -int -ixmlDocument_createAttributeEx( IN IXML_Document * doc, - IN const char *name, - OUT IXML_Attr ** rtAttr ) + +int ixmlDocument_createAttributeEx( + IXML_Document *doc, + const char *name, + IXML_Attr **rtAttr) { - IXML_Attr *attrNode = NULL; - int errCode = IXML_SUCCESS; + IXML_Attr *attrNode = NULL; + int errCode = IXML_SUCCESS; - attrNode = ( IXML_Attr * ) malloc( sizeof( IXML_Attr ) ); - if( attrNode == NULL ) { - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + attrNode = (IXML_Attr *)malloc(sizeof (IXML_Attr)); + if (attrNode == NULL) { + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - if( ( doc == NULL ) || ( name == NULL ) ) { - ixmlAttr_free( attrNode ); - attrNode = NULL; - errCode = IXML_INVALID_PARAMETER; - goto ErrorHandler; - } + if (doc == NULL || name == NULL) { + ixmlAttr_free(attrNode); + attrNode = NULL; + errCode = IXML_INVALID_PARAMETER; + goto ErrorHandler; + } - ixmlAttr_init( attrNode ); + ixmlAttr_init(attrNode); + attrNode->n.nodeType = eATTRIBUTE_NODE; - attrNode->n.nodeType = eATTRIBUTE_NODE; + // set the node fields + attrNode->n.nodeName = strdup(name); + if (attrNode->n.nodeName == NULL) { + ixmlAttr_free(attrNode); + attrNode = NULL; + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - // set the node fields - attrNode->n.nodeName = strdup( name ); - if( attrNode->n.nodeName == NULL ) { - ixmlAttr_free( attrNode ); - attrNode = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } - - attrNode->n.ownerDocument = doc; - - ErrorHandler: - *rtAttr = attrNode; - return errCode; + attrNode->n.ownerDocument = doc; +ErrorHandler: + *rtAttr = attrNode; + return errCode; } -/*================================================================ -* ixmlDocument_createAttribute -* Creates an attribute of the given name. -* External function. -* Parameters: -* name: The name of the Attribute node. -* Return Value: -* A new attr object with the nodeName attribute set to the -* given name, and the localName, prefix and namespaceURI set to NULL. -* The value of the attribute is the empty string. -* -================================================================*/ -IXML_Attr * -ixmlDocument_createAttribute( IN IXML_Document * doc, - IN const char *name ) + +IXML_Attr *ixmlDocument_createAttribute( + IXML_Document *doc, + const char *name) { - IXML_Attr *attrNode = NULL; + IXML_Attr *attrNode = NULL; - ixmlDocument_createAttributeEx( doc, name, &attrNode ); - return attrNode; + ixmlDocument_createAttributeEx(doc, name, &attrNode); + return attrNode; } -/*================================================================ -* ixmlDocument_createAttributeNSEx -* Creates an attrbute of the given name and namespace URI -* External function. -* Parameters: -* namespaceURI: the namespace fo the attribute to create -* qualifiedName: qualifiedName of the attribute to instantiate -* Return Value: -* IXML_SUCCESS -* IXML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL -* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations. -* -*=================================================================*/ -int -ixmlDocument_createAttributeNSEx( IN IXML_Document * doc, - IN const DOMString namespaceURI, - IN const DOMString qualifiedName, - OUT IXML_Attr ** rtAttr ) + +int ixmlDocument_createAttributeNSEx( + IXML_Document *doc, + const DOMString namespaceURI, + const DOMString qualifiedName, + IXML_Attr **rtAttr ) { - IXML_Attr *attrNode = NULL; - int errCode = IXML_SUCCESS; + IXML_Attr *attrNode = NULL; + int errCode = IXML_SUCCESS; - if( ( doc == NULL ) || ( namespaceURI == NULL ) - || ( qualifiedName == NULL ) ) { - errCode = IXML_INVALID_PARAMETER; - goto ErrorHandler; - } + if (doc == NULL || namespaceURI == NULL || qualifiedName == NULL) { + errCode = IXML_INVALID_PARAMETER; + goto ErrorHandler; + } - errCode = - ixmlDocument_createAttributeEx( doc, qualifiedName, &attrNode ); - if( errCode != IXML_SUCCESS ) { - goto ErrorHandler; - } - // set the namespaceURI field - attrNode->n.namespaceURI = strdup( namespaceURI ); - if( attrNode->n.namespaceURI == NULL ) { - ixmlAttr_free( attrNode ); - attrNode = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } - // set the localName and prefix - errCode = - ixmlNode_setNodeName( ( IXML_Node * ) attrNode, qualifiedName ); - if( errCode != IXML_SUCCESS ) { - ixmlAttr_free( attrNode ); - attrNode = NULL; - goto ErrorHandler; - } - - ErrorHandler: - *rtAttr = attrNode; - return errCode; + errCode = + ixmlDocument_createAttributeEx(doc, qualifiedName, &attrNode); + if (errCode != IXML_SUCCESS) { + goto ErrorHandler; + } + // set the namespaceURI field + attrNode->n.namespaceURI = strdup(namespaceURI); + if (attrNode->n.namespaceURI == NULL) { + ixmlAttr_free(attrNode); + attrNode = NULL; + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } + // set the localName and prefix + errCode = + ixmlNode_setNodeName((IXML_Node *)attrNode, qualifiedName); + if (errCode != IXML_SUCCESS) { + ixmlAttr_free(attrNode); + attrNode = NULL; + goto ErrorHandler; + } +ErrorHandler: + *rtAttr = attrNode; + return errCode; } -/*================================================================ -* ixmlDocument_createAttributeNS -* Creates an attrbute of the given name and namespace URI -* External function. -* Parameters: -* namespaceURI: the namespace fo the attribute to create -* qualifiedName: qualifiedName of the attribute to instantiate -* Return Value: -* Creates an attribute node with the given namespaceURI and -* qualifiedName. The prefix and localname are extracted from -* the qualifiedName. The node value is empty. -* -*=================================================================*/ -IXML_Attr * -ixmlDocument_createAttributeNS( IN IXML_Document * doc, - IN const DOMString namespaceURI, - IN const DOMString qualifiedName ) -{ - IXML_Attr *attrNode = NULL; - ixmlDocument_createAttributeNSEx( doc, namespaceURI, qualifiedName, - &attrNode ); - return attrNode; +IXML_Attr *ixmlDocument_createAttributeNS( + IXML_Document *doc, + const DOMString namespaceURI, + const DOMString qualifiedName) +{ + IXML_Attr *attrNode = NULL; + + ixmlDocument_createAttributeNSEx( + doc, namespaceURI, qualifiedName, &attrNode); + + return attrNode; } -/*================================================================ -* ixmlDocument_createCDATASectionEx -* Creates an CDATASection node whose value is the specified string -* External function. -* Parameters: -* data: the data for the CDATASection contents. -* Return Value: -* IXML_SUCCESS -* IXML_INVALID_PARAMETER: if either doc or data is NULL -* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations. -* -*=================================================================*/ -int -ixmlDocument_createCDATASectionEx( IN IXML_Document * doc, - IN const DOMString data, - OUT IXML_CDATASection ** rtCD ) + +int ixmlDocument_createCDATASectionEx( + IXML_Document *doc, + const DOMString data, + IXML_CDATASection **rtCD) { - int errCode = IXML_SUCCESS; - IXML_CDATASection *cDSectionNode = NULL; + int errCode = IXML_SUCCESS; + IXML_CDATASection *cDSectionNode = NULL; - if( ( doc == NULL ) || ( data == NULL ) ) { - errCode = IXML_INVALID_PARAMETER; - goto ErrorHandler; - } + if(doc == NULL || data == NULL) { + errCode = IXML_INVALID_PARAMETER; + goto ErrorHandler; + } - cDSectionNode = - ( IXML_CDATASection * ) malloc( sizeof( IXML_CDATASection ) ); - if( cDSectionNode == NULL ) { - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + cDSectionNode = (IXML_CDATASection *)malloc(sizeof (IXML_CDATASection)); + if (cDSectionNode == NULL) { + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - ixmlCDATASection_init( cDSectionNode ); + ixmlCDATASection_init(cDSectionNode); + cDSectionNode->n.nodeType = eCDATA_SECTION_NODE; + cDSectionNode->n.nodeName = strdup(CDATANODENAME); + if (cDSectionNode->n.nodeName == NULL) { + ixmlCDATASection_free(cDSectionNode); + cDSectionNode = NULL; + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - cDSectionNode->n.nodeType = eCDATA_SECTION_NODE; - cDSectionNode->n.nodeName = strdup( CDATANODENAME ); - if( cDSectionNode->n.nodeName == NULL ) { - ixmlCDATASection_free( cDSectionNode ); - cDSectionNode = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + cDSectionNode->n.nodeValue = strdup(data); + if (cDSectionNode->n.nodeValue == NULL) { + ixmlCDATASection_free( cDSectionNode ); + cDSectionNode = NULL; + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - cDSectionNode->n.nodeValue = strdup( data ); - if( cDSectionNode->n.nodeValue == NULL ) { - ixmlCDATASection_free( cDSectionNode ); - cDSectionNode = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } - - cDSectionNode->n.ownerDocument = doc; - - ErrorHandler: - *rtCD = cDSectionNode; - return errCode; + cDSectionNode->n.ownerDocument = doc; +ErrorHandler: + *rtCD = cDSectionNode; + return errCode; } -/*================================================================ -* ixmlDocument_createCDATASection -* Creates an CDATASection node whose value is the specified string -* External function. -* Parameters: -* data: the data for the CDATASection contents. -* Return Value: -* The new CDATASection object. -* -*=================================================================*/ -IXML_CDATASection * -ixmlDocument_createCDATASection( IN IXML_Document * doc, - IN const DOMString data ) + +IXML_CDATASection *ixmlDocument_createCDATASection( + IXML_Document *doc, + const DOMString data) { + IXML_CDATASection *cDSectionNode = NULL; - IXML_CDATASection *cDSectionNode = NULL; + ixmlDocument_createCDATASectionEx(doc, data, &cDSectionNode); - ixmlDocument_createCDATASectionEx( doc, data, &cDSectionNode ); - return cDSectionNode; + return cDSectionNode; } -/*================================================================ -* ixmlDocument_createElementNSEx -* Creates an element of the given qualified name and namespace URI. -* External function. -* Parameters: -* namespaceURI: the namespace URI of the element to create. -* qualifiedName: the qualified name of the element to instantiate. -* Return Value: -* Return Value: -* IXML_SUCCESS -* IXML_INVALID_PARAMETER: if either doc,namespaceURI or qualifiedName is NULL -* IXML_INSUFFICIENT_MEMORY: if not enough memory to finish this operations. -* -*=================================================================*/ -int -ixmlDocument_createElementNSEx( IN IXML_Document * doc, - IN const DOMString namespaceURI, - IN const DOMString qualifiedName, - OUT IXML_Element ** rtElement ) + +int ixmlDocument_createElementNSEx( + IXML_Document *doc, + const DOMString namespaceURI, + const DOMString qualifiedName, + IXML_Element **rtElement) { + IXML_Element *newElement = NULL; + int errCode = IXML_SUCCESS; + int line = 0; - IXML_Element *newElement = NULL; - int errCode = IXML_SUCCESS; + if (doc == NULL || namespaceURI == NULL || qualifiedName == NULL) { + line = __LINE__; + errCode = IXML_INVALID_PARAMETER; + goto ErrorHandler; + } - if( ( doc == NULL ) || ( namespaceURI == NULL ) - || ( qualifiedName == NULL ) ) { - errCode = IXML_INVALID_PARAMETER; - goto ErrorHandler; - } + errCode = ixmlDocument_createElementEx(doc, qualifiedName, &newElement); + if (errCode != IXML_SUCCESS) { + line = __LINE__; + goto ErrorHandler; + } + // set the namespaceURI field + newElement->n.namespaceURI = strdup(namespaceURI); + if (newElement->n.namespaceURI == NULL) { + line = __LINE__; + ixmlElement_free(newElement); + newElement = NULL; + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } + // set the localName and prefix + errCode = ixmlNode_setNodeName((IXML_Node *)newElement, qualifiedName); + if (errCode != IXML_SUCCESS) { + line = __LINE__; + ixmlElement_free(newElement); + newElement = NULL; + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - errCode = - ixmlDocument_createElementEx( doc, qualifiedName, &newElement ); - if( errCode != IXML_SUCCESS ) { - goto ErrorHandler; - } - // set the namespaceURI field - newElement->n.namespaceURI = strdup( namespaceURI ); - if( newElement->n.namespaceURI == NULL ) { - ixmlElement_free( newElement ); - newElement = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } - // set the localName and prefix - errCode = - ixmlNode_setNodeName( ( IXML_Node * ) newElement, qualifiedName ); - if( errCode != IXML_SUCCESS ) { - ixmlElement_free( newElement ); - newElement = NULL; - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + newElement->n.nodeValue = NULL; - newElement->n.nodeValue = NULL; - - ErrorHandler: - *rtElement = newElement; - return errCode; +ErrorHandler: + *rtElement = newElement; + if (errCode != IXML_SUCCESS) { + IxmlPrintf("(%s::ixmlDocument_createElementNSEx): Error %d, line %d\n", + __FILE__, errCode, line); + } + return errCode; } -/*================================================================ -* ixmlDocument_createElementNS -* Creates an element of the given qualified name and namespace URI. -* External function. -* Parameters: -* namespaceURI: the namespace URI of the element to create. -* qualifiedName: the qualified name of the element to instantiate. -* Return Value: -* The new element object with tagName qualifiedName, prefix and -* localName extraced from qualfiedName, nodeName of qualfiedName, -* namespaceURI of namespaceURI. -* -*=================================================================*/ -IXML_Element * -ixmlDocument_createElementNS( IN IXML_Document * doc, - IN const DOMString namespaceURI, - IN const DOMString qualifiedName ) -{ - IXML_Element *newElement = NULL; - ixmlDocument_createElementNSEx( doc, namespaceURI, qualifiedName, - &newElement ); - return newElement; +IXML_Element *ixmlDocument_createElementNS( + IXML_Document *doc, + const DOMString namespaceURI, + const DOMString qualifiedName) +{ + IXML_Element *newElement = NULL; + + ixmlDocument_createElementNSEx(doc, namespaceURI, qualifiedName, &newElement); + + return newElement; } -/*================================================================ -* ixmlDocument_getElementsByTagName -* Returns a nodeList of all the Elements with a given tag name -* in the order in which they are encountered in a preorder traversal -* of the document tree. -* External function. -* Parameters: -* tagName: the name of the tag to match on. The special value "*" -* matches all tags. -* Return Value: -* A new nodeList object containing all the matched Elements. -* -*=================================================================*/ -IXML_NodeList * -ixmlDocument_getElementsByTagName( IN IXML_Document * doc, - IN const char *tagName ) + +IXML_NodeList *ixmlDocument_getElementsByTagName( + IXML_Document *doc, + const DOMString tagName) { - IXML_NodeList *returnNodeList = NULL; + IXML_NodeList *returnNodeList = NULL; - if( ( doc == NULL ) || ( tagName == NULL ) ) { - return NULL; - } + if (doc == NULL || tagName == NULL) { + return NULL; + } - ixmlNode_getElementsByTagName( ( IXML_Node * ) doc, tagName, - &returnNodeList ); - return returnNodeList; + ixmlNode_getElementsByTagName((IXML_Node *)doc, tagName, &returnNodeList); + + return returnNodeList; } -/*================================================================ -* ixmlDocument_getElementsByTagNameNS -* Returns a nodeList of all the Elements with a given local name and -* namespace URI in the order in which they are encountered in a -* preorder traversal of the document tree. -* External function. -* Parameters: -* namespaceURI: the namespace of the elements to match on. The special -* value "*" matches all namespaces. -* localName: the local name of the elements to match on. The special -* value "*" matches all local names. -* Return Value: -* A new nodeList object containing all the matched Elements. -* -*=================================================================*/ -IXML_NodeList * -ixmlDocument_getElementsByTagNameNS( IN IXML_Document * doc, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +IXML_NodeList *ixmlDocument_getElementsByTagNameNS( + IXML_Document *doc, + const DOMString namespaceURI, + const DOMString localName) { - IXML_NodeList *returnNodeList = NULL; + IXML_NodeList *returnNodeList = NULL; - if( ( doc == NULL ) || ( namespaceURI == NULL ) - || ( localName == NULL ) ) { - return NULL; - } + if (doc == NULL || namespaceURI == NULL || localName == NULL) { + return NULL; + } - ixmlNode_getElementsByTagNameNS( ( IXML_Node * ) doc, namespaceURI, - localName, &returnNodeList ); - return returnNodeList; + ixmlNode_getElementsByTagNameNS( + (IXML_Node *)doc, namespaceURI, localName, &returnNodeList); + + return returnNodeList; } -/*================================================================ -* ixmlDocument_getElementById -* Returns the element whose ID is given by tagName. If no such -* element exists, returns null. -* External function. -* Parameter: -* tagName: the tag name for an element. -* Return Values: -* The matching element. -* -*=================================================================*/ -IXML_Element * -ixmlDocument_getElementById( IN IXML_Document * doc, - IN const DOMString tagName ) + +IXML_Element *ixmlDocument_getElementById( + IXML_Document *doc, + const DOMString tagName) { - IXML_Element *rtElement = NULL; - IXML_Node *nodeptr = ( IXML_Node * ) doc; - const char *name; + IXML_Element *rtElement = NULL; + IXML_Node *nodeptr = (IXML_Node *)doc; + const char *name; - if( ( nodeptr == NULL ) || ( tagName == NULL ) ) { - return rtElement; - } + if (nodeptr == NULL || tagName == NULL) { + return rtElement; + } - if( ixmlNode_getNodeType( nodeptr ) == eELEMENT_NODE ) { - name = ixmlNode_getNodeName( nodeptr ); - if( name == NULL ) { - return rtElement; - } + if (ixmlNode_getNodeType(nodeptr) == eELEMENT_NODE) { + name = ixmlNode_getNodeName(nodeptr); + if (name == NULL) { + return rtElement; + } - if( strcmp( tagName, name ) == 0 ) { - rtElement = ( IXML_Element * ) nodeptr; - return rtElement; - } else { - rtElement = ixmlDocument_getElementById( ( IXML_Document * ) - ixmlNode_getFirstChild - ( nodeptr ), - tagName ); - if( rtElement == NULL ) { - rtElement = ixmlDocument_getElementById( ( IXML_Document - * ) - ixmlNode_getNextSibling - ( nodeptr ), - tagName ); - } - } - } else { - rtElement = ixmlDocument_getElementById( ( IXML_Document * ) - ixmlNode_getFirstChild - ( nodeptr ), tagName ); - if( rtElement == NULL ) { - rtElement = ixmlDocument_getElementById( ( IXML_Document * ) - ixmlNode_getNextSibling - ( nodeptr ), - tagName ); - } - } + if (strcmp(tagName, name) == 0) { + rtElement = (IXML_Element *)nodeptr; + return rtElement; + } else { + rtElement = ixmlDocument_getElementById( + (IXML_Document *)ixmlNode_getFirstChild(nodeptr), + tagName ); + if (rtElement == NULL) { + rtElement = ixmlDocument_getElementById( + (IXML_Document *)ixmlNode_getNextSibling(nodeptr), + tagName); + } + } + } else { + rtElement = ixmlDocument_getElementById( + (IXML_Document *)ixmlNode_getFirstChild(nodeptr), + tagName); + if (rtElement == NULL) { + rtElement = ixmlDocument_getElementById( + (IXML_Document *)ixmlNode_getNextSibling(nodeptr), + tagName); + } + } - return rtElement; + return rtElement; } + diff --git a/ixml/src/element.c b/ixml/src/element.c index 524d9b6..b554314 100644 --- a/ixml/src/element.c +++ b/ixml/src/element.c @@ -1,969 +1,717 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/******************************************************************************* + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + + +/*! + * \file + */ + #include "ixmlparser.h" -/*================================================================ -* ixmlElement_Init -* Initializes an element node. -* External function. -* -*=================================================================*/ -void -ixmlElement_init( IN IXML_Element * element ) + +#include +#include /* for free() */ +#include + + +void ixmlElement_init(IXML_Element *element) { - if( element != NULL ) { - memset( element, 0, sizeof( IXML_Element ) ); - } + if (element != NULL) { + memset(element, 0, sizeof (IXML_Element)); + } } -/*================================================================ -* ixmlElement_getTagName -* Gets the element node's tagName -* External function. -* -*=================================================================*/ -const DOMString -ixmlElement_getTagName( IN IXML_Element * element ) +const DOMString ixmlElement_getTagName(IXML_Element *element) { - - if( element != NULL ) { - return element->tagName; - } else { - return NULL; - } + if( element != NULL ) { + return element->tagName; + } else { + return NULL; + } } -/*================================================================ -* ixmlElement_setTagName -* Sets the given element's tagName. -* Parameters: -* tagName: new tagName for the element. -* -*=================================================================*/ -int -ixmlElement_setTagName( IN IXML_Element * element, - IN const char *tagName ) + +int ixmlElement_setTagName(IXML_Element *element, const char *tagName) { - int rc = IXML_SUCCESS; + int rc = IXML_SUCCESS; - assert( ( element != NULL ) && ( tagName != NULL ) ); - if( ( element == NULL ) || ( tagName == NULL ) ) { - return IXML_FAILED; - } + assert(element != NULL && tagName != NULL); - if( element->tagName != NULL ) { - free( element->tagName ); - } + if (element == NULL || tagName == NULL) { + return IXML_FAILED; + } - element->tagName = strdup( tagName ); - if( element->tagName == NULL ) { - rc = IXML_INSUFFICIENT_MEMORY; - } - - return rc; + if (element->tagName != NULL) { + free(element->tagName); + } + element->tagName = strdup(tagName); + if (element->tagName == NULL) { + rc = IXML_INSUFFICIENT_MEMORY; + } + return rc; } -/*================================================================ -* ixmlElement_getAttribute -* Retrievea an attribute value by name. -* External function. -* Parameters: -* name: the name of the attribute to retrieve. -* Return Values: -* attribute value as a string, or the empty string if that attribute -* does not have a specified value. -* -*=================================================================*/ -const DOMString -ixmlElement_getAttribute( IN IXML_Element * element, - IN const DOMString name ) + +const DOMString ixmlElement_getAttribute(IXML_Element *element, const DOMString name) { - IXML_Node *attrNode; + IXML_Node *attrNode; - if( ( element == NULL ) || ( name == NULL ) ) { - return NULL; - } + if (element == NULL || name == NULL) { + return NULL; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { // found it - return attrNode->nodeValue; - } else { - attrNode = attrNode->nextSibling; - } - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { + return attrNode->nodeValue; + } else { + attrNode = attrNode->nextSibling; + } + } - return NULL; + return NULL; } -/*================================================================ -* ixmlElement_setAttribute -* Adds a new attribute. If an attribute with that name is already -* present in the element, its value is changed to be that of the value -* parameter. If not, a new attribute is inserted into the element. -* -* External function. -* Parameters: -* name: the name of the attribute to create or alter. -* value: value to set in string form -* Return Values: -* IXML_SUCCESS or failure code. -* -*=================================================================*/ -int -ixmlElement_setAttribute( IN IXML_Element * element, - IN const char *name, - IN const char *value ) + +int ixmlElement_setAttribute( + IXML_Element *element, + const DOMString name, + const DOMString value) { - IXML_Node *attrNode; - IXML_Attr *newAttrNode; - short errCode = IXML_SUCCESS; + IXML_Node *attrNode; + IXML_Attr *newAttrNode; + short errCode = IXML_SUCCESS; - if( ( element == NULL ) || ( name == NULL ) || ( value == NULL ) ) { - errCode = IXML_INVALID_PARAMETER; - goto ErrorHandler; - } + if (element == NULL || name == NULL || value == NULL) { + errCode = IXML_INVALID_PARAMETER; + goto ErrorHandler; + } - if( Parser_isValidXmlName( name ) == FALSE ) { - errCode = IXML_INVALID_CHARACTER_ERR; - goto ErrorHandler; - } + if (Parser_isValidXmlName(name) == FALSE) { + errCode = IXML_INVALID_CHARACTER_ERR; + goto ErrorHandler; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } - if( attrNode == NULL ) { // add a new attribute - errCode = - ixmlDocument_createAttributeEx( ( IXML_Document * ) element->n. - ownerDocument, name, - &newAttrNode ); - if( errCode != IXML_SUCCESS ) { - goto ErrorHandler; - } + if (attrNode == NULL) { + /* Add a new attribute */ + errCode = ixmlDocument_createAttributeEx( + (IXML_Document *)element->n.ownerDocument, name, &newAttrNode); + if (errCode != IXML_SUCCESS) { + goto ErrorHandler; + } - attrNode = ( IXML_Node * ) newAttrNode; + attrNode = (IXML_Node *)newAttrNode; + attrNode->nodeValue = strdup(value); + if (attrNode->nodeValue == NULL) { + ixmlAttr_free(newAttrNode); + errCode = IXML_INSUFFICIENT_MEMORY; + goto ErrorHandler; + } - attrNode->nodeValue = strdup( value ); - if( attrNode->nodeValue == NULL ) { - ixmlAttr_free( newAttrNode ); - errCode = IXML_INSUFFICIENT_MEMORY; - goto ErrorHandler; - } + errCode = ixmlElement_setAttributeNode(element, newAttrNode, NULL); + if (errCode != IXML_SUCCESS) { + ixmlAttr_free(newAttrNode); + goto ErrorHandler; + } + } else { + if (attrNode->nodeValue != NULL) { + /* Attribute name has a value already */ + free(attrNode->nodeValue); + } + attrNode->nodeValue = strdup(value); + if (attrNode->nodeValue == NULL) { + errCode = IXML_INSUFFICIENT_MEMORY; + } + } - errCode = - ixmlElement_setAttributeNode( element, newAttrNode, NULL ); - if( errCode != IXML_SUCCESS ) { - ixmlAttr_free( newAttrNode ); - goto ErrorHandler; - } - - } else { - if( attrNode->nodeValue != NULL ) { // attribute name has a value already - free( attrNode->nodeValue ); - } - - attrNode->nodeValue = strdup( value ); - if( attrNode->nodeValue == NULL ) { - errCode = IXML_INSUFFICIENT_MEMORY; - } - } - - ErrorHandler: - return errCode; +ErrorHandler: + return errCode; } -/*================================================================ -* ixmlElement_removeAttribute -* Removes an attribute value by name. The attribute node is -* not removed. -* External function. -* Parameters: -* name: the name of the attribute to remove. -* Return Values: -* IXML_SUCCESS or error code. -* -*=================================================================*/ -int -ixmlElement_removeAttribute( IN IXML_Element * element, - IN const char *name ) + +int ixmlElement_removeAttribute(IXML_Element *element, const DOMString name) { + IXML_Node *attrNode; - IXML_Node *attrNode; + if (element == NULL || name == NULL) { + return IXML_INVALID_PARAMETER; + } - if( ( element == NULL ) || ( name == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + if (attrNode != NULL) { + /* Has the attribute */ + if (attrNode->nodeValue != NULL) { + free(attrNode->nodeValue); + attrNode->nodeValue = NULL; + } + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } - - if( attrNode != NULL ) { // has the attribute - if( attrNode->nodeValue != NULL ) { - free( attrNode->nodeValue ); - attrNode->nodeValue = NULL; - } - } - - return IXML_SUCCESS; + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_getAttributeNode -* Retrieve an attribute node by name. -* External function. -* Parameters: -* name: the name(nodeName) of the attribute to retrieve. -* Return Value: -* The attr node with the specified name (nodeName) or NULL if -* there is no such attribute. -* -*=================================================================*/ -IXML_Attr * -ixmlElement_getAttributeNode( IN IXML_Element * element, - IN const char *name ) + +IXML_Attr *ixmlElement_getAttributeNode(IXML_Element *element, const DOMString name) { + IXML_Node *attrNode; - IXML_Node *attrNode; + if (element == NULL || name == NULL) { + return NULL; + } - if( ( element == NULL ) || ( name == NULL ) ) { - return NULL; - } - - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { // found it - break; - } else { - attrNode = attrNode->nextSibling; - } - } - - return ( IXML_Attr * ) attrNode; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { // found it + break; + } else { + attrNode = attrNode->nextSibling; + } + } + return (IXML_Attr *)attrNode; } -/*================================================================ -* ixmlElement_setAttributeNode -* Adds a new attribute node. If an attribute with that name(nodeName) -* is already present in the element, it is replaced by the new one. -* External function. -* Parameters: -* The attr node to add to the attribute list. -* Return Value: -* if newAttr replaces an existing attribute, the replaced -* attr node is returned, otherwise NULL is returned. -* -*=================================================================*/ -int -ixmlElement_setAttributeNode( IN IXML_Element * element, - IN IXML_Attr * newAttr, - OUT IXML_Attr ** rtAttr ) + +int ixmlElement_setAttributeNode( + IXML_Element *element, + IXML_Attr *newAttr, + IXML_Attr **rtAttr) { + IXML_Node *attrNode = NULL; + IXML_Node *node = NULL; + IXML_Node *nextAttr = NULL; + IXML_Node *prevAttr = NULL; + IXML_Node *preSib = NULL; + IXML_Node *nextSib = NULL; - IXML_Node *attrNode; - IXML_Node *node; - IXML_Node *nextAttr = NULL; - IXML_Node *prevAttr = NULL; - IXML_Node *preSib, - *nextSib; + if (element == NULL || newAttr == NULL) { + return IXML_INVALID_PARAMETER; + } - if( ( element == NULL ) || ( newAttr == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (newAttr->n.ownerDocument != element->n.ownerDocument) { + return IXML_WRONG_DOCUMENT_ERR; + } - if( newAttr->n.ownerDocument != element->n.ownerDocument ) { - return IXML_WRONG_DOCUMENT_ERR; - } + if (newAttr->ownerElement != NULL) { + return IXML_INUSE_ATTRIBUTE_ERR; + } - if( newAttr->ownerElement != NULL ) { - return IXML_INUSE_ATTRIBUTE_ERR; - } + newAttr->ownerElement = element; + node = (IXML_Node *)newAttr; - newAttr->ownerElement = element; - node = ( IXML_Node * ) newAttr; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, node->nodeName) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, node->nodeName ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } + if (attrNode != NULL) { + /* Already present, will replace by newAttr */ + preSib = attrNode->prevSibling; + nextSib = attrNode->nextSibling; + if (preSib != NULL) { + preSib->nextSibling = node; + } + if (nextSib != NULL) { + nextSib->prevSibling = node; + } + if (element->n.firstAttr == attrNode) { + element->n.firstAttr = node; + } + if (rtAttr != NULL) { + *rtAttr = (IXML_Attr *)attrNode; + } + } else { + /* Add this attribute */ + if (element->n.firstAttr != NULL) { + prevAttr = element->n.firstAttr; + nextAttr = prevAttr->nextSibling; + while (nextAttr != NULL) { + prevAttr = nextAttr; + nextAttr = prevAttr->nextSibling; + } + prevAttr->nextSibling = node; + node->prevSibling = prevAttr; + } else { + /* This is the first attribute node */ + element->n.firstAttr = node; + node->prevSibling = NULL; + node->nextSibling = NULL; + } - if( attrNode != NULL ) // already present, will replace by newAttr - { - preSib = attrNode->prevSibling; - nextSib = attrNode->nextSibling; + if (rtAttr != NULL) { + *rtAttr = NULL; + } + } - if( preSib != NULL ) { - preSib->nextSibling = node; - } - - if( nextSib != NULL ) { - nextSib->prevSibling = node; - } - - if( element->n.firstAttr == attrNode ) { - element->n.firstAttr = node; - } - - if( rtAttr != NULL ) { - *rtAttr = ( IXML_Attr * ) attrNode; - } - } else // add this attribute - { - if( element->n.firstAttr != NULL ) { - prevAttr = element->n.firstAttr; - nextAttr = prevAttr->nextSibling; - while( nextAttr != NULL ) { - prevAttr = nextAttr; - nextAttr = prevAttr->nextSibling; - } - prevAttr->nextSibling = node; - node->prevSibling = prevAttr; - } else // this is the first attribute node - { - element->n.firstAttr = node; - node->prevSibling = NULL; - node->nextSibling = NULL; - } - - if( rtAttr != NULL ) { - *rtAttr = NULL; - } - } - - return IXML_SUCCESS; + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_findAttributeNode -* Find a attribute node whose contents are the same as the oldAttr. -* Internal only to parser. -* Parameter: -* oldAttr: the attribute node to match -* Return: -* if found it, the attribute node is returned, -* otherwise, return NULL. -* -*=================================================================*/ -IXML_Node * -ixmlElement_findAttributeNode( IN IXML_Element * element, - IN IXML_Attr * oldAttr ) +/*! + * \brief Find a attribute node whose contents are the same as the oldAttr. + * + * \return If found, the attribute node is returned, otherwise \b NULL is + * returned. + */ +static IXML_Node *ixmlElement_findAttributeNode( + /*! [in] The element to search for the attribute. */ + IXML_Element *element, + /*! [in] The attribute node to match. */ + IXML_Attr *oldAttr) { - IXML_Node *attrNode; - IXML_Node *oldAttrNode = ( IXML_Node * ) oldAttr; + IXML_Node *attrNode; + IXML_Node *oldAttrNode = (IXML_Node *)oldAttr; - assert( ( element != NULL ) && ( oldAttr != NULL ) ); + assert(element != NULL && oldAttr != NULL); - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { // parentNode, prevSib, nextSib and ownerDocument doesn't matter - if( ixmlNode_compare( attrNode, oldAttrNode ) == TRUE ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } - - return attrNode; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + /* parentNode, prevSib, nextSib and ownerDocument doesn't matter */ + if (ixmlNode_compare(attrNode, oldAttrNode) == TRUE) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + return attrNode; } -/*================================================================ -* ixmlElement_removeAttributeNode -* Removes the specified attribute node. -* External function. -* -* Parameters: -* oldAttr: the attr node to remove from the attribute list. -* -* Return Value: -* IXML_SUCCESS or failure -* -*=================================================================*/ -int -ixmlElement_removeAttributeNode( IN IXML_Element * element, - IN IXML_Attr * oldAttr, - OUT IXML_Attr ** rtAttr ) + +int ixmlElement_removeAttributeNode( + IXML_Element *element, + IXML_Attr *oldAttr, + IXML_Attr **rtAttr) { - IXML_Node *attrNode; - IXML_Node *preSib, - *nextSib; + IXML_Node *attrNode; + IXML_Node *preSib; + IXML_Node *nextSib; - if( ( element == NULL ) || ( oldAttr == NULL ) ) { - return IXML_INVALID_PARAMETER; - } - - attrNode = ixmlElement_findAttributeNode( element, oldAttr ); - if( attrNode != NULL ) { // has the attribute - preSib = attrNode->prevSibling; - nextSib = attrNode->nextSibling; - - if( preSib != NULL ) { - preSib->nextSibling = nextSib; - } - - if( nextSib != NULL ) { - nextSib->prevSibling = preSib; - } - - if( element->n.firstAttr == attrNode ) { - element->n.firstAttr = nextSib; - } - - /* ( IXML_Attr * ) */ attrNode->parentNode = NULL; - /* ( IXML_Attr * ) */ attrNode->prevSibling = NULL; - /* ( IXML_Attr * ) */ attrNode->nextSibling = NULL; - *rtAttr = ( IXML_Attr * ) attrNode; - return IXML_SUCCESS; - - } else { - return IXML_NOT_FOUND_ERR; - } + if(element == NULL || oldAttr == NULL) { + return IXML_INVALID_PARAMETER; + } + attrNode = ixmlElement_findAttributeNode( element, oldAttr ); + if (attrNode != NULL) { + /* Has the attribute */ + preSib = attrNode->prevSibling; + nextSib = attrNode->nextSibling; + if (preSib != NULL) { + preSib->nextSibling = nextSib; + } + if (nextSib != NULL) { + nextSib->prevSibling = preSib; + } + if (element->n.firstAttr == attrNode) { + element->n.firstAttr = nextSib; + } + attrNode->parentNode = NULL; + attrNode->prevSibling = NULL; + attrNode->nextSibling = NULL; + *rtAttr = (IXML_Attr *)attrNode; + return IXML_SUCCESS; + } else { + return IXML_NOT_FOUND_ERR; + } } -/*================================================================ -* ixmlElement_getElementsByTagName -* Returns a nodeList of all descendant Elements with a given -* tag name, in the order in which they are encountered in a preorder -* traversal of this element tree. -* External function. -* -* Parameters: -* tagName: the name of the tag to match on. The special value "*" -* matches all tags. -* -* Return Value: -* a nodeList of matching element nodes. -* -*=================================================================*/ -IXML_NodeList * -ixmlElement_getElementsByTagName( IN IXML_Element * element, - IN const char *tagName ) -{ - IXML_NodeList *returnNodeList = NULL; - if( ( element != NULL ) && ( tagName != NULL ) ) { - ixmlNode_getElementsByTagName( ( IXML_Node * ) element, tagName, - &returnNodeList ); - } - return returnNodeList; +IXML_NodeList *ixmlElement_getElementsByTagName( + IXML_Element *element, + const DOMString tagName) +{ + IXML_NodeList *returnNodeList = NULL; + + if (element != NULL && tagName != NULL) { + ixmlNode_getElementsByTagName( + (IXML_Node *)element, tagName, &returnNodeList); + } + return returnNodeList; } -/*================================================================ -* ixmlElement_getAttributeNS -* Retrieves an attribute value by local name and namespace URI. -* External function. -* -* Parameters: -* namespaceURI: the namespace URI of the attribute to retrieve. -* localName: the local name of the attribute to retrieve. -* -* Return Value: -* the attr value as a string, or NULL if that attribute does -* not have the specified value. -* -*=================================================================*/ -const DOMString -ixmlElement_getAttributeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +const DOMString ixmlElement_getAttributeNS( + IN IXML_Element *element, + IN const DOMString namespaceURI, + IN const DOMString localName) { - IXML_Node *attrNode; + IXML_Node *attrNode; - if( ( element == NULL ) || ( namespaceURI == NULL ) - || ( localName == NULL ) ) { - return NULL; - } + if (element == NULL || namespaceURI == NULL || localName == NULL) { + return NULL; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, localName ) == 0 && strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { // found it - return attrNode->nodeValue; - } else { - attrNode = attrNode->nextSibling; - } - } - - return NULL; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + /* Found it */ + return attrNode->nodeValue; + } else { + attrNode = attrNode->nextSibling; + } + } + return NULL; } -/*================================================================ -* ixmlElement_setAttributeNS -* Adds a new attribute. If an attribute with the same local name -* and namespace URI is already present on the element, its prefix -* is changed to be the prefix part of the qualifiedName, and its -* value is changed to be the value parameter. This value is a -* simple string. -* External function. -* -* Parameter: -* namespaceURI: the namespace of the attribute to create or alter. -* qualifiedName: the qualified name of the attribute to create or alter. -* value: the value to set in string form. -* -* Return Value: -* IXML_SUCCESS or failure -* -*=================================================================*/ -int -ixmlElement_setAttributeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString qualifiedName, - IN const DOMString value ) + +int ixmlElement_setAttributeNS( + IXML_Element *element, + const DOMString namespaceURI, + const DOMString qualifiedName, + const DOMString value) { - IXML_Node *attrNode = NULL; - IXML_Node newAttrNode; - IXML_Attr *newAttr; - int rc; + IXML_Node *attrNode = NULL; + IXML_Node newAttrNode; + IXML_Attr *newAttr; + int rc; - if( ( element == NULL ) || ( namespaceURI == NULL ) || - ( qualifiedName == NULL ) || ( value == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (element == NULL || namespaceURI == NULL || qualifiedName == NULL || + value == NULL) { + return IXML_INVALID_PARAMETER; + } - if( Parser_isValidXmlName( qualifiedName ) == FALSE ) { - return IXML_INVALID_CHARACTER_ERR; - } + if (Parser_isValidXmlName(qualifiedName) == FALSE) { + return IXML_INVALID_CHARACTER_ERR; + } - ixmlNode_init( &newAttrNode ); + ixmlNode_init(&newAttrNode); + newAttrNode.nodeName = strdup(qualifiedName); + if (newAttrNode.nodeName == NULL) { + return IXML_INSUFFICIENT_MEMORY; + } - newAttrNode.nodeName = strdup( qualifiedName ); - if( newAttrNode.nodeName == NULL ) { - return IXML_INSUFFICIENT_MEMORY; - } + rc = Parser_setNodePrefixAndLocalName(&newAttrNode); + if (rc != IXML_SUCCESS) { + Parser_freeNodeContent(&newAttrNode); + return rc; + } - rc = Parser_setNodePrefixAndLocalName( &newAttrNode ); - if( rc != IXML_SUCCESS ) { - Parser_freeNodeContent( &newAttrNode ); - return rc; - } - // see DOM 2 spec page 59 - if( ( newAttrNode.prefix != NULL && namespaceURI == NULL ) || - ( strcmp( newAttrNode.prefix, "xml" ) == 0 && - strcmp( namespaceURI, - "http://www.w3.org/XML/1998/namespace" ) != 0 ) - || ( strcmp( qualifiedName, "xmlns" ) == 0 - && strcmp( namespaceURI, - "http://www.w3.org/2000/xmlns/" ) != 0 ) ) { - Parser_freeNodeContent( &newAttrNode ); - return IXML_NAMESPACE_ERR; - } + /* see DOM 2 spec page 59 */ + if ((newAttrNode.prefix != NULL && namespaceURI == NULL) || + (strcmp(newAttrNode.prefix, "xml") == 0 && + strcmp(namespaceURI, "http://www.w3.org/XML/1998/namespace") != 0) || + (strcmp(qualifiedName, "xmlns") == 0 && + strcmp(namespaceURI, "http://www.w3.org/2000/xmlns/") != 0)) { + Parser_freeNodeContent( &newAttrNode ); + return IXML_NAMESPACE_ERR; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, newAttrNode.localName ) == 0 && - strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, newAttrNode.localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + if (attrNode != NULL) { + if (attrNode->prefix != NULL) { + /* Remove the old prefix */ + free(attrNode->prefix); + } + /* replace it with the new prefix */ + attrNode->prefix = strdup( newAttrNode.prefix ); + if (attrNode->prefix == NULL) { + Parser_freeNodeContent(&newAttrNode); + return IXML_INSUFFICIENT_MEMORY; + } - if( attrNode != NULL ) { - if( attrNode->prefix != NULL ) { - free( attrNode->prefix ); // remove the old prefix - } - // replace it with the new prefix - attrNode->prefix = strdup( newAttrNode.prefix ); - if( attrNode->prefix == NULL ) { - Parser_freeNodeContent( &newAttrNode ); - return IXML_INSUFFICIENT_MEMORY; - } + if (attrNode->nodeValue != NULL) { + free(attrNode->nodeValue); + } + attrNode->nodeValue = strdup(value); + if (attrNode->nodeValue == NULL) { + free(attrNode->prefix); + Parser_freeNodeContent(&newAttrNode); + return IXML_INSUFFICIENT_MEMORY; + } + } else { + /* Add a new attribute */ + rc = ixmlDocument_createAttributeNSEx( + (IXML_Document *)element->n.ownerDocument, + namespaceURI, + qualifiedName, + &newAttr); + if (rc != IXML_SUCCESS) { + return rc; + } + newAttr->n.nodeValue = strdup(value); + if (newAttr->n.nodeValue == NULL) { + ixmlAttr_free(newAttr); + return IXML_INSUFFICIENT_MEMORY; + } + if (ixmlElement_setAttributeNodeNS(element, newAttr, NULL) != IXML_SUCCESS) { + ixmlAttr_free(newAttr); + return IXML_FAILED; + } + } + Parser_freeNodeContent(&newAttrNode); - if( attrNode->nodeValue != NULL ) { - free( attrNode->nodeValue ); - } - - attrNode->nodeValue = strdup( value ); - if( attrNode->nodeValue == NULL ) { - free( attrNode->prefix ); - Parser_freeNodeContent( &newAttrNode ); - return IXML_INSUFFICIENT_MEMORY; - } - - } else { - // add a new attribute - rc = ixmlDocument_createAttributeNSEx( ( IXML_Document * ) - element->n.ownerDocument, - namespaceURI, qualifiedName, - &newAttr ); - if( rc != IXML_SUCCESS ) { - return rc; - } - - newAttr->n.nodeValue = strdup( value ); - if( newAttr->n.nodeValue == NULL ) { - ixmlAttr_free( newAttr ); - return IXML_INSUFFICIENT_MEMORY; - } - - if( ixmlElement_setAttributeNodeNS( element, newAttr, NULL ) != - IXML_SUCCESS ) { - ixmlAttr_free( newAttr ); - return IXML_FAILED; - } - - } - - Parser_freeNodeContent( &newAttrNode ); - return IXML_SUCCESS; + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_removeAttributeNS -* Removes an attribute by local name and namespace URI. The replacing -* attribute has the same namespace URI and local name, as well as -* the original prefix. -* External function. -* -* Parameters: -* namespaceURI: the namespace URI of the attribute to remove. -* localName: the local name of the atribute to remove. -* -* Return Value: -* IXML_SUCCESS or failure. -* -*=================================================================*/ -int -ixmlElement_removeAttributeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +int ixmlElement_removeAttributeNS( + IXML_Element *element, + const DOMString namespaceURI, + const DOMString localName) { - IXML_Node *attrNode; + IXML_Node *attrNode = NULL; - if( ( element == NULL ) || ( namespaceURI == NULL ) - || ( localName == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (element == NULL || namespaceURI == NULL || localName == NULL) { + return IXML_INVALID_PARAMETER; + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, localName ) == 0 && - strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } - - if( attrNode != NULL ) { // has the attribute - if( attrNode->nodeValue != NULL ) { - free( attrNode->nodeValue ); - attrNode->nodeValue = NULL; - } - } - - return IXML_SUCCESS; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + if(attrNode != NULL) { + /* Has the attribute */ + if(attrNode->nodeValue != NULL) { + free(attrNode->nodeValue); + attrNode->nodeValue = NULL; + } + } + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_getAttributeNodeNS -* Retrieves an attr node by local name and namespace URI. -* External function. -* -* Parameter: -* namespaceURI: the namespace of the attribute to retrieve. -* localName: the local name of the attribute to retrieve. -* -* Return Value: -* The attr node with the specified attribute local name and -* namespace URI or null if there is no such attribute. -* -*=================================================================*/ -IXML_Attr * -ixmlElement_getAttributeNodeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +IXML_Attr *ixmlElement_getAttributeNodeNS( + IXML_Element *element, + const DOMString namespaceURI, + const DOMString localName) { + IXML_Node *attrNode = NULL; - IXML_Node *attrNode; + if (element == NULL || namespaceURI == NULL || localName == NULL) { + return NULL; + } - if( ( element == NULL ) || ( namespaceURI == NULL ) - || ( localName == NULL ) ) { - return NULL; - } - - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, localName ) == 0 && strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { // found it - break; - } else { - attrNode = attrNode->nextSibling; - } - } - - return ( IXML_Attr * ) attrNode; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + // found it + break; + } else { + attrNode = attrNode->nextSibling; + } + } + return (IXML_Attr *)attrNode; } -/*================================================================ -* ixmlElement_setAttributeNodeNS -* Adds a new attribute. If an attribute with that local name and -* that namespace URI is already present in the element, it is replaced -* by the new one. -* External function. -* -* Parameter: -* newAttr: the attr node to add to the attribute list. -* -* Return Value: -* If the newAttr attribute replaces an existing attribute with the -* same local name and namespace, the replaced attr node is returned, -* otherwise null is returned. -* -*=================================================================*/ -int -ixmlElement_setAttributeNodeNS( IN IXML_Element * element, - IN IXML_Attr * newAttr, - OUT IXML_Attr ** rtAttr ) + +int ixmlElement_setAttributeNodeNS( + IN IXML_Element *element, + IN IXML_Attr *newAttr, + OUT IXML_Attr **rtAttr) { - IXML_Node *attrNode; - IXML_Node *node; - IXML_Node *prevAttr = NULL, - *nextAttr = NULL; - IXML_Node *preSib, - *nextSib; + IXML_Node *attrNode = NULL; + IXML_Node *node = NULL; + IXML_Node *prevAttr = NULL; + IXML_Node *nextAttr = NULL; + IXML_Node *preSib = NULL; + IXML_Node *nextSib = NULL; - if( ( element == NULL ) || ( newAttr == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (element == NULL || newAttr == NULL) { + return IXML_INVALID_PARAMETER; + } - if( newAttr->n.ownerDocument != element->n.ownerDocument ) { - return IXML_WRONG_DOCUMENT_ERR; - } + if (newAttr->n.ownerDocument != element->n.ownerDocument) { + return IXML_WRONG_DOCUMENT_ERR; + } - if( ( newAttr->ownerElement != NULL ) - && ( newAttr->ownerElement != element ) ) { - return IXML_INUSE_ATTRIBUTE_ERR; - } + if (newAttr->ownerElement != NULL && newAttr->ownerElement != element) { + return IXML_INUSE_ATTRIBUTE_ERR; + } - newAttr->ownerElement = element; - node = ( IXML_Node * ) newAttr; + newAttr->ownerElement = element; + node = (IXML_Node *)newAttr; + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, node->localName) == 0 && + strcmp(attrNode->namespaceURI, node->namespaceURI) == 0) { + /* Found it */ + break; + } else { + attrNode = attrNode->nextSibling; + } + } + if (attrNode != NULL) { + /* already present, will replace by newAttr */ + preSib = attrNode->prevSibling; + nextSib = attrNode->nextSibling; + if (preSib != NULL) { + preSib->nextSibling = node; + } + if (nextSib != NULL) { + nextSib->prevSibling = node; + } + if (element->n.firstAttr == attrNode) { + element->n.firstAttr = node; + } + *rtAttr = (IXML_Attr *)attrNode; - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, node->localName ) == 0 && - strcmp( attrNode->namespaceURI, node->namespaceURI ) == 0 ) { - break; //found it - } else { - attrNode = attrNode->nextSibling; - } - } + } else { + /* Add this attribute */ + if (element->n.firstAttr != NULL) { + /* Element has attribute already */ + prevAttr = element->n.firstAttr; + nextAttr = prevAttr->nextSibling; + while (nextAttr != NULL) { + prevAttr = nextAttr; + nextAttr = prevAttr->nextSibling; + } + prevAttr->nextSibling = node; + } else { + /* This is the first attribute node */ + element->n.firstAttr = node; + node->prevSibling = NULL; + node->nextSibling = NULL; + } + if (rtAttr != NULL) { + *rtAttr = NULL; + } + } - if( attrNode != NULL ) // already present, will replace by newAttr - { - preSib = attrNode->prevSibling; - nextSib = attrNode->nextSibling; - - if( preSib != NULL ) { - preSib->nextSibling = node; - } - - if( nextSib != NULL ) { - nextSib->prevSibling = node; - } - - if( element->n.firstAttr == attrNode ) { - element->n.firstAttr = node; - } - - *rtAttr = ( IXML_Attr * ) attrNode; - - } else // add this attribute - { - if( element->n.firstAttr != NULL ) // element has attribute already - { - prevAttr = element->n.firstAttr; - nextAttr = prevAttr->nextSibling; - while( nextAttr != NULL ) { - prevAttr = nextAttr; - nextAttr = prevAttr->nextSibling; - } - prevAttr->nextSibling = node; - } else // this is the first attribute node - { - element->n.firstAttr = node; - node->prevSibling = NULL; - node->nextSibling = NULL; - } - - if( rtAttr != NULL ) { - *rtAttr = NULL; - } - } - - return IXML_SUCCESS; + return IXML_SUCCESS; } -/*================================================================ -* ixmlElement_getElementsByTagNameNS -* Returns a nodeList of all the descendant Elements with a given -* local name and namespace in the order in which they are encountered -* in a preorder traversal of the element tree. -* External function. -* -* Parameters: -* namespaceURI: the namespace URI of the elements to match on. The -* special value "*" matches all namespaces. -* localName: the local name of the elements to match on. The special -* value "*" matches all local names. -* -* Return Value: -* A new nodeList object containing all the matched Elements. -* -*=================================================================*/ -IXML_NodeList * -ixmlElement_getElementsByTagNameNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +IXML_NodeList *ixmlElement_getElementsByTagNameNS( + IXML_Element *element, + const DOMString namespaceURI, + const DOMString localName) { - IXML_Node *node = ( IXML_Node * ) element; - IXML_NodeList *nodeList = NULL; + IXML_Node *node = (IXML_Node *)element; + IXML_NodeList *nodeList = NULL; - if( ( element != NULL ) && ( namespaceURI != NULL ) - && ( localName != NULL ) ) { - ixmlNode_getElementsByTagNameNS( node, namespaceURI, localName, - &nodeList ); - } + if(element != NULL && namespaceURI != NULL && localName != NULL) { + ixmlNode_getElementsByTagNameNS( + node, namespaceURI, localName, &nodeList); + } - return nodeList; + return nodeList; } -/*================================================================ -* ixmlElement_hasAttribute -* Returns true when an attribute with a given name is specified on -* this element, false otherwise. -* External function. -* -* Parameters: -* name: the name of the attribute to look for. -* -* Return Value: -* ture if an attribute with the given name is specified on this -* element, false otherwise. -* -*=================================================================*/ -BOOL -ixmlElement_hasAttribute( IN IXML_Element * element, - IN const DOMString name ) + +BOOL ixmlElement_hasAttribute( + IXML_Element *element, + const DOMString name) { + IXML_Node *attrNode = NULL; - IXML_Node *attrNode; + if (element == NULL || name == NULL) { + return FALSE; + } - if( ( element == NULL ) || ( name == NULL ) ) { - return FALSE; - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->nodeName, name) == 0) { + return TRUE; + } else { + attrNode = attrNode->nextSibling; + } + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->nodeName, name ) == 0 ) { - return TRUE; - } else { - attrNode = attrNode->nextSibling; - } - } - - return FALSE; + return FALSE; } -/*================================================================ -* ixmlElement_hasAttributeNS -* Returns true when attribute with a given local name and namespace -* URI is specified on this element, false otherwise. -* External function. -* -* Parameters: -* namespaceURI: the namespace URI of the attribute to look for. -* localName: the local name of the attribute to look for. -* -* Return Value: -* true if an attribute with the given local name and namespace URI -* is specified, false otherwise. -* -*=================================================================*/ -BOOL -ixmlElement_hasAttributeNS( IN IXML_Element * element, - IN const DOMString namespaceURI, - IN const DOMString localName ) + +BOOL ixmlElement_hasAttributeNS( + IXML_Element * element, + const DOMString namespaceURI, + const DOMString localName ) { + IXML_Node *attrNode = NULL; - IXML_Node *attrNode; + if (element == NULL || namespaceURI == NULL || localName == NULL) { + return FALSE; + } - if( ( element == NULL ) || ( namespaceURI == NULL ) - || ( localName == NULL ) ) { - return FALSE; - } + attrNode = element->n.firstAttr; + while (attrNode != NULL) { + if (strcmp(attrNode->localName, localName) == 0 && + strcmp(attrNode->namespaceURI, namespaceURI) == 0) { + return TRUE; + } else { + attrNode = attrNode->nextSibling; + } + } - attrNode = element->n.firstAttr; - while( attrNode != NULL ) { - if( strcmp( attrNode->localName, localName ) == 0 && - strcmp( attrNode->namespaceURI, namespaceURI ) == 0 ) { - return TRUE; - } else { - attrNode = attrNode->nextSibling; - } - } - - return FALSE; + return FALSE; } -/*================================================================ -* ixmlElement_free -* frees a element node. -* External function. -* -*=================================================================*/ -void -ixmlElement_free( IN IXML_Element * element ) + +void ixmlElement_free(IXML_Element *element) { - if( element != NULL ) { - ixmlNode_free( ( IXML_Node * ) element ); - } + if (element != NULL) { + ixmlNode_free((IXML_Node *)element); + } } + diff --git a/ixml/src/inc/ixmlmembuf.h b/ixml/src/inc/ixmlmembuf.h index 25b7c9f..246f5ac 100644 --- a/ixml/src/inc/ixmlmembuf.h +++ b/ixml/src/inc/ixmlmembuf.h @@ -1,73 +1,173 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/************************************************************************** + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************/ + + +#ifndef IXML_MEMBUF_H +#define IXML_MEMBUF_H + + +/*! + * \file + */ -#ifndef _IXML_MEMBUF_H -#define _IXML_MEMBUF_H -#include #include "ixml.h" -#define MINVAL( a, b ) ( (a) < (b) ? (a) : (b) ) -#define MAXVAL( a, b ) ( (a) > (b) ? (a) : (b) ) + +#include /* for size_t */ + + +#define MINVAL(a, b) ( (a) < (b) ? (a) : (b) ) +#define MAXVAL(a, b) ( (a) > (b) ? (a) : (b) ) + #define MEMBUF_DEF_SIZE_INC 20 -typedef struct // ixml_membuf +/*! + * \brief The ixml_membuf type. + */ +typedef struct { - char *buf; - - size_t length; - size_t capacity; - size_t size_inc; - + char *buf; + size_t length; + size_t capacity; + size_t size_inc; } ixml_membuf; -//-------------------------------------------------- -//////////////// functions ///////////////////////// -//-------------------------------------------------- -/* -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus -*/ -void ixml_membuf_init(INOUT ixml_membuf *m); -void ixml_membuf_destroy(INOUT ixml_membuf *m); -int ixml_membuf_assign(INOUT ixml_membuf *m, IN const void *buf, - IN size_t buf_len ); -int ixml_membuf_assign_str(INOUT ixml_membuf *m, IN const char *c_str ); -int ixml_membuf_append(INOUT ixml_membuf *m, IN const void *buf); -int ixml_membuf_append_str(INOUT ixml_membuf *m, IN const char *c_str); -int ixml_membuf_insert(INOUT ixml_membuf *m, IN const void* buf, - IN size_t buf_len, int index ); +/*! + * \brief ixml_membuf initialization routine. + */ +void ixml_membuf_init( + /*! [in,out] The memory buffer to initializa. */ + ixml_membuf *m); + + +/*! + * \brief ixml_membuf clearing routine. + * + * The internal buffer is deleted and ixml_membuf_init() is called in the end + * to reinitialize the buffer. + */ +void ixml_membuf_destroy( + /*! [in,out] The memory buffer to clear. */ + ixml_membuf *m); + + +/*! + * \brief Copies the contents o a buffer to the designated ixml_membuf. + * + * The previous contents of the ixml_membuf are destroyed. + * + * \return IXML_SUCCESS if successfull, or the error code returned + * by ixml_membuf_set_size(). + * + * \sa ixml_membuf_assign_str(). + */ +int ixml_membuf_assign( + /*! [in,out] The memory buffer on which to operate. */ + ixml_membuf *m, + /*! [in] The input buffer to copy from. */ + const void *buf, + /*! [in] The number of bytes to copy from the input buffer. */ + size_t buf_len); + +/*! + * \brief Copies a \b NULL terminated string to the ixml_buffer. + * + * This is a convenience function that internally uses ixml_membuf_assign(). + * + * \return The return value of ixml_membuf_assign(). + * + * \sa ixml_membuf_assign(). + */ +int ixml_membuf_assign_str( + /*! [in,out] The memory buffer on which to operate. */ + ixml_membuf *m, + /*! [in] The input string to copy from. */ + const char *c_str); + +/*! + * \brief Appends one byte to the designated ixml_membuffer. + * + * This is a convenience function that internally uses ixml_membuf_insert(). + * + * \return The return value of ixml_membuf_insert(). + * + * \sa ixml_membuf_insert() + */ +int ixml_membuf_append( + /*! [in,out] The memory buffer on which to operate. */ + ixml_membuf *m, + /*! [in] The pointer to the byte to append. */ + const void *buf); + +/*! + * \brief Appends the contents of a \b NULL terminated string to the designated + * ixml_membuf. + * + * This is a convenience function that internally uses ixml_membuf_insert(). + * + * \return The return value of ixml_membuf_insert(). + * + * \sa ixml_membuf_insert(). + */ +int ixml_membuf_append_str( + /*! [in,out] The memory buffer on which to operate. */ + ixml_membuf *m, + /*! [in] The input string to copy from. */ + const char *c_str); + +/*! + * \brief + * + * \return + * \li 0 if successfull. + * \li IXML_INDEX_SIZE_ERR if the index parameter is out of range. + * \li Or the return code of ixml_membuf_set_size() + * + * \sa ixml_membuf_set_size() + */ +int ixml_membuf_insert( + /*! [in,out] The memory buffer on which to operate. */ + ixml_membuf *m, + /*! [in] The pointer to the input buffer. */ + const void *buf, + /*! [in] The buffer length. */ + size_t buf_len, + /*! [in] The point of insertion relative to the beggining of the + * ixml_membuf internal buffer. */ + int index); + + +#endif /* IXML_MEMBUF_H */ -#endif // _IXML_MEMBUF_H diff --git a/ixml/src/inc/ixmlparser.h b/ixml/src/inc/ixmlparser.h index 06151ec..a58ba89 100644 --- a/ixml/src/inc/ixmlparser.h +++ b/ixml/src/inc/ixmlparser.h @@ -1,41 +1,49 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// - -#ifndef _IXMLPARSER_H -#define _IXMLPARSER_H +/************************************************************************** + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************/ + + +#ifndef IXMLPARSER_H +#define IXMLPARSER_H + + +/*! + * \file + */ + #include "ixml.h" #include "ixmlmembuf.h" -// Parser definitions + +/* Parser definitions */ #define QUOT """ #define LT "<" #define GT ">" @@ -44,77 +52,218 @@ #define ESC_HEX "&#x" #define ESC_DEC "&#" + typedef struct _IXML_NamespaceURI { - char *nsURI; - char *prefix; - struct _IXML_NamespaceURI *nextNsURI; + char *nsURI; + char *prefix; + struct _IXML_NamespaceURI *nextNsURI; } IXML_NamespaceURI; typedef struct _IXML_ElementStack { - char *element; - char *prefix; - char *namespaceUri; - IXML_NamespaceURI *pNsURI; - struct _IXML_ElementStack *nextElement; + char *element; + char *prefix; + char *namespaceUri; + IXML_NamespaceURI *pNsURI; + struct _IXML_ElementStack *nextElement; } IXML_ElementStack; typedef enum { - eELEMENT, - eATTRIBUTE, - eCONTENT, + eELEMENT, + eATTRIBUTE, + eCONTENT, } PARSER_STATE; + typedef struct _Parser { - char *dataBuffer; //data buffer - char *curPtr; //ptr to the token parsed - char *savePtr; //Saves for backup - ixml_membuf lastElem; - ixml_membuf tokenBuf; - - IXML_Node *pNeedPrefixNode; - IXML_ElementStack *pCurElement; - IXML_Node *currentNodePtr; - PARSER_STATE state; - - BOOL bHasTopLevel; - + /*! Data buffer. */ + char *dataBuffer; + /*! Pointer to the token parsed. */ + char *curPtr; + /*! Saves for backup. */ + char *savePtr; + ixml_membuf lastElem; + ixml_membuf tokenBuf; + IXML_Node *pNeedPrefixNode; + IXML_ElementStack *pCurElement; + IXML_Node *currentNodePtr; + PARSER_STATE state; + BOOL bHasTopLevel; } Parser; +/*! + * \brief Check to see whether name is a valid xml name. + */ +BOOL Parser_isValidXmlName( + /*! [in] The string to be checked. */ + const DOMString name); -int Parser_LoadDocument( IXML_Document **retDoc, const char * xmlFile, BOOL file); -BOOL Parser_isValidXmlName( const DOMString name); -int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr); -void Parser_freeNodeContent( IXML_Node *IXML_Nodeptr); -void Parser_setErrorChar( char c ); +/*! + * \brief Sets the error character. + * + * If 'c' is 0 (default), the parser is strict about XML encoding: + * invalid UTF-8 sequences or "&" entities are rejected, and the parsing + * aborts. + * + * If 'c' is not 0, the parser is relaxed: invalid UTF-8 characters + * are replaced by this character, and invalid "&" entities are left + * untranslated. The parsing is then allowed to continue. + */ +void Parser_setErrorChar( + /*! [in] The character to become the error character. */ + char c); -void ixmlAttr_free(IXML_Attr *attrNode); -void ixmlAttr_init(IXML_Attr *attrNode); -int ixmlElement_setTagName(IXML_Element *element, const char *tagName); +/*! + * \brief Fees a node contents. + */ +void Parser_freeNodeContent( + /*! [in] The Node to process. */ + IXML_Node *IXML_Nodeptr); -void ixmlNamedNodeMap_init(IXML_NamedNodeMap *nnMap); -int ixmlNamedNodeMap_addToNamedNodeMap(IXML_NamedNodeMap **nnMap, IXML_Node *add); +int Parser_LoadDocument(IXML_Document **retDoc, const char * xmlFile, BOOL file); -void ixmlNode_init(IXML_Node *IXML_Nodeptr); -BOOL ixmlNode_compare(IXML_Node *srcIXML_Node, IXML_Node *destIXML_Node); +int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr); -void ixmlNode_getElementsByTagName( IXML_Node *n, const char *tagname, IXML_NodeList **list); -void ixmlNode_getElementsByTagNameNS( IXML_Node *IXML_Node, const char *namespaceURI, - const char *localName, IXML_NodeList **list); -int ixmlNode_setNodeProperties(IXML_Node* node, IXML_Node *src); -int ixmlNode_setNodeName( IXML_Node* node, const DOMString qualifiedName); +void ixmlAttr_init(IXML_Attr *attrNode); -void ixmlNodeList_init(IXML_NodeList *nList); -int ixmlNodeList_addToNodeList(IXML_NodeList **nList, IXML_Node *add); +/*! + * \brief Set the given element's tagName. + * + * \return One of the following: + * \li \b IXML_SUCCESS, if successfull. + * \li \b IXML_FAILED, if element of tagname is \b NULL. + * \li \b IXML_INSUFFICIENT_MEMORY, if there is no memory to allocate the + * buffer for the element's tagname. + */ +int ixmlElement_setTagName( + /*! [in] The element to change the tagname. */ + IXML_Element *element, + /*! [in] The new tagName for the element. */ + const char *tagName); -#endif // _IXMLPARSER_H + +/*! + * \brief Initializes a NamedNodeMap object. + */ +void ixmlNamedNodeMap_init( + /*! [in] The named node map to process. */ + IXML_NamedNodeMap *nnMap); + + +/*! + * \brief Add a node to a NamedNodeMap. + * + * \return IXML_SUCCESS or failure. + */ +int ixmlNamedNodeMap_addToNamedNodeMap( + /* [in] The named node map. */ + IXML_NamedNodeMap **nnMap, + /* [in] The node to add. */ + IXML_Node *add); + +/*! + * \brief Add a node to nodelist. + */ +int ixmlNodeList_addToNodeList( + /*! [in] The pointer to the nodelist. */ + IXML_NodeList **nList, + /*! [in] The node to add. */ + IXML_Node *add); + + +/*! + * \brief Intializes a node. + */ +void ixmlNode_init( + /*! [in] The \b Node to iniatialize. */ + IN IXML_Node *nodeptr); + + +/*! + * \brief Compare two nodes to see whether they are the same node. + * Parent, sibling and children node are ignored. + * + * \return + * \li TRUE, the two nodes are the same. + * \li FALSE, the two nodes are not the same. + */ +BOOL ixmlNode_compare( + /*! [in] The first \b Node. */ + IXML_Node *srcNode, + /*! [in] The second \b Node. */ + IXML_Node *destNode); + + +/*! + * \brief Returns a nodeList of all descendant Elements with a given tagName, + * in the order in which they are encountered in a traversal of this element + * tree. + */ +void ixmlNode_getElementsByTagName( + /*! [in] The \b Node tree. */ + IXML_Node *n, + /*! [in] The tag name to match. */ + const char *tagname, + /*! [out] The output \b NodeList. */ + IXML_NodeList **list); + + +/*! + * \brief Returns a nodeList of all the descendant Elements with a given local + * name and namespace URI in the order in which they are encountered in a + * preorder traversal of this Elememt tree. + */ +void ixmlNode_getElementsByTagNameNS( + /*! [in] The \b Element tree. */ + IXML_Node *n, + /*! [in] The name space to match. */ + const char *namespaceURI, + /*! [in] The local name to match. */ + const char *localName, + /*! [out] The output \b NodeList. */ + IXML_NodeList **list); + + +/*! + * \brief + * + * \return + */ +int ixmlNode_setNodeName( + /*! [in] The \b Node. */ + IXML_Node *node, + /*! [in] . */ + const DOMString qualifiedName); + + +/*! + * \brief + * + * \return + */ +int ixmlNode_setNodeProperties( + /*! [in] . */ + IXML_Node *destNode, + /*! [in] . */ + IXML_Node *src); + + +/*! + * \brief Initializes a nodelist + */ +void ixmlNodeList_init( + /*! [in,out] The \b NodeList to initialize. */ + IXML_NodeList *nList); + + +#endif /* IXMLPARSER_H */ diff --git a/ixml/src/ixml.c b/ixml/src/ixml.c index 32388bb..fe9851c 100644 --- a/ixml/src/ixml.c +++ b/ixml/src/ixml.c @@ -1,531 +1,469 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/************************************************************************** + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************/ + +/*! + * \file + */ + + +#include "ixmldebug.h" #include "ixmlmembuf.h" #include "ixmlparser.h" -/*================================================================ -* copy_with_escape -* -* -*=================================================================*/ -static void -copy_with_escape( INOUT ixml_membuf * buf, - IN const char *p ) + +#include /* for free() */ +#include + + +/*! + * \brief Appends a string to a buffer, substituting some characters by escape + * sequences. + */ +static void copy_with_escape( + /*! [in,out] The input/output buffer. */ + ixml_membuf *buf, + /*! [in] The string to copy from. */ + const char *p) { - int i; - int plen; - - if( p == NULL ) - return; - - plen = strlen( p ); - - for( i = 0; i < plen; i++ ) { - switch ( p[i] ) { - case '<': - ixml_membuf_append_str( buf, "<" ); - break; - - case '>': - ixml_membuf_append_str( buf, ">" ); - break; - - case '&': - ixml_membuf_append_str( buf, "&" ); - break; - - case '\'': - ixml_membuf_append_str( buf, "'" ); - break; - - case '\"': - ixml_membuf_append_str( buf, """ ); - break; - - default: - ixml_membuf_append( buf, &p[i] ); - } - } -} - -/*================================================================ -* ixmlPrintDomTreeRecursive -* It is a recursive function to print all the node in a tree. -* Internal to parser only. -* -*=================================================================*/ -void -ixmlPrintDomTreeRecursive( IN IXML_Node * nodeptr, - IN ixml_membuf * buf ) -{ - const char *nodeName = NULL; - const char *nodeValue = NULL; - IXML_Node *child = NULL, - *sibling = NULL; - - if( nodeptr != NULL ) { - nodeName = ( const char * )ixmlNode_getNodeName( nodeptr ); - nodeValue = ixmlNode_getNodeValue( nodeptr ); - - switch ( ixmlNode_getNodeType( nodeptr ) ) { - - case eTEXT_NODE: - copy_with_escape( buf, nodeValue ); - break; - - case eCDATA_SECTION_NODE: - ixml_membuf_append_str( buf, "" ); - break; - - case ePROCESSING_INSTRUCTION_NODE: - ixml_membuf_append_str( buf, "\n" ); - break; - - case eDOCUMENT_NODE: - ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild - ( nodeptr ), buf ); - break; - - case eATTRIBUTE_NODE: - ixml_membuf_append_str( buf, nodeName ); - ixml_membuf_append_str( buf, "=\"" ); - copy_with_escape( buf, nodeValue ); - ixml_membuf_append_str( buf, "\"" ); - - if( nodeptr->nextSibling != NULL ) { - ixml_membuf_append_str( buf, " " ); - ixmlPrintDomTreeRecursive( nodeptr->nextSibling, buf ); - } - break; - - case eELEMENT_NODE: - ixml_membuf_append_str( buf, "<" ); - ixml_membuf_append_str( buf, nodeName ); - - if( nodeptr->firstAttr != NULL ) { - ixml_membuf_append_str( buf, " " ); - ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf ); - } - - child = ixmlNode_getFirstChild( nodeptr ); - if( ( child != NULL ) - && ( ixmlNode_getNodeType( child ) == - eELEMENT_NODE ) ) { - ixml_membuf_append_str( buf, ">\r\n" ); - } else { - ixml_membuf_append_str( buf, ">" ); - } - - // output the children - ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild - ( nodeptr ), buf ); - - // Done with children. Output the end tag. - ixml_membuf_append_str( buf, "" ); - } else { - ixml_membuf_append_str( buf, ">\r\n" ); - } - ixmlPrintDomTreeRecursive( ixmlNode_getNextSibling - ( nodeptr ), buf ); - break; - - default: - break; - } - } -} - -/*================================================================ -* ixmlPrintDomTree -* Print a DOM tree. -* Element, and Attribute nodes are handled differently. -* We don't want to print the Element and Attribute nodes' sibling. -* External function. -* -*=================================================================*/ -void -ixmlPrintDomTree( IN IXML_Node * nodeptr, - IN ixml_membuf * buf ) -{ - const char *nodeName = NULL; - const char *nodeValue = NULL; - IXML_Node *child = NULL; - - if( ( nodeptr == NULL ) || ( buf == NULL ) ) { - return; - } - - nodeName = ( const char * )ixmlNode_getNodeName( nodeptr ); - nodeValue = ixmlNode_getNodeValue( nodeptr ); - - switch ( ixmlNode_getNodeType( nodeptr ) ) { - - case eTEXT_NODE: - case eCDATA_SECTION_NODE: - case ePROCESSING_INSTRUCTION_NODE: - case eDOCUMENT_NODE: - ixmlPrintDomTreeRecursive( nodeptr, buf ); - break; - - case eATTRIBUTE_NODE: - ixml_membuf_append_str( buf, nodeName ); - ixml_membuf_append_str( buf, "=\"" ); - copy_with_escape( buf, nodeValue ); - ixml_membuf_append_str( buf, "\"" ); - break; - - case eELEMENT_NODE: - ixml_membuf_append_str( buf, "<" ); - ixml_membuf_append_str( buf, nodeName ); - - if( nodeptr->firstAttr != NULL ) { - ixml_membuf_append_str( buf, " " ); - ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf ); - } - - child = ixmlNode_getFirstChild( nodeptr ); - if( ( child != NULL ) - && ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) { - ixml_membuf_append_str( buf, ">\r\n" ); - } else { - ixml_membuf_append_str( buf, ">" ); - } - - // output the children - ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ), - buf ); - - // Done with children. Output the end tag. - ixml_membuf_append_str( buf, "\r\n" ); - break; - - default: - break; - } -} - -/*================================================================ -* ixmlDomTreetoString -* Converts a DOM tree into a text string -* Element, and Attribute nodes are handled differently. -* We don't want to print the Element and Attribute nodes' sibling. -* External function. -* -*=================================================================*/ -void -ixmlDomTreetoString( IN IXML_Node * nodeptr, - IN ixml_membuf * buf ) -{ - const char *nodeName = NULL; - const char *nodeValue = NULL; - IXML_Node *child = NULL; - - if( ( nodeptr == NULL ) || ( buf == NULL ) ) { - return; - } - - nodeName = ( const char * )ixmlNode_getNodeName( nodeptr ); - nodeValue = ixmlNode_getNodeValue( nodeptr ); - - switch ( ixmlNode_getNodeType( nodeptr ) ) { - - case eTEXT_NODE: - case eCDATA_SECTION_NODE: - case ePROCESSING_INSTRUCTION_NODE: - case eDOCUMENT_NODE: - ixmlPrintDomTreeRecursive( nodeptr, buf ); - break; - - case eATTRIBUTE_NODE: - ixml_membuf_append_str( buf, nodeName ); - ixml_membuf_append_str( buf, "=\"" ); - copy_with_escape( buf, nodeValue ); - ixml_membuf_append_str( buf, "\"" ); - break; - - case eELEMENT_NODE: - ixml_membuf_append_str( buf, "<" ); - ixml_membuf_append_str( buf, nodeName ); - - if( nodeptr->firstAttr != NULL ) { - ixml_membuf_append_str( buf, " " ); - ixmlPrintDomTreeRecursive( nodeptr->firstAttr, buf ); - } - - child = ixmlNode_getFirstChild( nodeptr ); - if( ( child != NULL ) - && ( ixmlNode_getNodeType( child ) == eELEMENT_NODE ) ) { - ixml_membuf_append_str( buf, ">" ); - } else { - ixml_membuf_append_str( buf, ">" ); - } - - // output the children - ixmlPrintDomTreeRecursive( ixmlNode_getFirstChild( nodeptr ), - buf ); - - // Done with children. Output the end tag. - ixml_membuf_append_str( buf, "" ); - break; - - default: - break; - } -} - -/*================================================================ -* ixmlLoadDocumentEx -* Parses the given file, and returns the DOM tree from it. -* External function. -* -*=================================================================*/ -int -ixmlLoadDocumentEx( IN const char *xmlFile, - IXML_Document ** doc ) -{ - - if( ( xmlFile == NULL ) || ( doc == NULL ) ) { - return IXML_INVALID_PARAMETER; - } - - return Parser_LoadDocument( doc, xmlFile, TRUE ); -} - -/*================================================================ -* ixmlLoadDocument -* Parses the given file, and returns the DOM tree from it. -* External function. -* -*=================================================================*/ -IXML_Document * -ixmlLoadDocument( IN const char *xmlFile ) -{ - - IXML_Document *doc = NULL; - - ixmlLoadDocumentEx( xmlFile, &doc ); - return doc; -} - -/*================================================================ -* ixmlPrintDocument -* Prints entire document, prepending XML prolog first. -* Puts lots of white spaces. -* External function. -* -*=================================================================*/ - -DOMString -ixmlPrintDocument(IXML_Document *doc) -{ - IXML_Node* rootNode = ( IXML_Node * )doc; - ixml_membuf memBuf; - ixml_membuf *buf = &memBuf; - - if( rootNode == NULL ) { - return NULL; - } - - ixml_membuf_init( buf ); - ixml_membuf_append_str( buf, "\r\n" ); - ixmlPrintDomTree( rootNode, buf ); - return buf->buf; - -} - -/*================================================================ -* ixmlPrintNode -* Print DOM tree under node. Puts lots of white spaces -* External function. -* -*=================================================================*/ -DOMString -ixmlPrintNode( IN IXML_Node * node ) -{ - - ixml_membuf memBuf; - ixml_membuf *buf = &memBuf; - - if( node == NULL ) { - return NULL; - } - - ixml_membuf_init( buf ); - ixmlPrintDomTree( node, buf ); - return buf->buf; - -} - -/*================================================================ -* ixmlDocumenttoString -* converts DOM tree under node to text string, -* prepending XML prolog first. -* External function. -* -*=================================================================*/ - -DOMString -ixmlDocumenttoString(IXML_Document *doc) -{ - IXML_Node* rootNode = ( IXML_Node * )doc; - ixml_membuf memBuf; - ixml_membuf *buf = &memBuf; - - if( rootNode == NULL ) { - return NULL; - } - - ixml_membuf_init( buf ); - ixml_membuf_append_str( buf, "\r\n" ); - ixmlDomTreetoString( rootNode, buf ); - return buf->buf; - -} - -/*================================================================ -* ixmlNodetoString -* converts DOM tree under node to text string -* External function. -* -*=================================================================*/ -DOMString -ixmlNodetoString( IN IXML_Node * node ) -{ - - ixml_membuf memBuf; - ixml_membuf *buf = &memBuf; - - if( node == NULL ) { - return NULL; - } - - ixml_membuf_init( buf ); - ixmlDomTreetoString( node, buf ); - return buf->buf; - -} - -/*================================================================ -* ixmlRelaxParser -* Makes the XML parser more tolerant to malformed text. -* External function. -* -*=================================================================*/ -void -ixmlRelaxParser(char errorChar) -{ - Parser_setErrorChar( errorChar ); + int i; + int plen; + + if (p == NULL) { + return; + } + + plen = strlen( p ); + + for (i = 0; i < plen; i++) { + switch (p[i]) { + case '<': + ixml_membuf_append_str(buf, "<"); + break; + + case '>': + ixml_membuf_append_str(buf, ">"); + break; + + case '&': + ixml_membuf_append_str(buf, "&"); + break; + + case '\'': + ixml_membuf_append_str(buf, "'"); + break; + + case '\"': + ixml_membuf_append_str(buf, """); + break; + + default: + ixml_membuf_append(buf, &p[i]); + break; + } + } } -/*================================================================ -* ixmlParseBufferEx -* Parse xml file stored in buffer. -* External function. -* -*=================================================================*/ -int -ixmlParseBufferEx( IN const char *buffer, - IXML_Document ** retDoc ) +/*! + * \brief Recursive function to print all the node in a tree. + * Internal to parser only. + */ +static void ixmlPrintDomTreeRecursive( + /*! [in] \todo documentation. */ + IXML_Node *nodeptr, + /*! [in] \todo documentation. */ + ixml_membuf *buf) { + const char *nodeName = NULL; + const char *nodeValue = NULL; + IXML_Node *child = NULL, + *sibling = NULL; - if( ( buffer == NULL ) || ( retDoc == NULL ) ) { - return IXML_INVALID_PARAMETER; - } + if (nodeptr != NULL) { + nodeName = (const char *)ixmlNode_getNodeName(nodeptr); + nodeValue = ixmlNode_getNodeValue(nodeptr); + + switch (ixmlNode_getNodeType(nodeptr)) { + case eTEXT_NODE: + copy_with_escape(buf, nodeValue); + break; - if( buffer[0] == '\0' ) { - return IXML_INVALID_PARAMETER; - } + case eCDATA_SECTION_NODE: + ixml_membuf_append_str(buf, ""); + break; - return Parser_LoadDocument( retDoc, buffer, FALSE ); + case ePROCESSING_INSTRUCTION_NODE: + ixml_membuf_append_str(buf, "\n"); + break; + + case eDOCUMENT_NODE: + ixmlPrintDomTreeRecursive( + ixmlNode_getFirstChild(nodeptr), buf); + break; + + case eATTRIBUTE_NODE: + ixml_membuf_append_str(buf, nodeName); + ixml_membuf_append_str(buf, "=\""); + copy_with_escape(buf, nodeValue); + ixml_membuf_append_str(buf, "\""); + if (nodeptr->nextSibling != NULL) { + ixml_membuf_append_str(buf, " "); + ixmlPrintDomTreeRecursive(nodeptr->nextSibling, buf); + } + break; + + case eELEMENT_NODE: + ixml_membuf_append_str(buf, "<"); + ixml_membuf_append_str(buf, nodeName); + if (nodeptr->firstAttr != NULL) { + ixml_membuf_append_str(buf, " "); + ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf); + } + child = ixmlNode_getFirstChild(nodeptr); + if (child != NULL && + ixmlNode_getNodeType(child) == eELEMENT_NODE) { + ixml_membuf_append_str(buf, ">\r\n"); + } else { + ixml_membuf_append_str(buf, ">"); + } + // output the children + ixmlPrintDomTreeRecursive( + ixmlNode_getFirstChild(nodeptr), buf); + + // Done with children. Output the end tag. + ixml_membuf_append_str(buf, "" ); + } else { + ixml_membuf_append_str( buf, ">\r\n" ); + } + ixmlPrintDomTreeRecursive( + ixmlNode_getNextSibling(nodeptr), buf); + break; + + default: + IxmlPrintf("(%s::ixmlPrintDomTreeRecursive) line %d: " + "Warning, unknown node type %d\n", + __FILE__, __LINE__, ixmlNode_getNodeType(nodeptr)); + break; + } + } } -/*================================================================ -* ixmlParseBuffer -* Parse xml file stored in buffer. -* External function. -* -*=================================================================*/ -IXML_Document * -ixmlParseBuffer( IN const char *buffer ) -{ - IXML_Document *doc = NULL; - ixmlParseBufferEx( buffer, &doc ); - return doc; +/*! + * \brief Print a DOM tree. + * + * Element, and Attribute nodes are handled differently. We don't want to print + * the Element and Attribute nodes' sibling. + */ +static void ixmlPrintDomTree( + /*! [in] \todo documentation. */ + IXML_Node *nodeptr, + /*! [in] \todo documentation. */ + ixml_membuf *buf) +{ + const char *nodeName = NULL; + const char *nodeValue = NULL; + IXML_Node *child = NULL; + + if (nodeptr == NULL || buf == NULL) { + return; + } + + nodeName = (const char *)ixmlNode_getNodeName(nodeptr); + nodeValue = ixmlNode_getNodeValue(nodeptr); + switch (ixmlNode_getNodeType(nodeptr)) { + case eTEXT_NODE: + case eCDATA_SECTION_NODE: + case ePROCESSING_INSTRUCTION_NODE: + case eDOCUMENT_NODE: + ixmlPrintDomTreeRecursive(nodeptr, buf); + break; + + case eATTRIBUTE_NODE: + ixml_membuf_append_str(buf, nodeName); + ixml_membuf_append_str(buf, "=\""); + copy_with_escape(buf, nodeValue); + ixml_membuf_append_str(buf, "\""); + break; + + case eELEMENT_NODE: + ixml_membuf_append_str(buf, "<"); + ixml_membuf_append_str(buf, nodeName); + if (nodeptr->firstAttr != NULL) { + ixml_membuf_append_str(buf, " "); + ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf); + } + child = ixmlNode_getFirstChild(nodeptr); + if (child != NULL && + ixmlNode_getNodeType(child) == eELEMENT_NODE) { + ixml_membuf_append_str(buf, ">\r\n"); + } else { + ixml_membuf_append_str(buf, ">"); + } + + // output the children + ixmlPrintDomTreeRecursive( + ixmlNode_getFirstChild(nodeptr), buf); + + // Done with children. Output the end tag. + ixml_membuf_append_str(buf, "\r\n"); + break; + + default: + IxmlPrintf("(%s::ixmlPrintDomTree) line %d: " + "Warning, unknown node type %d\n", + __FILE__, __LINE__, ixmlNode_getNodeType(nodeptr)); + break; + } } -/*================================================================ -* ixmlCloneDOMString -* Clones a DOM String. -* External function. -* -*=================================================================*/ -DOMString -ixmlCloneDOMString( IN const DOMString src ) -{ - if( src == NULL ) { - return NULL; - } - return ( strdup( src ) ); +/*! + * \brief Converts a DOM tree into a text string. + * + * Element, and Attribute nodes are handled differently. We don't want to print + * the Element and Attribute nodes' sibling. + */ +static void ixmlDomTreetoString( + /*! [in] \todo documentation. */ + IXML_Node *nodeptr, + /*! [in] \todo documentation. */ + ixml_membuf *buf) +{ + const char *nodeName = NULL; + const char *nodeValue = NULL; + IXML_Node *child = NULL; + + if (nodeptr == NULL || buf == NULL) { + return; + } + + nodeName = (const char *)ixmlNode_getNodeName(nodeptr); + nodeValue = ixmlNode_getNodeValue(nodeptr); + + switch (ixmlNode_getNodeType(nodeptr)) { + case eTEXT_NODE: + case eCDATA_SECTION_NODE: + case ePROCESSING_INSTRUCTION_NODE: + case eDOCUMENT_NODE: + ixmlPrintDomTreeRecursive(nodeptr, buf); + break; + + case eATTRIBUTE_NODE: + ixml_membuf_append_str(buf, nodeName); + ixml_membuf_append_str(buf, "=\""); + copy_with_escape(buf, nodeValue ); + ixml_membuf_append_str(buf, "\""); + break; + + case eELEMENT_NODE: + ixml_membuf_append_str(buf, "<"); + ixml_membuf_append_str(buf, nodeName); + if (nodeptr->firstAttr != NULL) { + ixml_membuf_append_str(buf, " "); + ixmlPrintDomTreeRecursive(nodeptr->firstAttr, buf); + } + child = ixmlNode_getFirstChild(nodeptr); + if (child != NULL && + ixmlNode_getNodeType(child) == eELEMENT_NODE) { + ixml_membuf_append_str(buf, ">"); + } else { + ixml_membuf_append_str(buf, ">"); + } + + // output the children + ixmlPrintDomTreeRecursive(ixmlNode_getFirstChild(nodeptr), buf); + + // Done with children. Output the end tag. + ixml_membuf_append_str(buf, ""); + break; + + default: + IxmlPrintf("(%s::ixmlDomTreetoString) line %d: " + "Warning, unknown node type %d\n", + __FILE__, __LINE__, ixmlNode_getNodeType(nodeptr)); + break; + } } -/*================================================================ -* ixmlFreeDOMString -* Frees a DOM String. -* External function. -* -*=================================================================*/ -void -ixmlFreeDOMString( IN DOMString buf ) + +int ixmlLoadDocumentEx(const char *xmlFile, IXML_Document **doc) { - if( buf != NULL ) { - free( buf ); - } + if (xmlFile == NULL || doc == NULL) { + return IXML_INVALID_PARAMETER; + } + + return Parser_LoadDocument(doc, xmlFile, TRUE); } + + +IXML_Document *ixmlLoadDocument(const char *xmlFile) +{ + IXML_Document *doc = NULL; + + ixmlLoadDocumentEx(xmlFile, &doc); + + return doc; +} + + +DOMString ixmlPrintDocument(IXML_Document *doc) +{ + IXML_Node* rootNode = (IXML_Node *)doc; + ixml_membuf memBuf; + ixml_membuf *buf = &memBuf; + + if(rootNode == NULL) { + return NULL; + } + + ixml_membuf_init(buf); + ixml_membuf_append_str(buf, "\r\n"); + ixmlPrintDomTree(rootNode, buf); + + return buf->buf; +} + + +DOMString ixmlPrintNode(IXML_Node *node) +{ + ixml_membuf memBuf; + ixml_membuf *buf = &memBuf; + + if (node == NULL) { + return NULL; + } + + ixml_membuf_init(buf); + ixmlPrintDomTree(node, buf); + + return buf->buf; +} + + +DOMString ixmlDocumenttoString(IXML_Document *doc) +{ + IXML_Node* rootNode = (IXML_Node *)doc; + ixml_membuf memBuf; + ixml_membuf *buf = &memBuf; + + if(rootNode == NULL) { + return NULL; + } + + ixml_membuf_init(buf); + ixml_membuf_append_str(buf, "\r\n"); + ixmlDomTreetoString(rootNode, buf); + + return buf->buf; +} + + +DOMString ixmlNodetoString(IXML_Node *node) +{ + ixml_membuf memBuf; + ixml_membuf *buf = &memBuf; + + if (node == NULL) { + return NULL; + } + + ixml_membuf_init(buf); + ixmlDomTreetoString(node, buf); + + return buf->buf; +} + + +void ixmlRelaxParser(char errorChar) +{ + Parser_setErrorChar(errorChar); +} + + +int ixmlParseBufferEx(const char *buffer, IXML_Document **retDoc) +{ + if (buffer == NULL || retDoc == NULL) { + return IXML_INVALID_PARAMETER; + } + + if (buffer[0] == '\0') { + return IXML_INVALID_PARAMETER; + } + + return Parser_LoadDocument(retDoc, buffer, FALSE); +} + + +IXML_Document *ixmlParseBuffer(const char *buffer) +{ + IXML_Document *doc = NULL; + + ixmlParseBufferEx(buffer, &doc); + + return doc; +} + + +DOMString ixmlCloneDOMString(const DOMString src) +{ + if (src == NULL) { + return NULL; + } + + return strdup(src); +} + + +void ixmlFreeDOMString(DOMString buf) +{ + if (buf != NULL) { + free(buf); + } +} + diff --git a/ixml/src/ixmlmembuf.c b/ixml/src/ixmlmembuf.c index 31cbac6..42b67e3 100644 --- a/ixml/src/ixmlmembuf.c +++ b/ixml/src/ixmlmembuf.c @@ -1,236 +1,218 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/************************************************************************** + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + **************************************************************************/ + + +/*! + * \file + */ + + +#include "ixmlmembuf.h" +#include "ixml.h" + #include #include #include -#include "ixmlmembuf.h" -#include "ixml.h" -/*================================================================ -* ixml_membuf_set_size -* -* Increases or decreases buffer cap so that at least -* 'new_length' bytes can be stored -* -* On error, m's fields do not change. -* -* returns: -* UPNP_E_SUCCESS -* UPNP_E_OUTOF_MEMORY -* -*=================================================================*/ -static int -ixml_membuf_set_size( INOUT ixml_membuf * m, - IN size_t new_length ) + +/*! + * \brief Increases or decreases buffer capacity so that at least 'new_length' + * bytes can be stored. + * + * On error, m's fields do not change. + * + * \return + * \li UPNP_E_SUCCESS + * \li UPNP_E_OUTOF_MEMORY + */ +static int ixml_membuf_set_size( + /*! [in,out] The memory buffer. */ + INOUT ixml_membuf *m, + /*! [in] The new lenght. */ + IN size_t new_length) { - size_t diff; - size_t alloc_len; - char *temp_buf; + size_t diff; + size_t alloc_len; + char *temp_buf; - if( new_length >= m->length ) // increase length - { - // need more mem? - if( new_length <= m->capacity ) { - return 0; // have enough mem; done - } + if (new_length >= m->length) { + /* increase length */ + /* need more mem? */ + if (new_length <= m->capacity) { + /* have enough mem; done */ + return 0; + } - diff = new_length - m->length; - alloc_len = MAXVAL( m->size_inc, diff ) + m->capacity; - } else // decrease length - { - assert( new_length <= m->length ); + diff = new_length - m->length; + alloc_len = MAXVAL(m->size_inc, diff) + m->capacity; + } else { + // decrease length + assert(new_length <= m->length); - // if diff is 0..m->size_inc, don't free - if( ( m->capacity - new_length ) <= m->size_inc ) { - return 0; - } + // if diff is 0..m->size_inc, don't free + if ((m->capacity - new_length) <= m->size_inc) { + return 0; + } + alloc_len = new_length + m->size_inc; + } - alloc_len = new_length + m->size_inc; - } + assert(alloc_len >= new_length); - assert( alloc_len >= new_length ); + temp_buf = realloc(m->buf, alloc_len + 1); + if (temp_buf == NULL) { + /* try smaller size */ + alloc_len = new_length; + temp_buf = realloc(m->buf, alloc_len + 1); + if (temp_buf == NULL) { + return IXML_INSUFFICIENT_MEMORY; + } + } + /* save */ + m->buf = temp_buf; + m->capacity = alloc_len; - temp_buf = realloc( m->buf, alloc_len + 1 ); - if( temp_buf == NULL ) { - // try smaller size - alloc_len = new_length; - temp_buf = realloc( m->buf, alloc_len + 1 ); - - if( temp_buf == NULL ) { - return IXML_INSUFFICIENT_MEMORY; - } - } - // save - m->buf = temp_buf; - m->capacity = alloc_len; - return 0; + return 0; } -/*================================================================ -* membuffer_init -* -* -*=================================================================*/ -void -ixml_membuf_init( INOUT ixml_membuf * m ) -{ - assert( m != NULL ); - m->size_inc = MEMBUF_DEF_SIZE_INC; - m->buf = NULL; - m->length = 0; - m->capacity = 0; +void ixml_membuf_init(ixml_membuf *m) +{ + assert(m != NULL); + + m->size_inc = MEMBUF_DEF_SIZE_INC; + m->buf = NULL; + m->length = 0; + m->capacity = 0; } -/*================================================================ -* membuffer_destroy -* -* -*=================================================================*/ -void -ixml_membuf_destroy( INOUT ixml_membuf * m ) -{ - if( m == NULL ) { - return; - } - free( m->buf ); - ixml_membuf_init( m ); +void ixml_membuf_destroy(ixml_membuf *m) +{ + if (m == NULL) { + return; + } + + free(m->buf); + ixml_membuf_init(m); } -/*================================================================ -* ixml_membuf_assign -* -* -*=================================================================*/ -int -ixml_membuf_assign( INOUT ixml_membuf * m, - IN const void *buf, - IN size_t buf_len ) + +int ixml_membuf_assign( + ixml_membuf *m, + const void *buf, + size_t buf_len) { - int return_code; + int return_code; - assert( m != NULL ); + assert(m != NULL); - // set value to null - if( buf == NULL ) { - ixml_membuf_destroy( m ); - return IXML_SUCCESS; - } - // alloc mem - return_code = ixml_membuf_set_size( m, buf_len ); - if( return_code != 0 ) { - return return_code; - } - // copy - memcpy( m->buf, buf, buf_len ); - m->buf[buf_len] = 0; // null-terminate + // set value to null + if (buf == NULL) { + ixml_membuf_destroy(m); + return IXML_SUCCESS; + } + // alloc mem + return_code = ixml_membuf_set_size(m, buf_len); + if (return_code != 0) { + return return_code; + } - m->length = buf_len; + // copy + memcpy(m->buf, buf, buf_len); - return IXML_SUCCESS; + // null-terminate + m->buf[buf_len] = 0; + m->length = buf_len; + return IXML_SUCCESS; } -/*================================================================ -* ixml_membuf_assign_str -* -* -*=================================================================*/ -int -ixml_membuf_assign_str( INOUT ixml_membuf * m, - IN const char *c_str ) + +int ixml_membuf_assign_str( + ixml_membuf *m, + const char *c_str) { - return ixml_membuf_assign( m, c_str, strlen( c_str ) ); + return ixml_membuf_assign(m, c_str, strlen(c_str)); } -/*================================================================ -* ixml_membuf_append -* -* -*=================================================================*/ -int -ixml_membuf_append( INOUT ixml_membuf * m, - IN const void *buf ) -{ - assert( m != NULL ); - return ixml_membuf_insert( m, buf, 1, m->length ); +int ixml_membuf_append( + INOUT ixml_membuf *m, + IN const void *buf) +{ + assert(m != NULL); + + return ixml_membuf_insert(m, buf, 1, m->length); } -/*================================================================ -* ixml_membuf_append_str -* -* -*=================================================================*/ -int -ixml_membuf_append_str( INOUT ixml_membuf * m, - IN const char *c_str ) + +int ixml_membuf_append_str( + INOUT ixml_membuf *m, + IN const char *c_str) { - return ixml_membuf_insert( m, c_str, strlen( c_str ), m->length ); + return ixml_membuf_insert(m, c_str, strlen(c_str), m->length); } -/*================================================================ -* ixml_membuf_insert -* -* -*=================================================================*/ -int -ixml_membuf_insert( INOUT ixml_membuf * m, - IN const void *buf, - IN size_t buf_len, - int index ) + +int ixml_membuf_insert( + INOUT ixml_membuf *m, + IN const void *buf, + IN size_t buf_len, + int index) { - int return_code; + int return_code = 0; - assert( m != NULL ); + assert(m != NULL); - if( index < 0 || index > ( int )m->length ) - return IXML_INDEX_SIZE_ERR; + if (index < 0 || index > (int)m->length) { + return IXML_INDEX_SIZE_ERR; + } - if( buf == NULL || buf_len == 0 ) { - return 0; - } - // alloc mem - return_code = ixml_membuf_set_size( m, m->length + buf_len ); - if( return_code != 0 ) { - return return_code; - } - // insert data - // move data to right of insertion point - memmove( m->buf + index + buf_len, m->buf + index, m->length - index ); - memcpy( m->buf + index, buf, buf_len ); - m->length += buf_len; - m->buf[m->length] = 0; // null-terminate + if (buf == NULL || buf_len == 0) { + return 0; + } + /* alloc mem */ + return_code = ixml_membuf_set_size(m, m->length + buf_len); + if (return_code != 0) { + return return_code; + } + /* insert data */ + /* move data to right of insertion point */ + memmove(m->buf + index + buf_len, m->buf + index, m->length - index); + memcpy(m->buf + index, buf, buf_len); + m->length += buf_len; + /* Null terminate */ + m->buf[m->length] = 0; - return 0; + return 0; } + diff --git a/ixml/src/ixmlparser.c b/ixml/src/ixmlparser.c index 04c74bb..fda11ed 100644 --- a/ixml/src/ixmlparser.c +++ b/ixml/src/ixmlparser.c @@ -1,43 +1,60 @@ -/////////////////////////////////////////////////////////////////////////// -// -// Copyright (c) 2000-2003 Intel Corporation -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are met: -// -// * Redistributions of source code must retain the above copyright notice, -// this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above copyright notice, -// this list of conditions and the following disclaimer in the documentation -// and/or other materials provided with the distribution. -// * Neither name of Intel Corporation nor the names of its contributors -// may be used to endorse or promote products derived from this software -// without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY -// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// -/////////////////////////////////////////////////////////////////////////// +/******************************************************************************* + * + * Copyright (c) 2000-2003 Intel Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither name of Intel Corporation nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + ******************************************************************************/ + + +/*! + * \file + */ + -#include #include "ixmlparser.h" + +#include "ixmldebug.h" + + +#include +#include +#include /* for free(), malloc() */ +#include + + #ifdef WIN32 - #define strncasecmp strnicmp + #define strncasecmp strnicmp #endif + static char g_error_char = '\0'; + static const char LESSTHAN = '<'; static const char GREATERTHAN = '>'; static const char SLASH = '/'; @@ -45,6 +62,7 @@ static const char EQUALS = '='; static const char QUOTE = '\"'; static const char SINGLEQUOTE = '\''; + static const char *WHITESPACE = "\n\t\r "; static const char *COMPLETETAG = "/>"; static const char *ENDTAG = ""; static const char *DEC_NUMBERS = "0123456789"; static const char *HEX_NUMBERS = "0123456789ABCDEFabcdef"; + typedef struct char_info { - unsigned short l, - h; + unsigned short l; + unsigned short h; } char_info_t; + typedef char utf8char[8]; -/*==============================================================================* -* Letter table contains all characters in XML 1.0 plus ":", "_" and -* ideographic. -* -* This table contains all the characters that an element name can start with. -* See XML 1.0 (2nd Edition) for more details. -* -*===============================================================================*/ + +/*! + * \brief The letter table contains all characters in XML 1.0 plus ":", "_" and + * ideographic. + * + * This table contains all the characters that an element name can start with. + * See XML 1.0 (2nd Edition) for more details. + */ static char_info_t Letter[] = { {0x003A, 0x003A}, // character ":" {0x0041, 0x005A}, @@ -129,253 +149,269 @@ static char_info_t Letter[] = { {0x1FBE, 0x1FBE}, {0x1FC2, 0x1FC4}, {0x1FC6, 0x1FCC}, {0x1FD0, 0x1FD3}, {0x1FD6, 0x1FDB}, {0x1FE0, 0x1FEC}, {0x1FF2, 0x1FF4}, {0x1FF6, 0x1FFC}, {0x2126, 0x2126}, {0x212A, 0x212B}, {0x212E, 0x212E}, {0x2180, 0x2182}, - {0x3007, 0x3007}, {0x3021, 0x3029}, // these two are ideographic + {0x3007, 0x3007}, {0x3021, 0x3029}, /* these two are ideographic */ {0x3041, 0x3094}, {0x30A1, 0x30FA}, {0x3105, 0x312C}, - {0x4E00, 0x9FA5}, // ideographic + {0x4E00, 0x9FA5}, /* ideographic */ {0xAC00, 0xD7A3} }; + +/*! + * \brief The size of the letter table array. + */ #define LETTERTABLESIZE (sizeof(Letter)/sizeof(Letter[0])) -/*==============================================================================* -* NameChar table contains -* CombiningChar, Extender, Digit, '-', '.', less '_', ':' -* NameChar ::= Digit | '-' | '.' | CombiningChar | Extender -* See XML 1.0 2nd Edition -* -*===============================================================================*/ + +/*! + * \brief The NameChar table contains CombiningChar, Extender, Digit, + * '-', '.', less '_', ':' + * + * NameChar ::= Digit | '-' | '.' | CombiningChar | Extender + * See XML 1.0 2nd Edition + */ static char_info_t NameChar[] = { - {0x002D, 0x002D}, // character "-" - {0x002E, 0x002E}, // character "." - {0x0030, 0x0039}, // digit - {0x00B7, 0x00B7}, {0x02D0, 0x02D0}, {0x02D1, 0x02D1}, // extended + {0x002D, 0x002D}, /* character "-" */ + {0x002E, 0x002E}, /* character "." */ + {0x0030, 0x0039}, /* digit */ + {0x00B7, 0x00B7}, {0x02D0, 0x02D0}, {0x02D1, 0x02D1}, /* extended */ {0x0300, 0x0345}, {0x0360, 0x0361}, - {0x0387, 0x0387}, // extended + {0x0387, 0x0387}, /* extended */ {0x0483, 0x0486}, {0x0591, 0x05A1}, {0x05A3, 0x05B9}, {0x05BB, 0x05BD}, {0x05BF, 0x05BF}, {0x05C1, 0x05C2}, {0x05C4, 0x05C4}, - {0x0640, 0x0640}, // extended + {0x0640, 0x0640}, /* extended */ {0x064B, 0x0652}, - {0x0660, 0x0669}, // digit + {0x0660, 0x0669}, /* digit */ {0x0670, 0x0670}, {0x06D6, 0x06DC}, {0x06DD, 0x06DF}, {0x06E0, 0x06E4}, {0x06E7, 0x06E8}, {0x06EA, 0x06ED}, - {0x06F0, 0x06F9}, // digit + {0x06F0, 0x06F9}, /* digit */ {0x0901, 0x0903}, {0x093C, 0x093C}, {0x093E, 0x094C}, {0x094D, 0x094D}, {0x0951, 0x0954}, {0x0962, 0x0963}, - {0x0966, 0x096F}, // digit + {0x0966, 0x096F}, /* digit */ {0x0981, 0x0983}, {0x09BC, 0x09BC}, {0x09BE, 0x09BE}, {0x09BF, 0x09BF}, {0x09C0, 0x09C4}, {0x09C7, 0x09C8}, {0x09CB, 0x09CD}, {0x09D7, 0x09D7}, {0x09E2, 0x09E3}, - {0x09E6, 0x09EF}, // digit + {0x09E6, 0x09EF}, /* digit */ {0x0A02, 0x0A02}, {0x0A3C, 0x0A3C}, {0x0A3E, 0x0A3E}, {0x0A3F, 0x0A3F}, {0x0A40, 0x0A42}, {0x0A47, 0x0A48}, {0x0A4B, 0x0A4D}, - {0x0A66, 0x0A6F}, // digit + {0x0A66, 0x0A6F}, /* digit */ {0x0A70, 0x0A71}, {0x0A81, 0x0A83}, {0x0ABC, 0x0ABC}, {0x0ABE, 0x0AC5}, {0x0AC7, 0x0AC9}, {0x0ACB, 0x0ACD}, - {0x0AE6, 0x0AEF}, // digit + {0x0AE6, 0x0AEF}, /* digit */ {0x0B01, 0x0B03}, {0x0B3C, 0x0B3C}, {0x0B3E, 0x0B43}, {0x0B47, 0x0B48}, {0x0B4B, 0x0B4D}, {0x0B56, 0x0B57}, - {0x0B66, 0x0B6F}, // digit + {0x0B66, 0x0B6F}, /* digit */ {0x0B82, 0x0B83}, {0x0BBE, 0x0BC2}, {0x0BC6, 0x0BC8}, {0x0BCA, 0x0BCD}, {0x0BD7, 0x0BD7}, - {0x0BE7, 0x0BEF}, // digit + {0x0BE7, 0x0BEF}, /* digit */ {0x0C01, 0x0C03}, {0x0C3E, 0x0C44}, {0x0C46, 0x0C48}, {0x0C4A, 0x0C4D}, {0x0C55, 0x0C56}, - {0x0C66, 0x0C6F}, // digit + {0x0C66, 0x0C6F}, /* digit */ {0x0C82, 0x0C83}, {0x0CBE, 0x0CC4}, {0x0CC6, 0x0CC8}, {0x0CCA, 0x0CCD}, {0x0CD5, 0x0CD6}, - {0x0CE6, 0x0CEF}, // digit + {0x0CE6, 0x0CEF}, /* digit */ {0x0D02, 0x0D03}, {0x0D3E, 0x0D43}, {0x0D46, 0x0D48}, {0x0D4A, 0x0D4D}, {0x0D57, 0x0D57}, - {0x0D66, 0x0D6F}, // digit + {0x0D66, 0x0D6F}, /* digit */ {0x0E31, 0x0E31}, {0x0E34, 0x0E3A}, - {0x0E46, 0x0E46}, // extended + {0x0E46, 0x0E46}, /* extended */ {0x0E47, 0x0E4E}, - {0x0E50, 0x0E59}, // digit + {0x0E50, 0x0E59}, /* digit */ {0x0EB1, 0x0EB1}, {0x0EB4, 0x0EB9}, {0x0EBB, 0x0EBC}, - {0x0EC6, 0x0EC6}, // extended + {0x0EC6, 0x0EC6}, /* extended */ {0x0EC8, 0x0ECD}, - {0x0ED0, 0x0ED9}, // digit + {0x0ED0, 0x0ED9}, /* digit */ {0x0F18, 0x0F19}, - {0x0F20, 0x0F29}, // digit + {0x0F20, 0x0F29}, /* digit */ {0x0F35, 0x0F35}, {0x0F37, 0x0F37}, {0x0F39, 0x0F39}, {0x0F3E, 0x0F3E}, {0x0F3F, 0x0F3F}, {0x0F71, 0x0F84}, {0x0F86, 0x0F8B}, {0x0F90, 0x0F95}, {0x0F97, 0x0F97}, {0x0F99, 0x0FAD}, {0x0FB1, 0x0FB7}, {0x0FB9, 0x0FB9}, {0x20D0, 0x20DC}, {0x20E1, 0x20E1}, - {0x3005, 0x3005}, // extended + {0x3005, 0x3005}, /* extended */ {0x302A, 0x302F}, - {0x3031, 0x3035}, // extended - {0x3099, 0x3099}, {0x309A, 0x309A}, // combining char - {0x309D, 0x309E}, {0x30FC, 0x30FE} // extended + {0x3031, 0x3035}, /* extended */ + {0x3099, 0x3099}, {0x309A, 0x309A}, /* combining char */ + {0x309D, 0x309E}, {0x30FC, 0x30FE} /* extended */ }; + +/*! + * \brief The name char table array size. + */ #define NAMECHARTABLESIZE (sizeof(NameChar)/sizeof(NameChar[0])) -// functions used in this file -static void Parser_free( Parser * myParser ); -static int Parser_skipDocType( char **pstr ); -static int Parser_skipProlog( Parser * xmlParser ); -static int Parser_skipMisc( Parser * xmlParser ); -static void Parser_freeElementStackItem( IXML_ElementStack * pItem ); -static void Parser_freeNsURI( IXML_NamespaceURI * pNsURI ); -static int Parser_getNextNode( Parser * myParser, - IXML_Node * newNode, - BOOL * isEnd ); -static int Parser_getNextToken( Parser * myParser ); -static int Parser_xmlNamespace( Parser * myParser, - IXML_Node * newNode ); -static BOOL Parser_ElementPrefixDefined( Parser * myParser, - IXML_Node * newNode, - char **nsURI ); -static int Parser_setElementNamespace( IXML_Element * newElement, - const char *nsURI ); -static int Parser_parseDocument( IXML_Document ** retDoc, - Parser * domParser ); -static BOOL Parser_hasDefaultNamespace( Parser * xmlParser, - IXML_Node * newNode, - char **nsURI ); -static int Parser_getChar( IN const char *src, - INOUT int *cLen ); +static void Parser_free( + Parser *myParser); +static int Parser_skipDocType( + char **pstr); +static int Parser_skipProlog( + Parser *xmlParser); +static int Parser_skipMisc( + Parser *xmlParser); +static void Parser_freeElementStackItem( + IXML_ElementStack *pItem); +static void Parser_freeNsURI( + IXML_NamespaceURI *pNsURI); -/*==============================================================================* -* safe_strdup -* strdup that handles NULL input. -* -*===============================================================================*/ -static char * -safe_strdup(const char *s) +static int Parser_getNextNode( + Parser *myParser, + IXML_Node *newNode, + BOOL *isEnd); +static int Parser_getNextToken( + Parser *myParser); +static int Parser_xmlNamespace( + Parser *myParser, + IXML_Node *newNode); +static BOOL Parser_ElementPrefixDefined( + Parser *myParser, + IXML_Node *newNode, + char **nsURI); +static int Parser_setElementNamespace( + IXML_Element *newElement, + const char *nsURI); +static int Parser_parseDocument( + IXML_Document **retDoc, + Parser *domParser); +static BOOL Parser_hasDefaultNamespace( + Parser *xmlParser, + IXML_Node *newNode, + char **nsURI); +static int Parser_getChar( + const char *src, + int *cLen); + + +/*! + * \brief Version of strdup() that handles NULL input. + * + * \return The same as strdup(). + */ +static char *safe_strdup( + /*! [in] String to be duplicated. */ + const char *s) { - assert(s != NULL); - if (s == NULL) { - return strdup(""); - } - return strdup(s); -} + assert(s != NULL); -/*==============================================================================* -* Parser_isCharInTable -* will determine whether character c is in the table of tbl -* (either Letter table or NameChar table) -* -*===============================================================================*/ -static BOOL -Parser_isCharInTable( IN int c, - IN char_info_t * tbl, - IN int sz ) -{ - int t = 0, - b = sz, - m; - - while( t <= b ) { - m = ( t + b ) / 2; - if( c < tbl[m].l ) { - b = m - 1; - } else if( c > tbl[m].h ) { - t = m + 1; - } else { - return TRUE; - } - } - return FALSE; -} - -/*==============================================================================* -* Parser_isXmlChar -* see XML 1.0 (2nd Edition) 2.2. -* Internal to parser only -* -*===============================================================================*/ -static BOOL -Parser_isXmlChar( IN int c ) -{ - return ( c == 0x9 || c == 0xA || c == 0xD || - ( c >= 0x20 && c <= 0xD7FF ) || - ( c >= 0xE000 && c <= 0xFFFD ) || - ( c >= 0x10000 && c <= 0x10FFFF ) ); -} - -/*==============================================================================* -* Parser_isNameChar -* check whether c (int) is in LetterTable or NameCharTable -* Internal to parser only. -* -*===============================================================================*/ -static BOOL -Parser_isNameChar( IN int c, - IN BOOL bNameChar ) -{ - if( Parser_isCharInTable( c, Letter, LETTERTABLESIZE ) ) { - return TRUE; - } - - if( bNameChar - && Parser_isCharInTable( c, NameChar, NAMECHARTABLESIZE ) ) { - return TRUE; - } - return FALSE; -} - -/*==============================================================================* -* Parser_isValidXmlName -* Check to see whether name is a valid xml name. -* External function. -* -*===============================================================================*/ -BOOL -Parser_isValidXmlName( IN const DOMString name ) -{ - const char *pstr = NULL; - int i = 0, - nameLen = 0; - - assert( name != NULL ); - - nameLen = strlen( name ); - - pstr = name; - if( Parser_isNameChar( *pstr, FALSE ) == TRUE ) { - for( i = 1; i < nameLen; i++ ) { - if( Parser_isNameChar( *( pstr + i ), TRUE ) == FALSE ) { //illegal char - return FALSE; - } - } - } - - return TRUE; -} - -/*==============================================================================* -* Parser_setErrorChar: -* If 'c' is 0 (default), the parser is strict about XML encoding : -* invalid UTF-8 sequences or "&" entities are rejected, and the parsing -* aborts. -* If 'c' is not 0, the parser is relaxed : invalid UTF-8 characters -* are replaced by this character, and invalid "&" entities are left -* untranslated. The parsing is then allowed to continue. -* External function. -* -*===============================================================================*/ -void -Parser_setErrorChar( IN char c ) -{ - g_error_char = c; + if (s == NULL) { + return strdup(""); + } + return strdup(s); } -/*==============================================================================* -* Parser_intToUTF8: -* Encoding a character to its UTF-8 character string, and return its length -* internal function. -* -*===============================================================================*/ -static int -Parser_intToUTF8( IN int c, - IN utf8char s ) +/*! + * \brief Will determine whether character c is in the table of tbl (either + * Letter table or NameChar table). + * + * \return TRUE or FALSE. + */ +static BOOL Parser_isCharInTable( + /*! [in] Character to check. */ + int c, + /*! [in] Table to use. */ + char_info_t *tbl, + /*! [in] Size of the table. */ + int sz) +{ + int t = 0; + int b = sz; + int m; + + while (t <= b) { + m = ( t + b ) / 2; + if (c < tbl[m].l) { + b = m - 1; + } else if (c > tbl[m].h) { + t = m + 1; + } else { + return TRUE; + } + } + + return FALSE; +} + + +/*! + * \brief see XML 1.0 (2nd Edition) 2.2. + */ +static BOOL Parser_isXmlChar( + /*! [in] The character to check. */ + int c) +{ + return + c == 0x9 || c == 0xA || c == 0xD || + (c >= 0x20 && c <= 0xD7FF) || + (c >= 0xE000 && c <= 0xFFFD) || + (c >= 0x10000 && c <= 0x10FFFF); +} + + +/*! + * \brief Check whether c (int) is in LetterTable or NameCharTable. + */ +static BOOL Parser_isNameChar( + /*! [in] The character to check. */ + int c, + /*! [in] TRUE if you also want to check in the NameChar table. */ + BOOL bNameChar) +{ + if (Parser_isCharInTable(c, Letter, LETTERTABLESIZE)) { + return TRUE; + } + + if (bNameChar && + Parser_isCharInTable(c, NameChar, NAMECHARTABLESIZE)) { + return TRUE; + } + + return FALSE; +} + + +BOOL Parser_isValidXmlName(const DOMString name) +{ + const char *pstr = NULL; + int i = 0; + int nameLen = 0; + + assert(name != NULL); + + nameLen = strlen(name); + pstr = name; + if (Parser_isNameChar(*pstr, FALSE) == TRUE) { + for (i = 1; i < nameLen; ++i) { + if (Parser_isNameChar(*(pstr + i), TRUE) == FALSE) { + /* illegal char */ + return FALSE; + } + } + } + + return TRUE; +} + + +void Parser_setErrorChar(char c) +{ + g_error_char = c; +} + + +/*! + * \brief Encodes a character to its UTF-8 character string, and return its length. + * + * \return The length of the encoded string in bytes. + */ +static int Parser_intToUTF8( + /*! [in] The character to encode. */ + int c, + /*! [out] The resultant UTF-8 encoded string. */ + utf8char s) { if( c < 0 ) { return 0; @@ -385,25 +421,25 @@ Parser_intToUTF8( IN int c, s[0] = c; s[1] = 0; return 1; - } else if( c <= 0x07FF ) { // 0x0080 < c <= 0x07FF + } else if( c <= 0x07FF ) { /* 0x0080 < c <= 0x07FF */ s[0] = 0xC0 | ( c >> 6 ); s[1] = 0x80 | ( c & 0x3f ); s[2] = 0; return 2; - } else if( c <= 0xFFFF ) { // 0x0800 < c <= 0xFFFF + } else if( c <= 0xFFFF ) { /* 0x0800 < c <= 0xFFFF */ s[0] = 0xE0 | ( c >> 12 ); s[1] = 0x80 | ( ( c >> 6 ) & 0x3f ); s[2] = 0x80 | ( c & 0x3f ); s[3] = 0; return 3; - } else if( c <= 0x1FFFFF ) { // 0x10000 < c <= 0x1FFFFF + } else if( c <= 0x1FFFFF ) { /* 0x10000 < c <= 0x1FFFFF */ s[0] = 0xF0 | ( c >> 18 ); s[1] = 0x80 | ( ( c >> 12 ) & 0x3f ); s[2] = 0x80 | ( ( c >> 6 ) & 0x3f ); s[3] = 0x80 | ( c & 0x3f ); s[4] = 0; return 4; - } else if( c <= 0x3FFFFFF ) { // 0x200000 < c <= 3FFFFFF + } else if( c <= 0x3FFFFFF ) { /* 0x200000 < c <= 3FFFFFF */ s[0] = 0xF8 | ( c >> 24 ); s[1] = 0x80 | ( ( c >> 18 ) & 0x3f ); s[2] = 0x80 | ( ( c >> 12 ) & 0x3f ); @@ -411,7 +447,7 @@ Parser_intToUTF8( IN int c, s[4] = 0x80 | ( c & 0x3f ); s[5] = 0; return 5; - } else if( c <= 0x7FFFFFFF ) { // 0x4000000 < c <= 7FFFFFFF + } else if( c <= 0x7FFFFFFF ) { /* 0x4000000 < c <= 7FFFFFFF */ s[0] = 0xFC | ( c >> 30 ); s[1] = 0x80 | ( ( c >> 24 ) & 0x3f ); s[2] = 0x80 | ( ( c >> 18 ) & 0x3f ); @@ -420,122 +456,159 @@ Parser_intToUTF8( IN int c, s[5] = 0x80 | ( c & 0x3f ); s[6] = 0; return 6; - } else { // illegal + } else { /* illegal */ return 0; } } -/*==============================================================================* -* Parser_UTF8ToInt -* In UTF-8, characters are encoded using sequences of 1 to 6 octets. -* This functions will return a UTF-8 character value and its octets number. -* Internal to parser only. -* Internal to parser only -* -*===============================================================================*/ -static int -Parser_UTF8ToInt( IN const char *ss, - OUT int *len ) + +/*! + * \brief In UTF-8, characters are encoded using sequences of 1 to 6 octets. + * This functions will return a UTF-8 character value and its octets number. + * + * \return The UTF-8 character converted to an int (32 bits). + */ +static int Parser_UTF8ToInt( + /*! [in] The pointer to the character to encode. */ + const char *ss, + /*! [out] The number of octets of the UTF-8 encoding of this character. */ + int *len) { + const unsigned char *s = (const unsigned char *)ss; + int c = *s; - const unsigned char *s = ( const unsigned char * )ss; - int c = *s; - - if( c <= 127 ) { // if c<=127, c is just the character. - *len = 1; - return c; - } else if( ( c & 0xE0 ) == 0xC0 && ( s[1] & 0xc0 ) == 0x80 ) { // a sequence of 110xxxxx and 10xxxxxx? - *len = 2; - return ( ( ( c & 0x1f ) << 6 ) | ( s[1] & 0x3f ) ); - } else if( ( c & 0xF0 ) == 0xE0 && ( s[1] & 0xc0 ) == 0x80 && ( s[2] & 0xc0 ) == 0x80 ) { // a sequence of 1110xxxx,10xxxxxx and 10xxxxxx ? - *len = 3; - return ( ( ( c & 0xf ) << 12 ) | ( ( s[1] & 0x3f ) << 6 ) | - ( s[2] & 0x3f ) ); - } else if( ( c & 0xf8 ) == 0xf0 && ( s[1] & 0xc0 ) == 0x80 && ( s[2] & 0xc0 ) == 0x80 && ( s[3] & 0xc0 ) == 0x80 ) { // a sequence of 11110xxx,10xxxxxx,10xxxxxx and 10xxxxxx ? - *len = 4; - return ( ( ( c & 0x7 ) << 18 ) | ( ( s[1] & 0x3f ) << 12 ) | - ( ( s[2] & 0x3f ) << 6 ) | ( s[3] & 0x3f ) ); - } else if( ( c & 0xfc ) == 0xf8 && ( s[1] & 0xc0 ) == 0x80 && ( s[2] & 0xc0 ) == 0x80 && ( s[3] & 0xc0 ) == 0x80 && ( s[4] & 0xc0 ) == 0x80 ) { // a sequence of 111110xx,10xxxxxx,10xxxxxx,10xxxxxx,10xxxxxx ? - *len = 5; - return ( ( ( c & 0x3 ) << 24 ) | ( ( s[1] & 0x3f ) << 18 ) | - ( ( s[2] & 0x3f ) << 12 ) | ( ( s[3] & 0x3f ) << 6 ) | - ( s[4] & 0x3f ) ); - } else if( ( c & 0xfe ) == 0xfc && ( s[1] & 0xc0 ) == 0x80 && ( s[2] & 0xc0 ) == 0x80 && ( s[3] & 0xc0 ) == 0x80 && ( s[4] & 0xc0 ) == 0x80 && ( s[5] & 0xc0 ) == 0x80 ) { // a sequence of 1111110x,10xxxxxx,10xxxxxx,10xxxxxx,10xxxxxx and 10xxxxxx ? - *len = 6; - return ( ( ( c & 0x1 ) << 30 ) | ( ( s[1] & 0x3f ) << 24 ) | - ( ( s[2] & 0x3f ) << 18 ) | ( ( s[3] & 0x3f ) << 12 ) | - ( ( s[4] & 0x3f ) << 6 ) | ( s[5] & 0x3f ) ); - } else { // none of above, error - if (g_error_char) { - *len = 1; - return g_error_char; - } else { - *len = 0; - return -1; - } - } + if (c <= 127) { + /* if c<=127, c is just the character. */ + *len = 1; + return c; + } else if ((c & 0xE0) == 0xC0 && + (s[1] & 0xc0) == 0x80) { + /* a sequence of 110xxxxx and 10xxxxxx? */ + *len = 2; + return ((c & 0x1f) << 6) | + (s[1] & 0x3f); + } else if ((c & 0xF0) == 0xE0 && + (s[1] & 0xc0) == 0x80 && + (s[2] & 0xc0) == 0x80) { + /* a sequence of 1110xxxx,10xxxxxx and 10xxxxxx ? */ + *len = 3; + return ((c & 0x0f) << 12) | + ((s[1] & 0x3f) << 6) | + (s[2] & 0x3f); + } else if ((c & 0xf8) == 0xf0 && + (s[1] & 0xc0) == 0x80 && + (s[2] & 0xc0) == 0x80 && + (s[3] & 0xc0) == 0x80) { + /* a sequence of 11110xxx,10xxxxxx,10xxxxxx and 10xxxxxx ? */ + *len = 4; + return ((c & 0x07) << 18) | + ((s[1] & 0x3f) << 12) | + ((s[2] & 0x3f) << 6) | + (s[3] & 0x3f); + } else if ((c & 0xfc) == 0xf8 && + (s[1] & 0xc0) == 0x80 && + (s[2] & 0xc0) == 0x80 && + (s[3] & 0xc0) == 0x80 && + (s[4] & 0xc0) == 0x80) { + /* a sequence of 111110xx,10xxxxxx,10xxxxxx,10xxxxxx,10xxxxxx ? */ + *len = 5; + return ((c & 0x03) << 24) | + ((s[1] & 0x3f) << 18) | + ((s[2] & 0x3f) << 12) | + ((s[3] & 0x3f) << 6) | + (s[4] & 0x3f); + } else if ((c & 0xfe) == 0xfc && + (s[1] & 0xc0) == 0x80 && + (s[2] & 0xc0) == 0x80 && + (s[3] & 0xc0) == 0x80 && + (s[4] & 0xc0) == 0x80 && + (s[5] & 0xc0) == 0x80) { + /* a sequence of 1111110x,10xxxxxx,10xxxxxx,10xxxxxx,10xxxxxx and 10xxxxxx ? */ + *len = 6; + return ((c & 0x01) << 30) | + ((s[1] & 0x3f) << 24) | + ((s[2] & 0x3f) << 18) | + ((s[3] & 0x3f) << 12) | + ((s[4] & 0x3f) << 6) | + (s[5] & 0x3f); + } else { + /* none of above, error */ + int ret = 0; + int line = __LINE__; + if (g_error_char) { + *len = 1; + ret = g_error_char; + } else { + *len = 0; + ret = -1; + } + IxmlPrintf("(%s::Parser_UTF8ToInt): Error %d, line %d\n", + __FILE__, ret, line); + return ret; + } } -/*==============================================================================* -* Parser_init -* Initializes a xml parser. -* Internal to parser only -* -*===============================================================================*/ -static Parser * -Parser_init() + +/*! + * \brief Initializes a xml parser. + * + * \return The parser object or \b NULL if there is not enough memory. + */ +static Parser *Parser_init() { - Parser *newParser = NULL; + Parser *newParser = NULL; - newParser = ( Parser * ) malloc( sizeof( Parser ) ); - if( newParser == NULL ) { - return NULL; - } + newParser = (Parser *)malloc(sizeof (Parser)); + if (newParser == NULL) { + return NULL; + } - memset( newParser, 0, sizeof( Parser ) ); + memset(newParser, 0, sizeof (Parser)); + ixml_membuf_init(&(newParser->tokenBuf)); + ixml_membuf_init(&(newParser->lastElem)); - ixml_membuf_init( &( newParser->tokenBuf ) ); - ixml_membuf_init( &( newParser->lastElem ) ); - - return newParser; + return newParser; } -/*================================================================ - * Parser_isValidEndElement - * check if a new node->nodeName matches top of element stack. - * Internal to parser only. - *=================================================================*/ -static int -Parser_isValidEndElement( - IN Parser * xmlParser, - IN IXML_Node * newNode ) -{ - assert( xmlParser ); - assert( xmlParser->pCurElement ); - assert( xmlParser->pCurElement->element ); - assert( newNode ); - assert( newNode->nodeName ); - return strcmp( xmlParser->pCurElement->element, newNode->nodeName ) == 0; +/*! + * \brief Check if a new node->nodeName matches top of element stack. + * + * \return TRUE if matches. + */ +static int Parser_isValidEndElement( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The node. */ + IXML_Node *newNode) +{ + assert(xmlParser); + assert(xmlParser->pCurElement); + assert(xmlParser->pCurElement->element); + assert(newNode); + assert(newNode->nodeName); + + return strcmp(xmlParser->pCurElement->element, newNode->nodeName) == 0; } -/*=============================================================== -* Parser_pushElement -* push a new element onto element stack -* Internal to parser only. -* -*=================================================================*/ -static int -Parser_pushElement( IN Parser * xmlParser, - IN IXML_Node * newElement ) -{ +/*! + * \brief Push a new element onto element stack. + * + * \return + */ +static int Parser_pushElement( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The element node to push. */ + IXML_Node *newElement) +{ IXML_ElementStack *pCurElement = NULL; IXML_ElementStack *pNewStackElement = NULL; assert( newElement ); if( newElement != NULL ) { - // push new element + /* push new element */ pNewStackElement = ( IXML_ElementStack * ) malloc( sizeof( IXML_ElementStack ) ); if( pNewStackElement == NULL ) { @@ -543,7 +616,7 @@ Parser_pushElement( IN Parser * xmlParser, } memset( pNewStackElement, 0, sizeof( IXML_ElementStack ) ); - // the element member includes both prefix and name + /* the element member includes both prefix and name */ pNewStackElement->element = safe_strdup( newElement->nodeName ); if( pNewStackElement->element == NULL ) { @@ -572,7 +645,7 @@ Parser_pushElement( IN Parser * xmlParser, pCurElement = xmlParser->pCurElement; - // insert the new element into the top of the stack + /* insert the new element into the top of the stack */ pNewStackElement->nextElement = pCurElement; xmlParser->pCurElement = pNewStackElement; @@ -581,49 +654,46 @@ Parser_pushElement( IN Parser * xmlParser, return IXML_SUCCESS; } -/*================================================================ -* Parser_popElement -* Remove element from element stack. -* Internal to parser only. -* -*=================================================================*/ -static void -Parser_popElement( IN Parser * xmlParser ) + +/*! + * \brief Remove element from element stack. + */ +static void Parser_popElement( + /*! [in] The XML parser. */ + Parser *xmlParser) { - IXML_ElementStack *pCur = NULL; - IXML_NamespaceURI *pnsUri = NULL, - *pNextNS = NULL; - - pCur = xmlParser->pCurElement; - if( pCur != NULL ) { - xmlParser->pCurElement = pCur->nextElement; - - Parser_freeElementStackItem( pCur ); - - pnsUri = pCur->pNsURI; - while( pnsUri != NULL ) { - pNextNS = pnsUri->nextNsURI; - - Parser_freeNsURI( pnsUri ); - free( pnsUri ); - pnsUri = pNextNS; - } - - free( pCur ); - } + IXML_ElementStack *pCur = NULL; + IXML_NamespaceURI *pnsUri = NULL; + IXML_NamespaceURI *pNextNS = NULL; + pCur = xmlParser->pCurElement; + if (pCur != NULL) { + xmlParser->pCurElement = pCur->nextElement; + Parser_freeElementStackItem(pCur); + pnsUri = pCur->pNsURI; + while (pnsUri != NULL) { + pNextNS = pnsUri->nextNsURI; + Parser_freeNsURI(pnsUri); + free(pnsUri); + pnsUri = pNextNS; + } + free(pCur); + } } -/*================================================================ -* Parser_readFileOrBuffer -* read a xml file or buffer contents into xml parser. -* Internal to parser only. -* -*=================================================================*/ -static int -Parser_readFileOrBuffer( IN Parser * xmlParser, - IN const char *xmlFileName, - IN BOOL file ) + +/*! + * \brief Read a xml file or buffer contents into xml parser. + */ +static int Parser_readFileOrBuffer( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The file name or the buffer to copy, according to the + * parameter "file". */ + const char *xmlFileName, + /*! [in] TRUE if you want to read from a file, false if xmlFileName is + * the buffer to copy to the parser. */ + BOOL file) { int fileSize = 0; int bytesRead = 0; @@ -663,16 +733,19 @@ Parser_readFileOrBuffer( IN Parser * xmlParser, return IXML_SUCCESS; } -/*================================================================ -* Parser_LoadDocument -* parses a xml file and return the DOM tree. -* Internal to parser only -* -*=================================================================*/ -int -Parser_LoadDocument( OUT IXML_Document ** retDoc, - IN const char *xmlFileName, - IN BOOL file ) + +/*! + * \brief Parses a xml file and return the DOM tree. + */ +int Parser_LoadDocument( + /*! [out] The output document tree. */ + IXML_Document **retDoc, + /*! [in] The file name or the buffer to copy, according to the + * parameter "file". */ + const char *xmlFileName, + /*! [in] TRUE if you want to read from a file, false if xmlFileName is + * the buffer to copy to the parser. */ + BOOL file) { int rc = IXML_SUCCESS; Parser *xmlParser = NULL; @@ -694,29 +767,31 @@ Parser_LoadDocument( OUT IXML_Document ** retDoc, } -/*================================================================ -* isTopLevelElement -* decides whether we have top level element already. -* Internal to parser only. -* -*=================================================================*/ -static int -isTopLevelElement( IN Parser * xmlParser ) + +/*! + * \brief Reports whether there is a top level element in the parser. + * + * \return TRUE if there is a top level element in the parser. + */ +static int isTopLevelElement( + /*! [in] The XML parser. */ + Parser *xmlParser) { - assert( xmlParser ); - return ( xmlParser->pCurElement == NULL ); + assert(xmlParser); + return xmlParser->pCurElement == NULL; } -/*================================================================ -* isDuplicateAttribute -* Decide whether the new attribute is the same as an -* existing one. -* Internal to parser only. -* -*=================================================================*/ -static int -isDuplicateAttribute( IN Parser * xmlParser, - IN IXML_Node * newAttrNode ) + +/*! + * \brief Reports whether the new attribute is the same as an existing one. + * + * \return TRUE if the new attribute is the same as an existing one. + */ +static int isDuplicateAttribute( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The node attribute to compare. */ + IXML_Node *newAttrNode) { IXML_Node *elementNode = NULL; IXML_Node *attrNode = NULL; @@ -734,16 +809,18 @@ isDuplicateAttribute( IN Parser * xmlParser, return FALSE; } -/*================================================================ -* Parser_processAttributeName -* processes the attribute name. -* Internal to parser only. -* -*=================================================================*/ -static int -Parser_processAttributeName( IN IXML_Document * rootDoc, - IN Parser * xmlParser, - IN IXML_Node * newNode ) +/*! + * \brief Processes the attribute name. + * + * \return IXML_SUCCESS if successful, otherwise or an error code. + */ +static int Parser_processAttributeName( + /*! [in] The XML document. */ + IXML_Document *rootDoc, + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *newNode) { IXML_Attr *attr = NULL; int rc = IXML_SUCCESS; @@ -752,8 +829,7 @@ Parser_processAttributeName( IN IXML_Document * rootDoc, return IXML_SYNTAX_ERR; } - rc = ixmlDocument_createAttributeEx( rootDoc, newNode->nodeName, - &attr ); + rc = ixmlDocument_createAttributeEx( rootDoc, newNode->nodeName, &attr ); if( rc != IXML_SUCCESS ) { return rc; } @@ -763,21 +839,23 @@ Parser_processAttributeName( IN IXML_Document * rootDoc, return rc; } - rc = ixmlElement_setAttributeNode( ( IXML_Element * ) xmlParser-> - currentNodePtr, attr, NULL ); + rc = ixmlElement_setAttributeNode( + (IXML_Element *)xmlParser->currentNodePtr, attr, NULL ); return rc; } -/*================================================================ -* Parser_processElementName -* Processes element name -* Internal to parser only. -* -*=================================================================*/ -static int -Parser_processElementName( IN IXML_Document * rootDoc, - IN Parser * xmlParser, - IN IXML_Node * newNode ) +/*! + * \brief Processes element name. + * + * \return IXML_SUCCESS if successful, otherwise or an error code. + */ +static int Parser_processElementName( + /*! [in] The XML document. */ + IXML_Document *rootDoc, + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *newNode ) { IXML_Element *newElement = NULL; char *nsURI = NULL; @@ -792,8 +870,7 @@ Parser_processElementName( IN IXML_Document * rootDoc, } xmlParser->savePtr = xmlParser->curPtr; - rc = ixmlDocument_createElementEx( rootDoc, newNode->nodeName, - &newElement ); + rc = ixmlDocument_createElementEx( rootDoc, newNode->nodeName, &newElement ); if( rc != IXML_SUCCESS ) { return rc; } @@ -838,18 +915,15 @@ Parser_processElementName( IN IXML_Document * rootDoc, return rc; } -/*================================================================ -* Parser_eTagVerification -* Verifies endof element tag is the same as the openning -* element tag. -* Internal to parser only. -* -*=================================================================*/ -static int -Parser_eTagVerification( IN Parser * xmlParser, - IN IXML_Node * newNode ) +/*! + * \brief Verifies endof element tag is the same as the openning element tag. + */ +static int Parser_eTagVerification( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The Node to process. */ + IXML_Node *newNode) { - assert( newNode->nodeName ); assert( xmlParser->currentNodePtr ); @@ -869,19 +943,11 @@ Parser_eTagVerification( IN Parser * xmlParser, } return IXML_SUCCESS; - } -/*================================================================ -* Parser_freeNodeContent -* frees a node contents -* Internal to parser only. -* -*=================================================================*/ -void -Parser_freeNodeContent( IN IXML_Node * nodeptr ) -{ +void Parser_freeNodeContent(IXML_Node *nodeptr) +{ if( nodeptr == NULL ) { return; } @@ -905,20 +971,20 @@ Parser_freeNodeContent( IN IXML_Node * nodeptr ) if( nodeptr->localName != NULL ) { free( nodeptr->localName ); } - } -/*================================================================ -* Parser_parseDocument -* Parses the xml file and returns the DOM document tree. -* External function. -* -*=================================================================*/ -static int -Parser_parseDocument( OUT IXML_Document ** retDoc, - IN Parser * xmlParser ) -{ +/*! + * \brief Parses the xml file and returns the DOM document tree. + * + * \return + */ +static int Parser_parseDocument( + /*! [out] The XML document. */ + IXML_Document **retDoc, + /*! [in] The XML parser. */ + Parser *xmlParser) +{ IXML_Document *gRootDoc = NULL; IXML_Node newNode; BOOL bETag = FALSE; @@ -1044,18 +1110,17 @@ ErrorHandler: ixmlDocument_free( gRootDoc ); Parser_free( xmlParser ); return rc; - } -/*==============================================================================* -* Parser_setLastElem -* set the last element to be the given string. -* Internal to parser only. -* -*===============================================================================*/ -static int -Parser_setLastElem( IN Parser * xmlParser, - IN const char *s ) + +/*! + * \brief Set the last element to be the given string. + */ +static int Parser_setLastElem( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The string to copy from. */ + const char *s) { int rc; @@ -1067,29 +1132,26 @@ Parser_setLastElem( IN Parser * xmlParser, return rc; } -/*==============================================================================* -* -* Parser_clearTokenBuf -* clear token buffer. -* Internal to parser only. -* -*===============================================================================*/ -static void -Parser_clearTokenBuf( IN Parser * xmlParser ) + +/*! + * \brief Clear token buffer. + ******************************************************************************/ +static void Parser_clearTokenBuf( + /*! [in] The XML parser. */ + Parser *xmlParser) { ixml_membuf_destroy( &( xmlParser->tokenBuf ) ); } -/*==============================================================================* -* -* Parser_appendTokBufStr -* Appends string s to token buffer -* Internal to parser only. -* -*===============================================================================*/ -static int -Parser_appendTokBufStr( IN Parser * xmlParser, - IN const char *s ) + +/*! + * \brief Appends string s to token buffer. + */ +static int Parser_appendTokBufStr( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The string to append. */ + const char *s) { int rc = IXML_SUCCESS; @@ -1100,16 +1162,15 @@ Parser_appendTokBufStr( IN Parser * xmlParser, return rc; } -/*==============================================================================* -* -* Parser_appendTokBufChar -* Appends c to token buffer. -* Internal to parser only. -* -*===============================================================================*/ -static int -Parser_appendTokBufChar( IN Parser * xmlParser, - IN char c ) + +/*! + * \brief Appends c to token buffer. + */ +static int Parser_appendTokBufChar( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The character to append. */ + char c) { int rc; @@ -1117,182 +1178,215 @@ Parser_appendTokBufChar( IN Parser * xmlParser, return rc; } -/*==============================================================================* -* -* Parser_skipWhiteSpaces -* skip white spaces -* Internal to parser only -* -*===============================================================================*/ -static void -Parser_skipWhiteSpaces( IN Parser * xmlParser ) + +/*! + * \brief Skip white spaces. + */ +static void Parser_skipWhiteSpaces( + /*! [in] The XML parser. */ + Parser *xmlParser) { while( ( *( xmlParser->curPtr ) != 0 ) && ( strchr( WHITESPACE, *( xmlParser->curPtr ) ) != NULL ) ) { xmlParser->curPtr++; } - } -/*==============================================================================* -* Parser_getChar -* returns next char value and its length -* Internal to parser only -* -*===============================================================================*/ -static int -Parser_getChar( IN const char *src, - INOUT int *cLen ) + +/*! + * \brief Returns next char value and its length. + */ +static int Parser_getChar( + /*! [in] . */ + const char *src, + /*! [in,out] . */ + int *cLen) { - const char *pnum; - int sum; - char c; - int i; + int ret = -1; + int line = 0; + const char *pnum; + int sum; + char c; + int i; - if( src == NULL || cLen == NULL ) { - return -1; - } + if( src == NULL || cLen == NULL ) { + line = __LINE__; + ret = -1; + goto ExitFunction; + } - *cLen = 0; + *cLen = 0; + if (*src != '&') { + if (*src > 0 && Parser_isXmlChar(*src)) { + *cLen = 1; + ret = *src; + goto ExitFunction; + } - if( *src != '&' ) { - if( *src > 0 && Parser_isXmlChar( *src ) ) { - *cLen = 1; - return *src; - } + i = Parser_UTF8ToInt(src, cLen); + if (!Parser_isXmlChar(i)) { + line = __LINE__; + ret = g_error_char ? g_error_char : -1; + goto ExitFunction; + } - i = Parser_UTF8ToInt( src, cLen ); - if( !Parser_isXmlChar( i ) ) { - return ( g_error_char ? g_error_char : -1 ); - } - return i; - } else if( strncasecmp( src, QUOT, strlen( QUOT ) ) == 0 ) { - *cLen = strlen( QUOT ); - return '"'; - } else if( strncasecmp( src, LT, strlen( LT ) ) == 0 ) { - *cLen = strlen( LT ); - return '<'; - } else if( strncasecmp( src, GT, strlen( GT ) ) == 0 ) { - *cLen = strlen( GT ); - return '>'; - } else if( strncasecmp( src, APOS, strlen( APOS ) ) == 0 ) { - *cLen = strlen( APOS ); - return '\''; - } else if( strncasecmp( src, AMP, strlen( AMP ) ) == 0 ) { - *cLen = strlen( AMP ); - return '&'; - } else if( strncasecmp( src, ESC_HEX, strlen( ESC_HEX ) ) == 0 ) { // Read in escape characters of type &#xnn where nn is a hexadecimal value - pnum = src + strlen( ESC_HEX ); - sum = 0; - while( strchr( HEX_NUMBERS, *pnum ) != 0 ) { - c = *pnum; - if( c <= '9' ) { - sum = sum * 16 + ( c - '0' ); - } else if( c <= 'F' ) { - sum = sum * 16 + ( c - 'A' + 10 ); - } else { - sum = sum * 16 + ( c - 'a' + 10 ); - } - - pnum++; - } - - if( ( pnum == src ) || *pnum != ';' || !Parser_isXmlChar( sum ) ) { - goto fail_entity; - } - - *cLen = pnum - src + 1; - return sum; - - } else if( strncasecmp( src, ESC_DEC, strlen( ESC_DEC ) ) == 0 ) { - // Read in escape characters of type &#nn where nn is a decimal value - pnum = src + strlen( ESC_DEC ); - sum = 0; - while( strchr( DEC_NUMBERS, *pnum ) != 0 ) { - sum = sum * 10 + ( *pnum - '0' ); - pnum++; - } - - if( ( pnum == src ) || *pnum != ';' || !Parser_isXmlChar( sum ) ) { - goto fail_entity; - } - - *cLen = pnum - src + 1; - return sum; - } + line = __LINE__; + ret = i; + goto ExitFunction; + } else if (strncasecmp(src, QUOT, strlen(QUOT)) == 0) { + *cLen = strlen(QUOT); + ret = '"'; + goto ExitFunction; + } else if (strncasecmp(src, LT, strlen(LT)) == 0) { + *cLen = strlen(LT); + ret = '<'; + goto ExitFunction; + } else if (strncasecmp(src, GT, strlen(GT)) == 0) { + *cLen = strlen(GT); + ret = '>'; + goto ExitFunction; + } else if (strncasecmp(src, APOS, strlen(APOS)) == 0) { + *cLen = strlen(APOS); + ret = '\''; + goto ExitFunction; + } else if (strncasecmp(src, AMP, strlen(AMP)) == 0) { + *cLen = strlen(AMP); + ret = '&'; + goto ExitFunction; + } else if (strncasecmp(src, ESC_HEX, strlen(ESC_HEX)) == 0) { + /* Read in escape characters of type &#xnn where nn is a hexadecimal value */ + pnum = src + strlen( ESC_HEX ); + sum = 0; + while (strchr(HEX_NUMBERS, *pnum) != 0) { + c = *pnum; + if (c <= '9') { + sum = sum * 16 + ( c - '0' ); + } else if( c <= 'F' ) { + sum = sum * 16 + ( c - 'A' + 10 ); + } else { + sum = sum * 16 + ( c - 'a' + 10 ); + } + pnum++; + } + if (pnum == src || *pnum != ';' || !Parser_isXmlChar(sum)) { + line = __LINE__; + goto fail_entity; + } + *cLen = pnum - src + 1; + ret = sum; + goto ExitFunction; + } else if (strncasecmp(src, ESC_DEC, strlen(ESC_DEC)) == 0) { + /* Read in escape characters of type &#nn where nn is a decimal value */ + pnum = src + strlen(ESC_DEC); + sum = 0; + while (strchr(DEC_NUMBERS, *pnum) != 0) { + sum = sum * 10 + ( *pnum - '0' ); + pnum++; + } + if( ( pnum == src ) || *pnum != ';' || !Parser_isXmlChar( sum ) ) { + line = __LINE__; + goto fail_entity; + } + *cLen = pnum - src + 1; + ret = sum; + goto ExitFunction; + } fail_entity: - if (g_error_char) { - *cLen = 1; - return '&'; - } - return -1; + if (g_error_char) { + *cLen = 1; + ret = '&'; + goto ExitFunction; + } + ret = -1; + +ExitFunction: + if (ret == -1 || (g_error_char && ret == g_error_char)) { + IxmlPrintf("(%s::Parser_getChar): Error %d, line %d\n", + __FILE__, ret, line); + } + + return ret; } -/*==============================================================================* -* Parser_copyToken -* copy string in src into xml parser token buffer -* Internal to parser only. -* -*===============================================================================*/ -static int -Parser_copyToken( IN Parser * xmlParser, - IN const char *src, - IN int len ) + +/*! + * \brief Copy string in src into xml parser token buffer + */ +static int Parser_copyToken( + /*! [in] The XML parser. */ + Parser *xmlParser, + /*! [in] The string to copy from. */ + const char *src, + /*! [in] The lenght to copy. */ + int len) { - int i, - c, - cl; - const char *psrc, - *pend; - utf8char uch; + int ret = IXML_SUCCESS; + int line = 0; + int i; + int c; + int cl; + const char *psrc; + const char *pend; + utf8char uch; - if( !src || len <= 0 ) { - return IXML_FAILED; - } + if (!src || len <= 0) { + line = __LINE__; + ret = IXML_FAILED; + goto ExitFunction; + } - psrc = src; - pend = src + len; + psrc = src; + pend = src + len; - while( psrc < pend ) { - if( ( c = Parser_getChar( psrc, &cl ) ) <= 0 ) { - return IXML_FAILED; - } + while (psrc < pend) { + c = Parser_getChar(psrc, &cl); + if (c <= 0) { + line = __LINE__; + ret = IXML_FAILED; + goto ExitFunction; + } - if( cl == 1 ) { - Parser_appendTokBufChar( xmlParser, ( char )c ); - psrc++; - } else { + if (cl == 1) { + Parser_appendTokBufChar(xmlParser, (char)c); + psrc++; + } else { + i = Parser_intToUTF8(c, uch); + if (i == 0) { + line = __LINE__; + ret = IXML_FAILED; + goto ExitFunction; + } + Parser_appendTokBufStr(xmlParser, uch); + psrc += cl; + } + } - i = Parser_intToUTF8( c, uch ); - if( i == 0 ) { - return IXML_FAILED; - } + if (psrc > pend) { + line = __LINE__; + ret = IXML_FAILED; + goto ExitFunction; + } - Parser_appendTokBufStr( xmlParser, uch ); - psrc += cl; - } - } - - if( psrc > pend ) { - return IXML_FAILED; - } else { - return IXML_SUCCESS; // success - } +ExitFunction: + if (ret != IXML_SUCCESS) { + IxmlPrintf("(%s::Parser_copyToken): Error %d, line %d\n", + __FILE__, ret, line); + } + return ret; } -/*==============================================================================* -* -* Parser_skipString -* Skips all characters in the string until it finds the skip key. -* Then it skips the skip key and returns. -* Internal to parser only -* -*===============================================================================*/ -static int -Parser_skipString( INOUT char **pstrSrc, - IN const char *strSkipKey ) + +/*! + * \brief Skips all characters in the string until it finds the skip key. + * Then it skips the skip key and returns. + */ +static int Parser_skipString( + /*! [in,out] The pointer to the skipped point. */ + char **pstrSrc, + /*! [in] The skip key. */ + const char *strSkipKey) { if( !( *pstrSrc ) || !strSkipKey ) { return IXML_FAILED; @@ -1312,15 +1406,13 @@ Parser_skipString( INOUT char **pstrSrc, return IXML_SUCCESS; //success } -/*==============================================================================* -* -* Function: -* Returns: -* -* -*===============================================================================*/ -static int -Parser_skipPI( INOUT char **pSrc ) + +/*! + * \brief + */ +static int Parser_skipPI( + /*! [in,out] The pointer to the skipped point. */ + char **pSrc) { char *pEnd = NULL; @@ -1329,11 +1421,13 @@ Parser_skipPI( INOUT char **pSrc ) return IXML_FAILED; } - if( ( strncasecmp( *pSrc, ( char * )XMLDECL, strlen( XMLDECL ) ) == 0 ) || ( strncasecmp( *pSrc, ( char * )XMLDECL2, strlen( XMLDECL2 ) ) == 0 ) ) { // not allowed + if ((strncasecmp(*pSrc, (char *)XMLDECL , strlen(XMLDECL )) == 0) || + (strncasecmp(*pSrc, (char *)XMLDECL2, strlen(XMLDECL2)) == 0)) { + /* not allowed */ return IXML_SYNTAX_ERR; } - if( strncasecmp( *pSrc, ( char * )BEGIN_PI, strlen( BEGIN_PI ) ) == 0 ) { + if (strncasecmp(*pSrc, (char *)BEGIN_PI, strlen(BEGIN_PI)) == 0) { pEnd = strstr( *pSrc, END_PI ); if( ( pEnd != NULL ) && ( pEnd != *pSrc ) ) { *pSrc = pEnd + strlen( BEGIN_PI ); @@ -1345,14 +1439,13 @@ Parser_skipPI( INOUT char **pSrc ) return IXML_SUCCESS; } -/*==============================================================================* -* Parser_skipXMLDecl: -* skips XML declarations. -* Internal only to parser. -* -*===============================================================================*/ -static int -Parser_skipXMLDecl( INOUT Parser * xmlParser ) + +/*! + * \brief Skips XML declarations. + */ +static int Parser_skipXMLDecl( + /*! [in,out] The XML parser. */ + Parser *xmlParser) { int rc = IXML_FAILED; @@ -1364,17 +1457,15 @@ Parser_skipXMLDecl( INOUT Parser * xmlParser ) rc = Parser_skipString( &( xmlParser->curPtr ), END_PI ); Parser_skipWhiteSpaces( xmlParser ); return rc; - } -/*==============================================================================* -* Parser_skipProlog -* skip prolog -* Internal to parser only. -* -*===============================================================================*/ -static int -Parser_skipProlog( INOUT Parser * xmlParser ) + +/*! + * \brief Skip prolog. + */ +static int Parser_skipProlog( + /*! [in,out] The XML parser. */ + Parser *xmlParser) { int rc = IXML_SUCCESS; @@ -1385,7 +1476,8 @@ Parser_skipProlog( INOUT Parser * xmlParser ) Parser_skipWhiteSpaces( xmlParser ); - if( strncmp( xmlParser->curPtr, ( char * )XMLDECL, strlen( XMLDECL ) ) == 0 ) { // curPtr, ( char * )XMLDECL, strlen( XMLDECL ) ) == 0 ) { + /* curPtr, ( char * )BEGIN_DOCTYPE, strlen( BEGIN_DOCTYPE ) ) == 0 ) { // curPtr, ( char * )BEGIN_DOCTYPE, strlen( BEGIN_DOCTYPE ) ) == 0 ) { + // curPtr++; rc = Parser_skipDocType( &( xmlParser->curPtr ) ); } @@ -1405,16 +1499,14 @@ Parser_skipProlog( INOUT Parser * xmlParser ) return rc; } -/*==============================================================================* -* -* Function: -* Returns: -* Skips all characters in the string until it finds the skip key. -* Then it skips the skip key and returns. -* -*===============================================================================*/ -static int -Parser_skipComment( INOUT char **pstrSrc ) + +/*! + * \brief Skips all characters in the string until it finds the skip key. + * Then it skips the skip key and returns. + */ +static int Parser_skipComment( + /*! [in,out] The pointer to the skipped point. */ + char **pstrSrc) { char *pStrFound = NULL; @@ -1434,13 +1526,13 @@ Parser_skipComment( INOUT char **pstrSrc ) return IXML_SUCCESS; } -/*==============================================================================* -* Parser_skipDocType -* skips document type declaration -* -*===============================================================================*/ -static int -Parser_skipDocType( INOUT char **pstr ) + +/*! + * \brief Skips document type declaration + */ +static int Parser_skipDocType( + /*! [in,out] The pointer to the skipped point. */ + char **pstr) { char *pCur = *pstr; char *pNext = NULL; // default there is no nested < @@ -1476,26 +1568,27 @@ Parser_skipDocType( INOUT char **pstr ) } } -/*==============================================================================* -* -* Parser_skipMisc: -* skip comment, PI and white space -* -* -*===============================================================================*/ -static int -Parser_skipMisc( IN Parser * xmlParser ) + +/*! + * \brief Skip comment, PI and white space. + */ +static int Parser_skipMisc( + /*! [in] The XML parser. */ + Parser *xmlParser) { int rc = IXML_SUCCESS; int done = FALSE; while( ( done == FALSE ) && ( rc == IXML_SUCCESS ) ) { - if( strncasecmp( xmlParser->curPtr, ( char * )BEGIN_COMMENT, strlen( BEGIN_COMMENT ) ) == 0 ) { //