File:  [ELWIX - Embedded LightWeight unIX -] / gpl / axl / src / axl_node.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 8 07:09:12 2011 UTC (13 years, 1 month ago) by misho
Branches: axl, MAIN
CVS tags: HEAD, AXL0_6_7, AXL0_6_1
3th party - XML

    1: /*
    2:  *  LibAxl:  Another XML library
    3:  *  Copyright (C) 2006 Advanced Software Production Line, S.L.
    4:  *
    5:  *  This program is free software; you can redistribute it and/or
    6:  *  modify it under the terms of the GNU Lesser General Public License
    7:  *  as published by the Free Software Foundation; either version 2.1 of
    8:  *  the License, or (at your option) any later version.
    9:  *
   10:  *  This program is distributed in the hope that it will be useful,
   11:  *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
   12:  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
   13:  *  GNU Lesser General Public License for more details.
   14:  *
   15:  *  You should have received a copy of the GNU Lesser General Public
   16:  *  License along with this program; if not, write to the Free
   17:  *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   18:  *  02111-1307 USA
   19:  *  
   20:  *  You may find a copy of the license under this software is released
   21:  *  at COPYING file. This is LGPL software: you are welcome to
   22:  *  develop proprietary applications using this library without any
   23:  *  royalty or fee but returning back any change, improvement or
   24:  *  addition in the form of source code, project image, documentation
   25:  *  patches, etc. 
   26:  *
   27:  *  For commercial support on build XML enabled solutions contact us:
   28:  *          
   29:  *      Postal address:
   30:  *         Advanced Software Production Line, S.L.
   31:  *         Edificio Alius A, Oficina 102,
   32:  *         C/ Antonio Suarez Nº 10,
   33:  *         Alcalá de Henares 28802 Madrid
   34:  *         Spain
   35:  *
   36:  *      Email address:
   37:  *         info@aspl.es - http://www.aspl.es/xml
   38:  */
   39: #ifndef __AXL_NODE_H__
   40: #define __AXL_NODE_H__
   41: 
   42: #include <axl_decl.h>
   43: 
   44: BEGIN_C_DECLS
   45: 
   46: /** 
   47:  * \addtogroup axl_node_module
   48:  * @{
   49:  */
   50: 
   51: axlNode * axl_node_create                   (const char * name);
   52: 
   53: axlNode * axl_node_create_ref               (char * name);
   54: 
   55: axlNode * axl_node_parse_strings            (axlError ** error, ...);
   56: 
   57: axlNode * axl_node_parse                    (axlError ** error, const char * content, ...);
   58: 
   59: void      axl_node_set_name                 (axlNode * node, 
   60: 					     const char * name);
   61: 
   62: void      axl_node_set_name_ref             (axlNode * node, 
   63: 					     char * name);
   64: 
   65: void      axl_node_set_name_from_factory    (axlNode * node, 
   66: 					     char * name);
   67: 
   68: axlNode * axl_node_copy                     (axlNode * node,
   69: 					     axl_bool  copy_attributes,
   70: 					     axl_bool  copy_childs);
   71: 
   72: axlDoc  * axl_node_get_doc                  (axlNode * node);
   73: 
   74: void      axl_node_set_doc                  (axlNode * node, 
   75: 					     axlDoc  * doc);
   76: 
   77: void      axl_node_set_attribute            (axlNode    * node, 
   78: 					     const char * attribute, 
   79: 					     const char * value);
   80: 
   81: void      axl_node_set_attribute_ref        (axlNode * node, 
   82: 					     char    * attribute, 
   83: 					     char    * value);
   84: 
   85: void      axl_node_set_attribute_from_factory  (axlFactory * factory, 
   86: 						axlNode    * node, 
   87: 						char       * attribute, 
   88: 						char       * value);
   89: 
   90: /** 
   91:  * @brief Macro definition which works as an alias for \ref
   92:  * axl_node_get_attribute_value.
   93:  * 
   94:  * @param node The node being checked to have an attribute value.
   95:  * @param attr The attribute that is being check to be present in the node provided.
   96:  * 
   97:  * @return \ref axl_true if the node has the provided attribute, otherwise
   98:  * \ref axl_false is returned.
   99:  */
  100: #define HAS_ATTR(node,attr) axl_node_has_attribute(node,attr)
  101: 
  102: axl_bool  axl_node_has_attribute            (axlNode    * node, 
  103: 					     const char * attribute);
  104: 
  105: void      axl_node_remove_attribute         (axlNode    * node,
  106: 					     const char * attribute);
  107: 
  108: int       axl_node_num_attributes           (axlNode    * node);
  109: 					     
  110: 
  111: /** 
  112:  * @brief Macro definition, which works as an alias for \ref
  113:  * axl_node_get_attribute_value.
  114:  * 
  115:  * @param node The node that is being required to return the content
  116:  * of a particular node.
  117:  *
  118:  * @param attr The attribute that is requested.
  119:  * 
  120:  * @return The value assocaited to the attribute value or null if it
  121:  * fails. See \ref axl_node_get_attribute_value.
  122:  */
  123: #define ATTR_VALUE(node,attr) axl_node_get_attribute_value(node, attr)
  124: 
  125: const char    * axl_node_get_attribute_value      (axlNode    * node, 
  126: 						   const char * attribute);
  127: 
  128: char    * axl_node_get_attribute_value_copy (axlNode    * node, 
  129: 					     const char * attribute);
  130: 
  131: /** 
  132:  * @brief Simple alias definition to \ref axl_node_get_attribute_value_trans function.
  133:  * 
  134:  * @param node The node which contains the attribute requested.
  135:  *
  136:  * @param attr The attribute key that is being requested.
  137:  * 
  138:  * @return A newly allocated string containing the attribute value,
  139:  * with known entity references translated.
  140:  */
  141: #define ATTR_VALUE_TRANS(node,attr) axl_node_get_attribute_value_trans(node,attr)
  142: 
  143: char    * axl_node_get_attribute_value_trans (axlNode * node, 
  144: 					      const char * attribute);
  145: 
  146: /** 
  147:  * @brief Allows to get the value associated to the attributed
  148:  * provided, inside the node selected, removing trailing and ending
  149:  * white spaces (in the W3C sence: \\n, \\t, \\r, ' ').
  150:  *
  151:  * This is a macro alias to \ref axl_node_get_attribute_value_trimmed.
  152:  * 
  153:  * @param node The node that is requested to return the associated 
  154:  * value to the attributed.
  155:  *
  156:  * @param attr The attribute that is being requested.
  157:  * 
  158:  * @return A reference to the attribute value or NULL if it fails.
  159:  */
  160: #define ATTR_VALUE_TRIMMED(node,attr) axl_node_get_attribute_value_trimmed(node,attr)
  161: 
  162: const char    * axl_node_get_attribute_value_trimmed (axlNode    * node,
  163: 						      const char * attribute);
  164: 
  165: /**
  166:  * @brief Convenience macro wrapping \ref
  167:  * axl_node_has_attribute_value.
  168:  */
  169: #define HAS_ATTR_VALUE(node, attr,value) (axl_node_has_attribute_value (node, attr, value))
  170: 
  171: axl_bool      axl_node_has_attribute_value       (axlNode    * node, 
  172: 						  const char * attribute, 
  173: 						  const char * value);
  174: 
  175: axl_bool      axl_node_has_attributes (axlNode * node);
  176: 
  177: /**
  178:  * @}
  179:  */
  180: 
  181: /** 
  182:  * \addtogroup axl_node_attribute_cursor
  183:  * @{
  184:  */
  185: 
  186: /* XML node attribute iteration API provided to traverse all
  187:  * attributes without knowing them. */
  188: axlAttrCursor * axl_node_attr_cursor_new       (axlNode * node);
  189: 
  190: void            axl_node_attr_cursor_first     (axlAttrCursor * cursor);
  191: 
  192: void            axl_node_attr_cursor_next      (axlAttrCursor * cursor);
  193: 
  194: axl_bool        axl_node_attr_cursor_has_next  (axlAttrCursor * cursor);
  195: 
  196: axl_bool        axl_node_attr_cursor_has_item  (axlAttrCursor * cursor);
  197: 
  198: const char *    axl_node_attr_cursor_get_key   (axlAttrCursor * cursor);
  199: 
  200: const char *    axl_node_attr_cursor_get_value (axlAttrCursor * cursor);
  201: 
  202: void            axl_node_attr_cursor_free      (axlAttrCursor * cursor);
  203: 
  204: void            axl_node_attr_foreach          (axlNode       * node, 
  205: 						axlNodeAttrForeachFunc func, 
  206: 						axlPointer      data,
  207: 						axlPointer      data2);
  208: 	
  209: 
  210: /**
  211:  * @}
  212:  */
  213: 
  214: /** 
  215:  * \addtogroup axl_node_annotate
  216:  * @{
  217:  */
  218: 
  219: void      axl_node_annotate_data                 (axlNode     * node, 
  220: 						 const char  * key, 
  221: 						 axlPointer    data);
  222: 
  223: void      axl_node_annotate_data_full            (axlNode       * node,
  224: 						 const char    * key, 
  225: 						 axlDestroyFunc  key_destroy,
  226: 						 axlPointer      data,
  227: 						 axlDestroyFunc  data_destroy);
  228: 
  229: axlPointer axl_node_annotate_get                 (axlNode       * node,
  230: 						  const char    * key,
  231: 						  axl_bool        lookup_in_parent);
  232: 
  233: void       axl_node_annotate_int                 (axlNode * node,
  234: 						  const char    * key,
  235: 						  int             int_value);
  236: 
  237: void       axl_node_annotate_string              (axlNode * node,
  238: 						 const char    * key,
  239: 						 const char    * string_value);
  240: 
  241: void       axl_node_annotate_double              (axlNode    * node,
  242: 						 const char * key,
  243: 						 double       double_value);
  244: 
  245: int        axl_node_annotate_get_int             (axlNode     * node,
  246: 						 const char   * key,
  247: 						 axl_bool       lookup_in_parent);
  248: 
  249: char *     axl_node_annotate_get_string          (axlNode       * node,
  250: 						 const char     * key,
  251: 						 axl_bool         lookup_in_parent);
  252: 
  253: double     axl_node_annotate_get_double          (axlNode      * node,
  254: 						 const char    * key,
  255: 						 axl_bool        lookup_in_parent);
  256: 
  257: /**
  258:  * @}
  259:  */
  260: 
  261: 
  262: /** 
  263:  * \addtogroup axl_node_module
  264:  * @{
  265:  */
  266: 
  267: /** 
  268:  * @brief Allows to easily check that the given xml node (\ref
  269:  * axlNode) have the provided name.
  270:  *
  271:  * This macro is provided as a convenience to check that a particular
  272:  * node have a particular name. Check the documentation that this
  273:  * macro is wrapping to get examples: \ref axl_node_get_name.
  274:  *
  275:  * <i><b>NOTE:</b> This function isn't XML Namespace aware. You must use \ref axl_ns_node_cmp instead. See \ref axl_ns_doc_validate. </i>
  276:  * 
  277:  * @param node The \ref axlNode where the name will be compared with
  278:  * the provided value.
  279:  *
  280:  * @param name The name to compare.
  281:  * 
  282:  * @return \ref axl_true if names are equal or \ref axl_false if not.
  283:  */
  284: #define NODE_CMP_NAME(node,name) (axl_cmp ((node != NULL) ? axl_node_get_name(node) : "><", (name != NULL) ? name : "<>"))
  285: 
  286: const char * axl_node_get_name           (axlNode * node);
  287: 
  288: axlNode * axl_node_get_parent         (axlNode * node);
  289: 
  290: axlNode * axl_node_get_next           (axlNode * node);
  291: 
  292: axlNode * axl_node_get_next_called    (axlNode    * node, 
  293: 				       const char * name);
  294: 
  295: axlNode * axl_node_get_previous         (axlNode * node);
  296: 
  297: axlNode * axl_node_get_previous_called  (axlNode    * node, 
  298: 					 const char * name);
  299: 
  300: axlNode * axl_node_get_first_child    (axlNode * node);
  301: 
  302: axlNode * axl_node_get_last_child     (axlNode * node);
  303: 
  304: void      axl_node_set_child          (axlNode * parent, 
  305: 				       axlNode * child);
  306: 
  307: void      axl_node_set_child_after    (axlNode * reference,
  308: 				       axlNode * child);
  309: 
  310: void      axl_node_replace            (axlNode * node, 
  311: 				       axlNode * new_node,
  312: 				       axl_bool  dealloc);
  313: 
  314: void      axl_node_remove             (axlNode * node,
  315: 				       axl_bool  dealloc);
  316: 
  317: void      axl_node_deattach           (axlNode * node);
  318: 				       
  319: 
  320: void      axl_node_set_is_empty       (axlNode  * node, 
  321: 				       axl_bool   empty);
  322: 
  323: axl_bool      axl_node_is_empty           (axlNode * node);
  324: 
  325: const char    * axl_node_get_content  (axlNode * node, 
  326: 				       int  * content_size);
  327: 
  328: char    * axl_node_get_content_copy   (axlNode * node, 
  329: 				       int  * content_size);
  330: 
  331: char    * axl_node_get_content_trans  (axlNode * node, 
  332: 				       int * content_size);
  333: 
  334: char    * axl_node_get_content_trim   (axlNode * node,
  335: 				       int * content_size);
  336: 
  337: void      axl_node_set_content        (axlNode    * node, 
  338: 				       const char * content, 
  339: 				       int content_size);
  340: 
  341: void      axl_node_set_content_ref    (axlNode * node, 
  342: 				       char * content, 
  343: 				       int content_size);
  344: 
  345: void      axl_node_set_content_from_factory (axlFactory * factory,
  346: 					     axlNode    * node,
  347: 					     char       * content,
  348: 					     int          content_size);
  349: 
  350: void      axl_node_set_cdata_content  (axlNode    * node,
  351: 				       const char * content,
  352: 				       int          content_size);
  353: 
  354: void      axl_node_set_cdata_content_from_factory (axlFactory  * factory,
  355: 						   axlNode     * node,
  356: 						   char        * content,
  357: 						   int           content_size);
  358: 
  359: void      axl_node_set_comment        (axlNode * node,
  360: 				       char * comment,
  361: 				       int    comment_size);
  362: 
  363: void      axl_node_set_have_childs    (axlNode * node, axl_bool childs);
  364: 
  365: axl_bool  axl_node_have_childs        (axlNode * node);
  366: 
  367: axlNode * axl_node_get_child_called   (axlNode * parent, const char * name);
  368: 
  369: axlNode * axl_node_find_called        (axlNode * parent, const char * name);
  370: 
  371: axlNode * axl_node_get_child_nth      (axlNode * parent, int position);
  372: 
  373: int       axl_node_get_child_num      (axlNode * parent);
  374: 
  375: axlList * axl_node_get_childs         (axlNode * node);
  376: 
  377: axl_bool  axl_node_are_equal          (axlNode * node, axlNode * node2);
  378: 
  379: axl_bool  axl_node_are_equal_full     (axlNode * node, axlNode * node2, axlError ** error);
  380: 
  381: void      axl_node_add_pi_target            (axlNode * node, 
  382: 					     char * target, 
  383: 					     char * content);
  384: 
  385: axl_bool  axl_node_has_pi_target            (axlNode * node, 
  386: 					     char * pi_target);
  387: 
  388: char    * axl_node_get_pi_target_content    (axlNode * node, 
  389: 					     char * pi_target);
  390: 
  391: axlList * axl_node_get_pi_target_list       (axlNode * node);
  392: 
  393: void      axl_node_transfer_childs          (axlNode * old_parent, 
  394: 					     axlNode * new_parent);
  395: 
  396: axl_bool  axl_node_dump                    (axlNode  * node, 
  397: 					    char    ** content, 
  398: 					    int      * size);
  399: 
  400: axl_bool  axl_node_dump_pretty             (axlNode  * node,
  401: 					    char    ** content,
  402: 					    int      * size,
  403: 					    int        tabular);
  404: 
  405: axl_bool  axl_node_dump_to_file            (axlNode  * node,
  406: 					    char     * file_path);
  407: 
  408: axl_bool  axl_node_dump_pretty_to_file     (axlNode  * node,
  409: 					    char     * file_path,
  410: 					    int        tabular);
  411: 
  412: int       axl_node_get_flat_size            (axlNode * node,
  413: 					     axl_bool  pretty_print,
  414: 					     int       level,
  415: 					     int       tabular);
  416: 
  417: int       axl_node_dump_at                  (axlNode * node,
  418: 					     char    * content,
  419: 					     int       desp,
  420: 					     axl_bool  pretty_print,
  421: 					     int       level,
  422: 					     int       tabular);
  423: 
  424: axl_bool    axl_node_has_invalid_chars        (const char * content,
  425: 					       int    content_size,
  426: 					       int  * added_size);
  427: 
  428: axl_bool    axl_node_has_invalid_chars_cdata    (const char * content,
  429: 						 int          content_size,
  430: 						 int        * added_size);
  431: 
  432: char      * axl_node_content_translate_defaults (char * content, 
  433: 						 int  * content_size);
  434: 
  435: char      * axl_node_content_copy_and_escape    (const char * content, 
  436: 						 int          content_size, 
  437: 						 int          additional_size);
  438: 
  439: char * axl_node_content_copy_and_escape_cdata (const char * content, 
  440: 					       int          content_size, 
  441: 					       int          additional_size);
  442: 
  443: void      axl_node_free            (axlNode * node);
  444: 
  445: void      axl_node_free_full       (axlNode * node, axl_bool also_childs);
  446: 
  447: /* @} */
  448: 
  449: /* item interface */
  450: 
  451: axlItem     * axl_item_new             (AxlItemType type,
  452: 					axlPointer  data);
  453: 
  454: axlItem     * axl_item_new_ref         (AxlItemType type,
  455: 					axlPointer  data);
  456: 
  457: axlDoc      * axl_item_get_doc         (axlItem * item);
  458: 
  459: void          axl_item_set_doc         (axlItem * item, axlDoc * doc);
  460: 
  461: axlNode     * axl_item_get_parent      (axlItem * item);
  462: 
  463: axlItem     * axl_item_get_next        (axlItem * item);
  464: 
  465: axlItem     * axl_item_node_next       (axlNode * node);
  466: 
  467: axlItem     * axl_item_get_previous    (axlItem * item);
  468: 
  469: axlItem     * axl_item_node_previous   (axlNode * node);
  470: 
  471: axlItem     * axl_item_node_holder     (axlNode * node);
  472: 
  473: axlItem     * axl_item_get_first_child (axlNode * node);
  474: 
  475: axlItem     * axl_item_get_last_child  (axlNode * node);
  476: 
  477: AxlItemType   axl_item_get_type        (axlItem * item);
  478: 
  479: axlPointer    axl_item_get_data        (axlItem * item);
  480: 
  481: char        * axl_item_get_content     (axlItem * item, 
  482: 					int * size);
  483: 
  484: void          axl_item_set_child       (axlNode * parent, 
  485: 					AxlItemType type, 
  486: 					axlPointer data);
  487: 
  488: void          axl_item_set_child_ref   (axlNode * parent, 
  489: 					axlItem * item);
  490: 
  491: void          axl_item_set_after       (axlItem * item,
  492: 					AxlItemType type,
  493: 					axlPointer data);
  494: 
  495: axlItem     * axl_item_copy            (axlItem * item,
  496: 					axlNode * set_parent);
  497: 
  498: void          axl_item_remove          (axlItem * item,
  499: 					axl_bool  dealloc);
  500: 
  501: void          axl_item_replace         (axlItem * item, 
  502: 					axlItem * new_item,
  503: 					axl_bool  dealloc);
  504: 
  505: void          axl_item_transfer_childs_after (axlNode * old_parent,
  506: 					      axlItem * item_ref);
  507: 
  508: axl_bool      axl_item_are_equal      (axlItem * item,
  509: 				       axlItem * item2,
  510: 				       axl_bool      trimmed);
  511: 
  512: axl_bool      axl_item_are_equal_full (axlItem    * item,
  513: 				       axlItem    * item2,
  514: 				       axl_bool     trimmed,
  515: 				       axlError  ** error);
  516: 
  517: void          axl_item_free           (axlItem * item,
  518: 				       axl_bool      dealloc);
  519: 
  520: axlFactory     * axl_item_factory_create (void);
  521: 
  522: axlItem        * axl_item_factory_get (axlFactory * factory);
  523: 
  524: axlFactory     * axl_node_factory_create (void);
  525: 
  526: axlNode        * axl_node_factory_get (axlFactory * factory);
  527: 
  528: axlFactory     * axl_item_content_factory_create (void);
  529: 
  530: axlFactory     * axl_item_attr_factory_create (void);
  531: 
  532: END_C_DECLS
  533: 
  534: #endif
  535: 
  536: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>