Advertisement
Guest User

xmlreader.h

a guest
Oct 4th, 2010
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.28 KB | None | 0 0
  1. /*
  2.  *******************************************************************************
  3.  * xmlreader.h
  4.  * Creation date: 01.11.2007
  5.  * Author:        Firoball
  6.  *
  7.  *******************************************************************************
  8.  * $Date: 2010-08-05 00:23:10 +0200 (Do, 05 Aug 2010) $
  9.  * $Revision: 4 $
  10.  * $Author: Firo $
  11.  *
  12.  *******************************************************************************
  13.  * Description
  14.  *
  15.  * Definition script for XML parser
  16.  *
  17.  * Comments
  18.  *
  19.  * for short descriptions see comments in this file
  20.  *
  21.  *******************************************************************************
  22.  */
  23.  
  24. #ifndef XMLREADER_H
  25. #define XMLREADER_H
  26. /*! \file
  27.  *  Include file for XML file parser.
  28.  */
  29.  
  30. /* ----- INCLUDES ----- */
  31.  
  32.  
  33. #include "..\list\list.h"
  34.  
  35.  
  36. /* ----- DEFINITIONS ----- */
  37.  
  38.  
  39. #define XMLREADER_ACTIVE    /*!< This define can be evaluated to check if this module is included and active */
  40.  
  41. /*! \name Constant Data
  42.  *  These constants are used as identifiers in certain functions.
  43.  * \{ */
  44. #define XML_NOTAG -1
  45. #define XML_CONTENT 0
  46. #define XML_OPENTAG 1
  47. #define XML_CLOSETAG 2
  48. #define XML_EOF 255
  49.  
  50. #define EOF 255
  51. /* \} */
  52.  
  53.  
  54. /* ----- STRUCTURES ----- */
  55.  
  56.  
  57. /*! Definition of a XML parameter.
  58.  *  Each parameter (tag) found in a XML file is represented by this structure.
  59.  *  Use the XMLPAR_create function for creation of a new XML parameter.
  60.  */
  61. typedef struct xmlpar
  62. {
  63.     STRING* strTag;     /*!< String pointer to tag name */
  64.     STRING* strContent; /*!< String pointer to tag content */
  65.     LIST* psTagList;        /*!< Pointer to a list of sub tags */
  66.     LIST* psAttribList; /*!< Pointer to a list of tag attributes */
  67.     struct xmlpar* psParent;
  68. }XMLPAR;
  69.  
  70. /*! Definition of a XML file.
  71.  *  For reading data from an XML file, this object is required.
  72.  *  Use the XMLFILE_create function for creation of a new XML file.
  73.  */
  74. typedef struct
  75. {
  76.     var vFHndl;         /*!< File handle (Acknex format) */
  77.     STRING* vFName; /*!< String pointer to xml filename */
  78.     XMLPAR* psAnchor;   /*!< Pointer to root XML parameter ("XML_root") */
  79.        
  80.     /* temp variables */
  81.     char cTmp[2];   /*!< For temporary use */
  82.     int iTmp;       /*!< For temporary use */
  83. }XMLFILE;
  84.  
  85. /*! Definition of a XML attribute.
  86.  *  Each attribute  of a XML tag is represented by this structure.
  87.  *  Use the XMLATTRIB_create function for creation of a new XML attribute.
  88.  */
  89. typedef struct
  90. {
  91.     STRING* strTag;     /*!< String pointer to attribute name */
  92.     STRING* strContent; /*!< String pointer to attribute content */
  93.     XMLPAR* psParent;       /*!< Pointer to parent XML parameter (tag) */
  94. }XMLATTRIB;
  95.  
  96.  
  97. /* ----- EXTERNAL FUNCTIONS ----- */
  98.  
  99.  
  100. /*! Open new xml file.
  101.  *  \param  pcFile Pointer: full name of xml file
  102.  *  \return Pointer to XMLFILE
  103.  */
  104. XMLFILE* XMLFILE_create(char* pcFile);
  105.  
  106. /*! Removes XMLFILE from memory. Delete all allocated content.
  107.  *  \param  psHost Pointer to XMLFILE to be deleted
  108.  */
  109. void XMLFILE_remove(XMLFILE* psHost);
  110.  
  111. /*! Read XML file into memory
  112.  *  \param  psHost Pointer to XMLFILE to be parsed
  113.  *  \return Pointer to root element of XML list
  114.  */
  115. XMLPAR* XMLFILE_parse(XMLFILE* psHost);
  116.  
  117.  
  118. /*! Creates new XMLPAR
  119.  *  \return Pointer to XMLPAR
  120.  */
  121. XMLPAR* XMLPAR_create();
  122.  
  123. /*! Removes XMLPAR from memory. Delete all allocated content.
  124.  *  \param  psHost Pointer to XMLPAR to be deleted
  125.  */
  126. void XMLPAR_remove(XMLPAR* psHost);
  127.  
  128. /*! Copy tag content to specified string.
  129.  *  \param  psHost Pointer to XMLPAR to be accessed
  130.  *  \param  strTarget String pointer to string to be filled
  131.  */
  132. void XMLPAR_getContent(XMLPAR* psHost, STRING* strTarget);
  133.  
  134. /*! Copy tag name to specified string.
  135.  *  \param  psHost Pointer to XMLPAR to be accessed
  136.  *  \param  strTarget String pointer to string to be filled
  137.  */
  138. void XMLPAR_getTag(XMLPAR* psHost, STRING* strTarget);
  139.  
  140. /*! Retrieve pointer to tag content.
  141.  *  \param  psHost Pointer to XMLPAR to be accessed
  142.  *  \return String pointer to tag name/tag content
  143.  */
  144. STRING* XMLPAR_getPContent(XMLPAR* psHost);
  145.  
  146. /*! Retrieve pointer to tag name.
  147.  *  \param  psHost Pointer to XMLPAR to be accessed
  148.  *  \return String pointer to tag name/tag content
  149.  */
  150. STRING* XMLPAR_getPTag(XMLPAR* psHost);
  151.  
  152. /*! Find specified tag inside parent XML parameter.
  153.  *  \param  psHost Pointer to parent XMLPAR
  154.  *  \param  strTag String pointer: name of xml tag
  155.  *  \return Pointer to found XMLPAR or NULL
  156.  */
  157. XMLPAR* XMLPAR_getElementByTag(XMLPAR* psHost, STRING* strTag);
  158.  
  159. /*! Find specified tag inside parent XML parameter.
  160.  *  \param  psHost Pointer to parent XMLPAR
  161.  *  \param  iIndex Index of xml tag
  162.  *  \return Pointer to found XMLPAR or NULL
  163.  */
  164. XMLPAR* XMLPAR_getElementByIndex(XMLPAR* psHost, int iIndex);
  165.  
  166. /*! Retrieve number of sub tags of XML parameter.  
  167.  *  \param  psHost Pointer to XMLPAR to be accessed
  168.  *  \return Number of sub tags
  169.  */
  170. int XMLPAR_getTagElements(XMLPAR* psHost);
  171.  
  172. /*! Retrieve number of attributes of XML parameter.
  173.  *  \param  psHost Pointer to XMLPAR to be accessed
  174.  *  \return Number of attributes
  175.  */
  176. int XMLPAR_getAttributeElements(XMLPAR* psHost);
  177.  
  178. /*! Creates new XML attribute.
  179.  *  \return Pointer to XMLATTRIB
  180.  */
  181. XMLATTRIB* XMLATTRIB_create();
  182.  
  183. /*! Removes XML attribute from memory. Delete all allocated content.
  184.  *  \param  psHost Pointer to XMLATTRIB to be deleted
  185.  */
  186. void XMLATTRIB_remove(XMLATTRIB* psHost);
  187.  
  188. /*! Copy tag content to specified string.
  189.  *  \param  psHost XMLATTRIB to be accessed
  190.  *  \param  strTarget String pointer to string to be filled
  191.  */
  192. void XMLATTRIB_getContent(XMLATTRIB* psHost, STRING* strTarget);
  193.  
  194. /*! Copy tag name to specified string.
  195.  *  \param  psHost XMLATTRIB to be accessed
  196.  *  \param  strTarget String pointer to string to be filled
  197.  */
  198. void XMLATTRIB_getAttribute(XMLATTRIB* psHost, STRING* strTarget);
  199.  
  200. /*! Retrieve pointer to attribute content.
  201.  *  \param  psHost Pointer to XMLATTRIB to be accessed
  202.  *  \return String pointer to tag name/tag content
  203.  */
  204. STRING* XMLATTRIB_getPContent(XMLATTRIB* psHost);
  205.  
  206. /*! Retrieve pointer to attribute name.
  207.  *  \param  psHost Pointer to XMLATTRIB to be accessed
  208.  *  \return String pointer to tag name/tag content
  209.  */
  210. STRING* XMLATTRIB_getPAttribute(XMLATTRIB* psHost);
  211.  
  212. /*! Find specified attribute inside parent XML parameter.  
  213.  *  \param  psHost Pointer to parent XMLPAR
  214.  *  \param  strTag String pointer: name of xml attribute
  215.  *  \return Pointer to found XMLATTRIB or NULL
  216.  */
  217. XMLATTRIB* XMLATTRIB_getElementByAttribute(XMLPAR* psHost, STRING* strTag);
  218.  
  219. /*! Find specified attribute inside parent XML parameter.
  220.  *  \param  psHost Pointer to parent XMLPAR
  221.  *  \param  iIndex Index of xml attribute
  222.  *  \return Pointer to found XMLATTRIB or NULL
  223.  */
  224. XMLATTRIB* XMLATTRIB_getElementByIndex(XMLPAR* psHost, int iIndex);
  225.  
  226.  
  227. /* ----- INTERNAL FUNCTIONS - DO NOT USE ----- */
  228.  
  229. /*! \internal - Do not use! */
  230. int XMLFILE__read(XMLFILE* psHost, XMLPAR* parentPar, int ntag);
  231. /*! \internal - Do not use! */
  232. void XMLFILE__readTagAttrib(XMLFILE* psHost, XMLPAR* par);
  233. /*! \internal - Do not use! */
  234. int XMLFILE__readOpenTag(XMLFILE* psHost, XMLPAR* par);
  235. /*! \internal - Do not use! */
  236. void XMLFILE__readCloseTag(XMLFILE* psHost);
  237. /*! \internal - Do not use! */
  238. void XMLFILE__readContent(XMLFILE* psHost, XMLPAR* par);
  239. /*! \internal - Do not use! */
  240. int XMLFILE__findNext(XMLFILE* psHost);
  241.  
  242.  
  243. #include "xmlreader.c"
  244.  
  245. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement