Back to index

php5  5.3.10
Classes | Defines | Typedefs | Enumerations | Functions
xml_element.h File Reference
#include <stdio.h>
#include "queue.h"
#include "simplestring.h"
#include "encodings.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _xml_output_options
struct  _xml_input_options
struct  _xml_elem_error
struct  _xml_element_attr
struct  _xml_element

Defines

#define xml_elem_next_element(el)   ((el) ? (xml_element *)Q_Next(&el->children) : NULL)
#define xml_elem_head_element(el)   ((el) ? (xml_element *)Q_Head(&el->children) : NULL)
#define xml_elem_next_attr(el)   ((el) ? (xml_element_attr *)Q_Next(&el->attrs) : NULL)
#define xml_elem_head_attr(el)   ((el) ? (xml_element_attr *)Q_Head(&el->attrs) : NULL)
#define xml_elem_get_name(el)   (char *)((el) ? el->name : NULL)
#define xml_elem_get_val(el)   (char *)((el) ? el->text.str : NULL)

Typedefs

typedef enum _xml_elem_verbosity XML_ELEM_VERBOSITY
typedef enum _xml_elem_escaping XML_ELEM_ESCAPING
typedef struct _xml_output_options STRUCT_XML_ELEM_OUTPUT_OPTIONS
typedef struct
_xml_output_options
XML_ELEM_OUTPUT_OPTIONS
typedef struct _xml_input_options STRUCT_XML_ELEM_INPUT_OPTIONS
typedef struct _xml_input_optionsXML_ELEM_INPUT_OPTIONS
typedef struct _xml_elem_error STRUCT_XML_ELEM_ERROR
typedef struct _xml_elem_errorXML_ELEM_ERROR
typedef struct _xml_element_attr xml_element_attr
typedef struct _xml_element xml_element

Enumerations

enum  _xml_elem_verbosity { xml_elem_no_white_space, xml_elem_newlines_only, xml_elem_pretty }
enum  _xml_elem_escaping {
  xml_elem_no_escaping = 0x000, xml_elem_markup_escaping = 0x002, xml_elem_non_ascii_escaping = 0x008, xml_elem_non_print_escaping = 0x010,
  xml_elem_cdata_escaping = 0x020
}

Functions

void xml_elem_free (xml_element *root)
void xml_elem_free_non_recurse (xml_element *root)
xml_elementxml_elem_new (void)
char * xml_elem_serialize_to_string (xml_element *el, XML_ELEM_OUTPUT_OPTIONS options, int *buf_len)
void xml_elem_serialize_to_stream (xml_element *el, FILE *output, XML_ELEM_OUTPUT_OPTIONS options)
xml_elementxml_elem_parse_buf (const char *in_buf, int len, XML_ELEM_INPUT_OPTIONS options, XML_ELEM_ERROR error)

Class Documentation

struct _xml_output_options

Definition at line 89 of file xml_element.h.

Class Members
const char * encoding
XML_ELEM_ESCAPING escaping
XML_ELEM_VERBOSITY verbosity
struct _xml_input_options

Definition at line 103 of file xml_element.h.

Class Members
ENCODING_ID encoding
struct _xml_elem_error

Definition at line 115 of file xml_element.h.

Class Members
long byte_index
long column
long line
int parser_code
const char * parser_error
struct _xml_element_attr

Definition at line 136 of file xml_element.h.

Class Members
char * key
char * val
struct _xml_element

Definition at line 149 of file xml_element.h.

Collaboration diagram for _xml_element:
Class Members
queue attrs
queue children
const char * name
struct _xml_element * parent
simplestring text

Define Documentation

#define xml_elem_get_name (   el)    (char *)((el) ? el->name : NULL)

Definition at line 189 of file xml_element.h.

#define xml_elem_get_val (   el)    (char *)((el) ? el->text.str : NULL)

Definition at line 190 of file xml_element.h.

#define xml_elem_head_attr (   el)    ((el) ? (xml_element_attr *)Q_Head(&el->attrs) : NULL)

Definition at line 188 of file xml_element.h.

#define xml_elem_head_element (   el)    ((el) ? (xml_element *)Q_Head(&el->children) : NULL)

Definition at line 186 of file xml_element.h.

#define xml_elem_next_attr (   el)    ((el) ? (xml_element_attr *)Q_Next(&el->attrs) : NULL)

Definition at line 187 of file xml_element.h.

#define xml_elem_next_element (   el)    ((el) ? (xml_element *)Q_Next(&el->children) : NULL)

Definition at line 185 of file xml_element.h.


Typedef Documentation

typedef struct _xml_elem_error * XML_ELEM_ERROR
typedef struct _xml_element xml_element

Enumeration Type Documentation

Enumerator:
xml_elem_no_escaping 
xml_elem_markup_escaping 
xml_elem_non_ascii_escaping 
xml_elem_non_print_escaping 
xml_elem_cdata_escaping 

Definition at line 72 of file xml_element.h.

                                {
   xml_elem_no_escaping             = 0x000,
   xml_elem_markup_escaping         = 0x002,   /* entity escape xml special chars         */
   xml_elem_non_ascii_escaping      = 0x008,   /* entity escape chars above 127           */
   xml_elem_non_print_escaping      = 0x010,   /* entity escape non print (illegal) chars */
   xml_elem_cdata_escaping          = 0x020,   /* wrap in cdata section                   */
} XML_ELEM_ESCAPING;
Enumerator:
xml_elem_no_white_space 
xml_elem_newlines_only 
xml_elem_pretty 

