Logo Search packages:      
Sourcecode: rapple version File versions  Download package

rpl_str_t rpl_parse ( rpl_str_t  xml_doc_in  ) 

Performs normalization parsing.

Parameters:
xml_doc 
Returns:
Parsed doc with entity keys replaced with entity literals.

Definition at line 595 of file parser.c.

References characters(), end(), rpl_log_error(), rpl_log_fatal(), rpl_me_free(), rpl_me_malloc(), rpl_message_get(), rpl_parse_escape_amperands(), rpl_parse_literal_ampersand(), rpl_str_concat(), and start().

Referenced by rpl_mod_parse_process().

                                {

    XML_Parser parser;
      rpl_str_t line_no, msg, xml_doc;

      assert(xml_doc_in != NULL);

      xml_doc = strdup((rpl_c_str_t)xml_doc_in);

    if((parser = XML_ParserCreate(NULL)) == NULL)
        rpl_log_fatal(rpl_message_get("OUT_OF_MEMORY", "normalizing XML parser", RPL_EOM));

    XML_SetElementHandler(parser, start, end);
    XML_SetCharacterDataHandler(parser, characters);

    p_doc = (rpl_str_t)rpl_me_malloc(2 * strlen(xml_doc) + 1);

      /* entity complicate the parsing somewhat since expat automatically resolves
         predefined entities (& < etc.) and sometimes these need to be 
         interpreted literally (e.g., when wishing to display an ampersand in a
         document.  The easiest solution is to "escape" all ampersands prior to
         parsing, let expat resolve what it finds and then quote the leftover
         ampersands (this passes the document faithfully onto the next parsing phase) */
      rpl_parse_escape_amperands(&xml_doc);
    if (XML_Parse(parser, xml_doc, strlen(xml_doc), 1) == XML_STATUS_ERROR)
      {
            line_no = (rpl_str_t)rpl_me_malloc(12);
            sprintf(line_no, "(line %d)", XML_GetCurrentLineNumber(parser));
            msg = rpl_str_concat("XML Parse Error: ", XML_ErrorString(XML_GetErrorCode(parser)), 
                                                      " ", line_no, RPL_STR_EOC);
            rpl_log_error(msg);
            rpl_me_free(line_no);
            rpl_me_free(msg);
            return RPL_STR_NUL;
      }

      /* rpl_parse_resolve_entities(&p_doc); */
      rpl_parse_literal_ampersand(&p_doc);
      return p_doc;
}


Generated by  Doxygen 1.6.0   Back to index