xmlStopParser              package:XML              R Documentation

_T_e_r_m_i_n_a_t_e _a_n _X_M_L _p_a_r_s_e_r

_D_e_s_c_r_i_p_t_i_o_n:

     This function allows an R-level function to terminate an XML
     parser before it completes the processing of the XML content. This
     might be useful, for example, in event-driven parsing with
     'xmlEventParse'  when we want  to read through an XML file until
     we find a record of interest. Then, having retrieved the necessary
     information, we want to  terminate the parsing rather than let it
     pointlessly continue. Instead of raising an error in our handler
     function, we can call 'xmlStopParser' and return. The parser will
     then take control again and terminate and return back to the
     original R function from which it was invoked. 

     The only argument to this function is a reference to internal
     C-level  which identifies the parser.   This is passed by the
     R-XML parser mechanism to a function invoked by the parser if that
     function inherits (in the S3 sense) from the class
     'XMLParserContextFunction'.

_U_s_a_g_e:

     xmlStopParser(parser)

_A_r_g_u_m_e_n_t_s:

  parser: an object of class 'XMLParserContext' which must have been
          obtained by via an 'XMLParserContextFunction' function called
          by the parser. This is just a handler function whose class
          includes 'XMLParserContextFunction' 

_V_a_l_u_e:

     'TRUE' if it succeeded and an error is raised  if the 'parser'
     object  is not valid.

_A_u_t_h_o_r(_s):

     Duncan Temple Lang

_R_e_f_e_r_e_n_c_e_s:

     libxml2 <URL: http://xmlsoft.org>

_S_e_e _A_l_s_o:

     'xmlEventParse'

_E_x_a_m_p_l_e_s:

       ############################################
       # Stopping the parser mid-way and an example of using XMLParserContextFunction.

       startElement =
       function(ctxt, name, attrs, ...)  {
         print(ctxt)
           print(name)
           if(name == "rewriteURI") {
                cat("Terminating parser\n")
                xmlStopParser(ctxt)
           }
       }
       class(startElement) = "XMLParserContextFunction"  
       endElement =
       function(name, ...) 
         cat("ending", name, "\n")

       fileName = system.file("exampleData", "catalog.xml", package = "XML")
       xmlEventParse(fileName, handlers = list(startElement = startElement, endElement = endElement))

