[xml] question again! --- nobody can help me?[questions about the SAX interface of libxml2]



Hi everyone,
   I am a new user of libxml library. Perfect as it really is, I think this library is very good. 
However,It's not a simple thing to make clear how to ues this library. Now, there are some basic questions 
about the SAX interface:
  Q1. I have an xml file named 'a.xml'. In order to parse this file with the sax interface, what I know is 
the following:
         a. defining my callback functions (such as startDocument, startElement,etc.)
         b. accounting a new variant of  'xmlSaxHandler' structure, and then set the my own callbace function 
into it
         c. calling ' xmlSAXUserParseFile' function  with the sax handler and 'a.xml' file
         Basically, are the above steps right?
   
 Q2.If errors eccur during parsing file, how can I locate the error position?
        If some errors occur in 'a.xml', the libxml sax parser will call the callback function 'error',which 
I have set into the 'sax handler',  to notify that error. How can I know the error position of the source 
document? I think I should user the document locator. 
        I can get the document locator pointer in callback functiong 'setDocumentLocator', However, the 
member functions 'int (*getLineNumber)(void *ctx)' and ' int (*getColumnNumber)(void *ctx)' of  the document 
loctator  strcuture need the 'xmlParserCtxt' pointer when being called. Therefore, How can I get the current 
xmlParserCtxt when parsing xml file?

 Q3. How can I deal with the entity?
        I get the 'a.xml' file with following content:
       a.xml
      --------------
      <?xml version="1.0" encoding="SHIFT_JIS"?>
      <!DOCTYPE  sax2A:root[
      <!ELEMENT  sax2A:root (sax2A:document)>
      <!ELEMENT  sax2A:document (#PCDATA)>
      <!ATTLIST    sax2A:root xmlns:sax2A CDATA #IMPLIED>
      <!ATTLIST    sax2A:document sax2A:attr1 CDATA #IMPLIED
                             sax2A:attr2 CDATA #IMPLIED>
      <!ENTITY sax "ddd">
       ]>

       <sax2A:root xmlns:sax2A=  "http://www.w3.org/XML/1998/namespace";>
             <sax2A:document sax2A:attr1="0" sax2A:attr2="&sax;">AAAAAAAA</sax2A:document>
      </sax2A:root>
       
       My own callback functions just are programmed to print the current  event. e.g. in startDocument, it 
only prints 'document  start' string.[The complete code is in the attachment of this mail. ]

     Then I get following output:
      ---------------------------
       [ala xml_server ala]$ ./sax_test a.xml 
        Parse file Name: a.xml
        Locator start 
        Document start 
        elementDecl
        elementDecl
        attrbuteDecl
        attrbuteDecl
        attrbuteDecl
        entityDecl
        name sax  content ddd
        entityDecl
        name sax  content ddd
        Element start 
        Error :  Entity 'sax' not defined
        Document End 

        
      a. According to the above output, why does the entity declaration event occur twice? As the xml source 
document shows,I only define one entity once: <!ENTITY sax "ddd">!
      b. I already define the entity 'sax' in the internal DTD declaration at the start of  'a.xml', but, why 
does error still occur when using the entity [sax2A:attr2="&sax;"] ?


 All of above are my questions, I hunger for the feedback!
 Thanks for all of you!

Jeffery Xu
Jun 2nd, 2003

P.S.
The attachment is my own SAX-parsing code.

Attachment: sax_test.c
Description: Binary data



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]