ixmlparser.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. /**************************************************************************
  2. *
  3. * Copyright (c) 2000-2003 Intel Corporation
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * - Redistributions of source code must retain the above copyright notice,
  10. * this list of conditions and the following disclaimer.
  11. * - Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. * - Neither name of Intel Corporation nor the names of its contributors
  15. * may be used to endorse or promote products derived from this software
  16. * without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
  22. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  26. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. **************************************************************************/
  31. #ifndef IXMLPARSER_H
  32. #define IXMLPARSER_H
  33. /*!
  34. * \file
  35. */
  36. #include "ixml.h"
  37. #include "ixmlmembuf.h"
  38. /* Parser definitions */
  39. #define QUOT """
  40. #define LT "<"
  41. #define GT ">"
  42. #define APOS "'"
  43. #define AMP "&"
  44. #define ESC_HEX "&#x"
  45. #define ESC_DEC "&#"
  46. typedef struct _IXML_NamespaceURI
  47. {
  48. char *nsURI;
  49. char *prefix;
  50. struct _IXML_NamespaceURI *nextNsURI;
  51. } IXML_NamespaceURI;
  52. typedef struct _IXML_ElementStack
  53. {
  54. char *element;
  55. char *prefix;
  56. char *namespaceUri;
  57. IXML_NamespaceURI *pNsURI;
  58. struct _IXML_ElementStack *nextElement;
  59. } IXML_ElementStack;
  60. typedef enum
  61. {
  62. eELEMENT,
  63. eATTRIBUTE,
  64. eCONTENT,
  65. } PARSER_STATE;
  66. typedef struct _Parser
  67. {
  68. /*! Data buffer. */
  69. char *dataBuffer;
  70. /*! Pointer to the token parsed. */
  71. char *curPtr;
  72. /*! Saves for backup. */
  73. char *savePtr;
  74. ixml_membuf lastElem;
  75. ixml_membuf tokenBuf;
  76. IXML_Node *pNeedPrefixNode;
  77. IXML_ElementStack *pCurElement;
  78. IXML_Node *currentNodePtr;
  79. PARSER_STATE state;
  80. BOOL bHasTopLevel;
  81. } Parser;
  82. /*!
  83. * \brief Check to see whether name is a valid xml name.
  84. */
  85. BOOL Parser_isValidXmlName(
  86. /*! [in] The string to be checked. */
  87. const DOMString name);
  88. /*!
  89. * \brief Sets the error character.
  90. *
  91. * If 'c' is 0 (default), the parser is strict about XML encoding:
  92. * invalid UTF-8 sequences or "&" entities are rejected, and the parsing
  93. * aborts.
  94. *
  95. * If 'c' is not 0, the parser is relaxed: invalid UTF-8 characters
  96. * are replaced by this character, and invalid "&" entities are left
  97. * untranslated. The parsing is then allowed to continue.
  98. */
  99. void Parser_setErrorChar(
  100. /*! [in] The character to become the error character. */
  101. char c);
  102. /*!
  103. * \brief Fees a node contents.
  104. */
  105. void Parser_freeNodeContent(
  106. /*! [in] The Node to process. */
  107. IXML_Node *IXML_Nodeptr);
  108. int Parser_LoadDocument(IXML_Document **retDoc, const char * xmlFile, BOOL file);
  109. int Parser_setNodePrefixAndLocalName(IXML_Node *newIXML_NodeIXML_Attr);
  110. void ixmlAttr_init(IXML_Attr *attrNode);
  111. /*!
  112. * \brief Set the given element's tagName.
  113. *
  114. * \return One of the following:
  115. * \li \b IXML_SUCCESS, if successfull.
  116. * \li \b IXML_FAILED, if element of tagname is \b NULL.
  117. * \li \b IXML_INSUFFICIENT_MEMORY, if there is no memory to allocate the
  118. * buffer for the element's tagname.
  119. */
  120. int ixmlElement_setTagName(
  121. /*! [in] The element to change the tagname. */
  122. IXML_Element *element,
  123. /*! [in] The new tagName for the element. */
  124. const char *tagName);
  125. /*!
  126. * \brief Initializes a NamedNodeMap object.
  127. */
  128. void ixmlNamedNodeMap_init(
  129. /*! [in] The named node map to process. */
  130. IXML_NamedNodeMap *nnMap);
  131. /*!
  132. * \brief Add a node to a NamedNodeMap.
  133. *
  134. * \return IXML_SUCCESS or failure.
  135. */
  136. int ixmlNamedNodeMap_addToNamedNodeMap(
  137. /* [in] The named node map. */
  138. IXML_NamedNodeMap **nnMap,
  139. /* [in] The node to add. */
  140. IXML_Node *add);
  141. /*!
  142. * \brief Add a node to nodelist.
  143. */
  144. int ixmlNodeList_addToNodeList(
  145. /*! [in] The pointer to the nodelist. */
  146. IXML_NodeList **nList,
  147. /*! [in] The node to add. */
  148. IXML_Node *add);
  149. /*!
  150. * \brief Intializes a node.
  151. */
  152. void ixmlNode_init(
  153. /*! [in] The \b Node to iniatialize. */
  154. IN IXML_Node *nodeptr);
  155. /*!
  156. * \brief Compare two nodes to see whether they are the same node.
  157. * Parent, sibling and children node are ignored.
  158. *
  159. * \return
  160. * \li TRUE, the two nodes are the same.
  161. * \li FALSE, the two nodes are not the same.
  162. */
  163. BOOL ixmlNode_compare(
  164. /*! [in] The first \b Node. */
  165. IXML_Node *srcNode,
  166. /*! [in] The second \b Node. */
  167. IXML_Node *destNode);
  168. /*!
  169. * \brief Returns a nodeList of all descendant Elements with a given tagName,
  170. * in the order in which they are encountered in a traversal of this element
  171. * tree.
  172. */
  173. void ixmlNode_getElementsByTagName(
  174. /*! [in] The \b Node tree. */
  175. IXML_Node *n,
  176. /*! [in] The tag name to match. */
  177. const char *tagname,
  178. /*! [out] The output \b NodeList. */
  179. IXML_NodeList **list);
  180. /*!
  181. * \brief Returns a nodeList of all the descendant Elements with a given local
  182. * name and namespace URI in the order in which they are encountered in a
  183. * preorder traversal of this Elememt tree.
  184. */
  185. void ixmlNode_getElementsByTagNameNS(
  186. /*! [in] The \b Element tree. */
  187. IXML_Node *n,
  188. /*! [in] The name space to match. */
  189. const char *namespaceURI,
  190. /*! [in] The local name to match. */
  191. const char *localName,
  192. /*! [out] The output \b NodeList. */
  193. IXML_NodeList **list);
  194. /*!
  195. * \brief
  196. *
  197. * \return
  198. */
  199. int ixmlNode_setNodeName(
  200. /*! [in] The \b Node. */
  201. IXML_Node *node,
  202. /*! [in] . */
  203. const DOMString qualifiedName);
  204. /*!
  205. * \brief
  206. *
  207. * \return
  208. */
  209. int ixmlNode_setNodeProperties(
  210. /*! [in] . */
  211. IXML_Node *destNode,
  212. /*! [in] . */
  213. IXML_Node *src);
  214. /*!
  215. * \brief Initializes a nodelist
  216. */
  217. void ixmlNodeList_init(
  218. /*! [in,out] The \b NodeList to initialize. */
  219. IXML_NodeList *nList);
  220. #endif /* IXMLPARSER_H */