Definition at line 55 of file xml_element.h.

                                 {
   xml_elem_no_white_space,    /* compact xml with no white space            */
   xml_elem_newlines_only,     /* add newlines for enhanced readability      */
   xml_elem_pretty             /* add newlines and indent accordint to depth */
} XML_ELEM_VERBOSITY;

Function Documentation

void xml_elem_free ( xml_element root)

Definition at line 236 of file xml_element.c.

                                      {
   if(root) {
      xml_element* kids = Q_Head(&root->children);
      while(kids) {
         xml_elem_free(kids);
         kids = Q_Next(&root->children);
      }
      xml_elem_free_non_recurse(root);
   }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 197 of file xml_element.c.

                                                  {
   if(root) {
      xml_element_attr* attrs = Q_Head(&root->attrs);
      while(attrs) {
         my_free(attrs->key);
         my_free(attrs->val);
         my_free(attrs);
         attrs = Q_Next(&root->attrs);
      }

      Q_Destroy(&root->children);
      Q_Destroy(&root->attrs);
      if(root->name) {
          free((char *)root->name);
          root->name = NULL;
      }
      simplestring_free(&root->text);
      my_free(root);
   }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 265 of file xml_element.c.

                            {
   xml_element* elem = calloc(1, sizeof(xml_element));
   if(elem) {
      Q_Init(&elem->children);
      Q_Init(&elem->attrs);
      simplestring_init(&elem->text);

      /* init empty string in case we don't find any char data */
      simplestring_addn(&elem->text, "", 0);
   }
   return elem;
}

Here is the call graph for this function:

Here is the caller graph for this function:

xml_element* xml_elem_parse_buf ( const char *  in_buf,
int  len,
XML_ELEM_INPUT_OPTIONS  options,
XML_ELEM_ERROR  error 
)

Definition at line 687 of file xml_element.c.

{
   xml_element* xReturn = NULL;
   char buf[100] = "";
   static STRUCT_XML_ELEM_INPUT_OPTIONS default_opts = {encoding_utf_8};

   if(!options) {
      options = &default_opts;
   }

   if(in_buf) {
      XML_Parser parser;
      xml_elem_data mydata = {0};

      parser = XML_ParserCreate(NULL);

      mydata.root = xml_elem_new();
      mydata.current = mydata.root;
      mydata.input_options = options;
      mydata.needs_enc_conversion = options->encoding && strcmp(options->encoding, encoding_utf_8);

      XML_SetElementHandler(parser, (XML_StartElementHandler)_xmlrpc_startElement, (XML_EndElementHandler)_xmlrpc_endElement);
      XML_SetCharacterDataHandler(parser, (XML_CharacterDataHandler)_xmlrpc_charHandler);

      /* pass the xml_elem_data struct along */
      XML_SetUserData(parser, (void*)&mydata);

      if(!len) {
         len = strlen(in_buf);
      }

      /* parse the XML */
      if(XML_Parse(parser, in_buf, len, 1) == 0) {
         enum XML_Error err_code = XML_GetErrorCode(parser);
         int line_num = XML_GetCurrentLineNumber(parser);
         int col_num = XML_GetCurrentColumnNumber(parser);
         long byte_idx = XML_GetCurrentByteIndex(parser);
/*         int byte_total = XML_GetCurrentByteCount(parser); */
         const char * error_str = XML_ErrorString(err_code);
         if(byte_idx >= 0) {
             snprintf(buf, 
                      sizeof(buf),
                      "\n\tdata beginning %ld before byte index: %s\n",
                      byte_idx > 10  ? 10 : byte_idx,
                      in_buf + (byte_idx > 10 ? byte_idx - 10 : byte_idx));
         }
/*
         fprintf(stderr, "expat reports error code %i\n"
                "\tdescription: %s\n"
                "\tline: %i\n"
                "\tcolumn: %i\n"
                "\tbyte index: %ld\n"
                "\ttotal bytes: %i\n%s ",
                err_code, error_str, line_num, 
                col_num, byte_idx, byte_total, buf);
*/

          /* error condition */
          if(error) {
              error->parser_code = (long)err_code;
              error->line = line_num;
              error->column = col_num;
              error->byte_index = byte_idx;
              error->parser_error = error_str;
          }
      }
      else {
         xReturn = (xml_element*)Q_Head(&mydata.root->children);
         xReturn->parent = NULL;
      }

      XML_ParserFree(parser);


      xml_elem_free_non_recurse(mydata.root);
   }

   return xReturn;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void xml_elem_serialize_to_stream ( xml_element el,
FILE *  output,
XML_ELEM_OUTPUT_OPTIONS  options 
)

Definition at line 571 of file xml_element.c.

{
   xml_element_serialize(el, file_out_fptr, (void *)output, options, 0);
}

Here is the call graph for this function:

char* xml_elem_serialize_to_string ( xml_element el,
XML_ELEM_OUTPUT_OPTIONS  options,
int buf_len 
)

Definition at line 537 of file xml_element.c.

{
   simplestring buf;
   simplestring_init(&buf);

   xml_element_serialize(el, simplestring_out_fptr, (void *)&buf, options, 0);

   if(buf_len) {
      *buf_len = buf.len;
   }

   return buf.str;
}

Here is the call graph for this function:

Here is the caller graph for this function: