RE: [xml] Trying to use SAX



Daniel:
        Thanks for replying. I am just starting to learn about XML parsing
so I may have some misunderstanding about some of the things I have read.
See comments and possible questions below between @@@@@@@@@@.


-----Original Message-----
From: Daniel Veillard [mailto:veillard redhat com] 
Sent: Tuesday, January 10, 2006 5:34 AM
To: Allen, Jack
Cc: 'xml gnome org'
Subject: Re: [xml] Trying to use SAX


On Mon, Jan 09, 2006 at 08:53:20PM -0500, Allen, Jack wrote:
Hello: 
        I am trying to use the SAX API.

  try to avoid it ! Use the xmlReader if you have a choice.
@@@@@@@@@@
I choose the SAX API because from what I read it would use less memory over
all and possibly be a little faster for my needs. The other APIs seem to
have to read the complete XML data and build a tree, then you have to search
the tree for the keywords you want to use. Where as the SAX API allowed
building the information from the keywords as the XML data is being
processed.
@@@@@@@@@@

I have setup the xmlSAXHandler
to callback my functions. The startDocument one works fine. But before
it calls my startElement function it takes a memory access error.
Running my program with gdb the backtrace looks like:

  is that a sax V2 handler ? 
@@@@@@@@@@
No it was not and that was the problem. I had to look in the parser.h file
to see that the xmlSAXHandler had more elements in it for SAX 2. The example
I was using as a guide must have been for SAX 1. After changing my functions
and assigning them to the correct element in xmlSAXHandler things are
working as I thought they should.
@@@@@@@@@@

Starting program: /home/jca/xml/event event.xml 

  Works fine here:

paphio:~/XML -> cat tst.xml
<?xml version="1.0"?>
<event>
        <number>1</number>
        <date>01-01-2006</date>
        <time>18:01:02</time>
        <action>menu selection</action>
</event>

paphio:~/XML -> ./testSAX --sax2 tst.xml
SAX.setDocumentLocator()
SAX.startDocument()
SAX.startElementNs(event, NULL, NULL, 0, 0, 0)
SAX.characters(
        , 9)
SAX.startElementNs(number, NULL, NULL, 0, 0, 0)
SAX.characters(1, 1)
SAX.endElementNs(number, NULL, NULL)
SAX.characters(
        , 9)
SAX.startElementNs(date, NULL, NULL, 0, 0, 0)
SAX.characters(01-01-2006, 10)
SAX.endElementNs(date, NULL, NULL)
SAX.characters(
        , 9)
SAX.startElementNs(time, NULL, NULL, 0, 0, 0)
SAX.characters(18:01:02, 8)
SAX.endElementNs(time, NULL, NULL)
SAX.characters(
        , 9)
SAX.startElementNs(action, NULL, NULL, 0, 0, 0)
SAX.characters(menu selection, 14)
SAX.endElementNs(action, NULL, NULL)
SAX.characters(
, 1)
SAX.endElementNs(event, NULL, NULL)
SAX.endDocument()

  Probably an error building the SAX handler or in the callbacks. Use the
xmlReader or the existing testSAX.c code as a guidance. Remember we can't 
debug your code.
@@@@@@@@@@
Where can I find the testSAX.c code on the web? Like I said I am using what
came with RedHat AS 4. So I am sure it is not the latest version of libxml2.
@@@@@@@@@@

Daniel

-- 
Daniel Veillard      | Red Hat http://redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml




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