You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by appleGuy <al...@gmail.com> on 2006/12/17 16:31:50 UTC

Parsing Using SAX

Hi,

Ive finally started to get going using Sax. Now im using the Samples to help
coding my own project.

Looking at Sax Count, they seem to have created their own handler class
(saxcounthandler):

SAXCountHandlers handler;
    parser->setDocumentHandler(&handler);
    parser->setErrorHandler(&handler);

How can they do this as The type needed in setDocumentHandler needs to be
type DocumentHandler.

When I try to use my custom class as a handler, it gives an error...what is
special about the SaxCountHandlers..?

Ive used pointers,. they have dereferenced an object, surely im doing the
same thing?

Many Thanks
Alex

p.s: Also by DocumentHandler, what does this do exactly. Im thinking its the
controller for the parsing. I.e you can use the parsed data to modify the
handler and visa-versa




-- 
View this message in context: http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7916807
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by appleGuy <al...@gmail.com>.
Ok, imgoing to use  a map.

Also I changed the catch statement, but there is still an error.

Using the debugger it seems to break when i call parser->parse(XMLfile)

Any ideas?

-Alex


Alberto Massari wrote:
> 
> At 06.37 18/12/2006 -0800, appleGuy wrote:
> 
>>Ok, cool
>>
>>Couldnt I use an STL Map to map the strings to Enums?
> 
> Provided that you use std::wstring, yes
> 
> 
>>Also currently my code compiles fine but i get a runtime error when
>>executed. Its having problems with the parser->parse(XMLfile) bit. Is it
>>because my handler class isnt completed or is there other problems.
> 
> If you get a runtime error, it's probably because you have written
> 
> catch(int debug /*Use Exception in class*/){
>          cout << "ERROR OCCURED" << endl;
> }
> 
> Try catching XMLException&. If it doesn't work, try running your code 
> inside a debugger.
> 
> Alberto
> 
> 
> 
>>Thanks
>>Alex
>>
>>
>>
>>Alberto Massari wrote:
>> >
>> > At 06.11 18/12/2006 -0800, appleGuy wrote:
>> >
>> >>Ok, ive found it in my library.
>> >>
>> >>Could you please do me a massive favour & show a step by step of your
>> >>process. To be honest im not totally understanding your logic to
>> achieve
>>my
>> >>goal. Also because its not documented its harder to impliment.
>> >
>> > Disclaimer: it's a totally untested code...
>> >
>> > #include <xercesc/util/StringPool.hpp>
>> >
>> > class myHandler : public DocumentHandler
>> > {
>> > [...]
>> >      virtual void startDocument();
>> >      virtual void startElement
>> >      (
>> >          const   XMLCh* const    name
>> >          ,       AttributeList&  attrs
>> >      );
>> >
>> > protected:
>> >    XMLStringPool _map;
>> > };
>> >
>> > void myHandler::startDocument()
>> > {
>> >    _map.flushAll();
>> >    _map.addOrFind(L"loopcardprj");       // id = 1
>> >    _map.addOrFind(L"_prjsetup"); // id = 2
>> >    _map.addOrFind(L"title");     // id = 3
>> >    _map.addOrFind(L"author");    // id = 4
>> >    _map.addOrFind(L"subject");   // id = 5
>> >    _map.addOrFind(L"card");      // id = 6
>> >    _map.addOrFind(L"_questions");        // id = 7
>> >    _map.addOrFind(L"question");  // id = 8
>> >    _map.addOrFind(L"q"); // id = 9
>> >    _map.addOrFind(L"a"); // id = 10
>> >    _map.addOrFind(L"comment");   // id = 11
>> > }
>> >
>> > void myHandler::startElement(const XMLCh* const name, AttributeList&
>> > attrs)
>> > {
>> >    switch(_map.getId(name))
>> >    {
>> >      // place the code in the corresponding 'case' branch...
>> >      case 1:
>> >      case 2:
>> >      case 3:
>> >      case 4:
>> >      case 5:
>> >      case 6:
>> >      case 7:
>> >      case 8:
>> >      case 9:
>> >      case 10:
>> >      case 11:
>> >    }
>> > }
>> >
>> > Alberto
>> >
>> >
>> >>Many Thanks Alberto
>> >>
>> >>-Alex
>> >>
>> >>
>> >>Alberto Massari wrote:
>> >> >
>> >> > At 04.41 18/12/2006 -0800, appleGuy wrote:
>> >> >
>> >> >>Ok,
>> >> >>
>> >> >>I cant seem to see XMLStringPool in the docs, there is a
>> >> >>XMLSyncronisedStringPool...
>> >> >
>> >> > I guess it was treated as an internal helper class, as it is
>> >> > explicitly removed from the doc generation step (while
>> >> > XMLSyncronisedStringPool is a more recent class that escaped the
>> >> > check...). You can use XMLSyncronisedStringPool (that derives from
>> >> > XMLStringPool), or just include xercesc/util/StringPool.hpp and use
>> >> > XMLStringPool...
>> >> >
>> >> > Alberto
>> >> >
>> >> >>???
>> >> >>
>> >> >>-Alex
>> >> >>
>> >> >>
>> >> >>Alberto Massari wrote:
>> >> >> >
>> >> >> > At 15.05 17/12/2006 -0800, appleGuy wrote:
>> >> >> >
>> >> >> >>Hi,
>> >> >> >>
>> >> >> >>Ive been getting there with this Sax buisness...
>> >> >> >>
>> >> >> >>Now my handler class is on the way (the problem I had earlier is
>> >> >> sorted)
>> >> >> >>
>> >> >> >>However How do I make comparisons efficently using SAX...I mean
>> when
>> >> it
>> >> >>get
>> >> >> >>the tag, i need to compare it & find the right variable to assign
>> >> the
>> >> >> >>character data too (the data between the tags)
>> >> >> >
>> >> >> > I would add to my handler class an instance of type
>> XMLStringPool,
>> >> >> > initialize it by adding to it the names I am interested in (using
>> >> >> > addOrFind), then use getId to convert the node name into one of
>> >> these
>> >> >> > known ids.
>> >> >> >
>> >> >> > Alberto
>> >> >> >
>> >> >> >
>> >> >> >>Cheers
>> >> >> >>Alex
>> >> >> >>
>> >> >> >>
>> >> >> >>appleGuy wrote:
>> >> >> >> >
>> >> >> >> > Ok,
>> >> >> >> >
>> >> >> >> > Im going to include my code for this problem.
>> >> >> >> > I get an error when the parse function is called:
>> >> >> >> > parser->parse(XMLfile)....Ive got no idea why
>> >> >> >> >
>> >> >> >> > Also this was formed from the SaxCount Code included with the
>> >> Xerces
>> >> >> >> > distro.
>> >> >> >> >
>> >> >> >> > Currently I dont see it doing anything. I need to be able to
>> >> change
>> >> >> >> > variable & containers in the DocumentHandler Class
>> >> >> >> >
>> >> >> >> > Cheers
>> >> >> >> > Alex
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > bool prjLoad::loadXML_prj(char *prj_filename){
>> >> >> >> >       //Start XML Xerces Framework
>> >> >> >> >       try {
>> >> >> >> >             XMLPlatformUtils::Initialize();
>> >> >> >> >         }
>> >> >> >> >         catch (const XMLException& toCatch) {
>> >> >> >> >             char* message =
>> >> >> XMLString::transcode(toCatch.getMessage());
>> >> >> >> >             cout << "Error during initialization! :\n"
>> >> >> >> >                  << message << "\n";
>> >> >> >> >             XMLString::release(&message);
>> >> >> >> >                       return false;
>> >> >> >> >         }
>> >> >> >> >
>> >> >> >> >               //Create New Parser (SAX)
>> >> >> >> >         SAXParser* parser = new SAXParser();
>> >> >> >> >
>> >> >> >> >               //File Input Validation
>> >> >> >> >         parser->setDoValidation(true);
>> >> >> >> >         parser->setDoNamespaces(true);
>> >> >> >> >
>> >> >> >> >               //Create our SAX handler object and install it
>> on
>> >> >> >> the parser (Doc &
>> >> >> >> > Error Handler)
>> >> >> >> >               //Using Project as Handler
>> >> >> >> >               parser->setDocumentHandler(prj);
>> >> >> >> >               parser->setErrorHandler(prj);
>> >> >> >> >
>> >> >> >> >               //Load File through Xerces
>> >> >> >> >               XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>> >> >> >> >         xmlFileHandle.open(prj_filename);
>> >> >> >> >
>> >> >> >> >               //Load Each Line From File To Array xmlFile
>> >> >> >> >               bool flag = true;
>> >> >> >> >               while (flag == true)
>> >> >> >> >     {
>> >> >> >> >         char token[1000];
>> >> >> >> >         //Set array to zeros
>> >> >> >> >         memset(token,0,sizeof(token));
>> >> >> >> >
>> >> >> >> >               //Sequential Search
>> >> >> >> >               if(!(xmlFileHandle.eof())){
>> >> >> >> >                       xmlFileHandle.getline(token,
>> >> sizeof(token));
>> >> >> >> >
>> >> >> >> >                       //Check If Line Contains Anything
>> >> >> >> >                       if(!(token))
>> >> >> >> >                               continue;
>> >> >> >> >                       else {
>> >> >> >> >                               //Load into New Derived Variable
>> >> >> >> for overloading & Safety
>> >> >> >> >                               const char *XMLfile = token;
>> >> >> >> >
>> >> >> >> >                               //Debug
>> >> >> >> >                               cout << "Parsing: " << XMLfile
>> <<
>> >> >> endl;
>> >> >> >> >
>> >> >> >> >                               //ERROR WIPE -> NEEDS
>> IMPLIMENTING
>> >> >> >> >
>> >> >> >> >                               try {
>> >> >> >> >                                       parser->parse(XMLfile);
>> >> >> >> >                               }
>> >> >> >> >                               catch(int debug /*Use Exception
>> in
>> >> >> >> class*/){
>> >> >> >> >                                       cout << "ERROR OCCURED"
>> <<
>> >> >> endl;
>> >> >> >> >                               }
>> >> >> >> >
>> >> >> >> >                       }
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >               }
>> >> >> >> >               //ELSE STATEMENT FOR EOF-> Set Flag to false
>> >> >> >> therefore exiting while
>> >> >> >> > loop
>> >> >> >> >               else
>> >> >> >> >                       flag = false;
>> >> >> >> >
>> >> >> >> >
>> >> >> >> >       }
>> >> >> >> >
>> >> >> >> >               return true;
>> >> >> >> > }
>> >> >> >> >
>> >> >> >> >
>> >> >> >> > appleGuy wrote:
>> >> >> >> >>
>> >> >> >> >> Its Ok,
>> >> >> >> >>
>> >> >> >> >> I needed to inheirt from the handlerbase class
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >> Cheers
>> >> >> >> >> ALEX
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >> appleGuy wrote:
>> >> >> >> >>>
>> >> >> >> >>> Hi,
>> >> >> >> >>>
>> >> >> >> >>> Ive finally started to get going using Sax. Now im using the
>> >> >> Samples
>> >> >> >> to
>> >> >> >> >>> help coding my own project.
>> >> >> >> >>>
>> >> >> >> >>> Looking at Sax Count, they seem to have created their own
>> >> handler
>> >> >> >> class
>> >> >> >> >>> (saxcounthandler):
>> >> >> >> >>>
>> >> >> >> >>> SAXCountHandlers handler;
>> >> >> >> >>>     parser->setDocumentHandler(&handler);
>> >> >> >> >>>     parser->setErrorHandler(&handler);
>> >> >> >> >>>
>> >> >> >> >>> How can they do this as The type needed in
>> setDocumentHandler
>> >> >> needs
>> >> >> >> to
>> >> >> >> >>> be type DocumentHandler.
>> >> >> >> >>>
>> >> >> >> >>> When I try to use my custom class as a handler, it gives an
>> >> >> >> error...what
>> >> >> >> >>> is special about the SaxCountHandlers..?
>> >> >> >> >>>
>> >> >> >> >>> Ive used pointers,. they have dereferenced an object, surely
>> im
>> >> >> doing
>> >> >> >> >>> the same thing?
>> >> >> >> >>>
>> >> >> >> >>> Many Thanks
>> >> >> >> >>> Alex
>> >> >> >> >>>
>> >> >> >> >>> p.s: Also by DocumentHandler, what does this do exactly. Im
>> >> >> thinking
>> >> >> >> its
>> >> >> >> >>> the controller for the parsing. I.e you can use the parsed
>> data
>> >> to
>> >> >> >> >>> modify the handler and visa-versa
>> >> >> >> >>>
>> >> >> >> >>>
>> >> >> >> >>>
>> >> >> >> >>>
>> >> >> >> >>>
>> >> >> >> >>
>> >> >> >> >>
>> >> >> >> >
>> >> >> >> >
>> >> >> >>
>> >> >> >>--
>> >> >> >>View this message in context:
>> >> >> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7921219
>> >> >> >>Sent from the Xerces - C - Users mailing list archive at
>> Nabble.com.
>> >> >> >
>> >> >> >
>> >> >> >
>> >> >>
>> >> >>--
>> >> >>View this message in context:
>> >> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7928122
>> >> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> >> >
>> >> >
>> >> >
>> >>
>> >>--
>> >>View this message in context:
>> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7929328
>> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> >
>> >
>> >
>>
>>--
>>View this message in context: 
>>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7929765
>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7931976
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by Alberto Massari <am...@datadirect.com>.
At 06.37 18/12/2006 -0800, appleGuy wrote:

>Ok, cool
>
>Couldnt I use an STL Map to map the strings to Enums?

Provided that you use std::wstring, yes


>Also currently my code compiles fine but i get a runtime error when
>executed. Its having problems with the parser->parse(XMLfile) bit. Is it
>because my handler class isnt completed or is there other problems.

If you get a runtime error, it's probably because you have written

catch(int debug /*Use Exception in class*/){
         cout << "ERROR OCCURED" << endl;
}

Try catching XMLException&. If it doesn't work, try running your code 
inside a debugger.

Alberto



>Thanks
>Alex
>
>
>
>Alberto Massari wrote:
> >
> > At 06.11 18/12/2006 -0800, appleGuy wrote:
> >
> >>Ok, ive found it in my library.
> >>
> >>Could you please do me a massive favour & show a step by step of your
> >>process. To be honest im not totally understanding your logic to achieve
>my
> >>goal. Also because its not documented its harder to impliment.
> >
> > Disclaimer: it's a totally untested code...
> >
> > #include <xercesc/util/StringPool.hpp>
> >
> > class myHandler : public DocumentHandler
> > {
> > [...]
> >      virtual void startDocument();
> >      virtual void startElement
> >      (
> >          const   XMLCh* const    name
> >          ,       AttributeList&  attrs
> >      );
> >
> > protected:
> >    XMLStringPool _map;
> > };
> >
> > void myHandler::startDocument()
> > {
> >    _map.flushAll();
> >    _map.addOrFind(L"loopcardprj");       // id = 1
> >    _map.addOrFind(L"_prjsetup"); // id = 2
> >    _map.addOrFind(L"title");     // id = 3
> >    _map.addOrFind(L"author");    // id = 4
> >    _map.addOrFind(L"subject");   // id = 5
> >    _map.addOrFind(L"card");      // id = 6
> >    _map.addOrFind(L"_questions");        // id = 7
> >    _map.addOrFind(L"question");  // id = 8
> >    _map.addOrFind(L"q"); // id = 9
> >    _map.addOrFind(L"a"); // id = 10
> >    _map.addOrFind(L"comment");   // id = 11
> > }
> >
> > void myHandler::startElement(const XMLCh* const name, AttributeList&
> > attrs)
> > {
> >    switch(_map.getId(name))
> >    {
> >      // place the code in the corresponding 'case' branch...
> >      case 1:
> >      case 2:
> >      case 3:
> >      case 4:
> >      case 5:
> >      case 6:
> >      case 7:
> >      case 8:
> >      case 9:
> >      case 10:
> >      case 11:
> >    }
> > }
> >
> > Alberto
> >
> >
> >>Many Thanks Alberto
> >>
> >>-Alex
> >>
> >>
> >>Alberto Massari wrote:
> >> >
> >> > At 04.41 18/12/2006 -0800, appleGuy wrote:
> >> >
> >> >>Ok,
> >> >>
> >> >>I cant seem to see XMLStringPool in the docs, there is a
> >> >>XMLSyncronisedStringPool...
> >> >
> >> > I guess it was treated as an internal helper class, as it is
> >> > explicitly removed from the doc generation step (while
> >> > XMLSyncronisedStringPool is a more recent class that escaped the
> >> > check...). You can use XMLSyncronisedStringPool (that derives from
> >> > XMLStringPool), or just include xercesc/util/StringPool.hpp and use
> >> > XMLStringPool...
> >> >
> >> > Alberto
> >> >
> >> >>???
> >> >>
> >> >>-Alex
> >> >>
> >> >>
> >> >>Alberto Massari wrote:
> >> >> >
> >> >> > At 15.05 17/12/2006 -0800, appleGuy wrote:
> >> >> >
> >> >> >>Hi,
> >> >> >>
> >> >> >>Ive been getting there with this Sax buisness...
> >> >> >>
> >> >> >>Now my handler class is on the way (the problem I had earlier is
> >> >> sorted)
> >> >> >>
> >> >> >>However How do I make comparisons efficently using SAX...I mean when
> >> it
> >> >>get
> >> >> >>the tag, i need to compare it & find the right variable to assign
> >> the
> >> >> >>character data too (the data between the tags)
> >> >> >
> >> >> > I would add to my handler class an instance of type XMLStringPool,
> >> >> > initialize it by adding to it the names I am interested in (using
> >> >> > addOrFind), then use getId to convert the node name into one of
> >> these
> >> >> > known ids.
> >> >> >
> >> >> > Alberto
> >> >> >
> >> >> >
> >> >> >>Cheers
> >> >> >>Alex
> >> >> >>
> >> >> >>
> >> >> >>appleGuy wrote:
> >> >> >> >
> >> >> >> > Ok,
> >> >> >> >
> >> >> >> > Im going to include my code for this problem.
> >> >> >> > I get an error when the parse function is called:
> >> >> >> > parser->parse(XMLfile)....Ive got no idea why
> >> >> >> >
> >> >> >> > Also this was formed from the SaxCount Code included with the
> >> Xerces
> >> >> >> > distro.
> >> >> >> >
> >> >> >> > Currently I dont see it doing anything. I need to be able to
> >> change
> >> >> >> > variable & containers in the DocumentHandler Class
> >> >> >> >
> >> >> >> > Cheers
> >> >> >> > Alex
> >> >> >> >
> >> >> >> >
> >> >> >> > bool prjLoad::loadXML_prj(char *prj_filename){
> >> >> >> >       //Start XML Xerces Framework
> >> >> >> >       try {
> >> >> >> >             XMLPlatformUtils::Initialize();
> >> >> >> >         }
> >> >> >> >         catch (const XMLException& toCatch) {
> >> >> >> >             char* message =
> >> >> XMLString::transcode(toCatch.getMessage());
> >> >> >> >             cout << "Error during initialization! :\n"
> >> >> >> >                  << message << "\n";
> >> >> >> >             XMLString::release(&message);
> >> >> >> >                       return false;
> >> >> >> >         }
> >> >> >> >
> >> >> >> >               //Create New Parser (SAX)
> >> >> >> >         SAXParser* parser = new SAXParser();
> >> >> >> >
> >> >> >> >               //File Input Validation
> >> >> >> >         parser->setDoValidation(true);
> >> >> >> >         parser->setDoNamespaces(true);
> >> >> >> >
> >> >> >> >               //Create our SAX handler object and install it on
> >> >> >> the parser (Doc &
> >> >> >> > Error Handler)
> >> >> >> >               //Using Project as Handler
> >> >> >> >               parser->setDocumentHandler(prj);
> >> >> >> >               parser->setErrorHandler(prj);
> >> >> >> >
> >> >> >> >               //Load File through Xerces
> >> >> >> >               XERCES_STD_QUALIFIER ifstream xmlFileHandle;
> >> >> >> >         xmlFileHandle.open(prj_filename);
> >> >> >> >
> >> >> >> >               //Load Each Line From File To Array xmlFile
> >> >> >> >               bool flag = true;
> >> >> >> >               while (flag == true)
> >> >> >> >     {
> >> >> >> >         char token[1000];
> >> >> >> >         //Set array to zeros
> >> >> >> >         memset(token,0,sizeof(token));
> >> >> >> >
> >> >> >> >               //Sequential Search
> >> >> >> >               if(!(xmlFileHandle.eof())){
> >> >> >> >                       xmlFileHandle.getline(token,
> >> sizeof(token));
> >> >> >> >
> >> >> >> >                       //Check If Line Contains Anything
> >> >> >> >                       if(!(token))
> >> >> >> >                               continue;
> >> >> >> >                       else {
> >> >> >> >                               //Load into New Derived Variable
> >> >> >> for overloading & Safety
> >> >> >> >                               const char *XMLfile = token;
> >> >> >> >
> >> >> >> >                               //Debug
> >> >> >> >                               cout << "Parsing: " << XMLfile <<
> >> >> endl;
> >> >> >> >
> >> >> >> >                               //ERROR WIPE -> NEEDS IMPLIMENTING
> >> >> >> >
> >> >> >> >                               try {
> >> >> >> >                                       parser->parse(XMLfile);
> >> >> >> >                               }
> >> >> >> >                               catch(int debug /*Use Exception in
> >> >> >> class*/){
> >> >> >> >                                       cout << "ERROR OCCURED" <<
> >> >> endl;
> >> >> >> >                               }
> >> >> >> >
> >> >> >> >                       }
> >> >> >> >
> >> >> >> >
> >> >> >> >               }
> >> >> >> >               //ELSE STATEMENT FOR EOF-> Set Flag to false
> >> >> >> therefore exiting while
> >> >> >> > loop
> >> >> >> >               else
> >> >> >> >                       flag = false;
> >> >> >> >
> >> >> >> >
> >> >> >> >       }
> >> >> >> >
> >> >> >> >               return true;
> >> >> >> > }
> >> >> >> >
> >> >> >> >
> >> >> >> > appleGuy wrote:
> >> >> >> >>
> >> >> >> >> Its Ok,
> >> >> >> >>
> >> >> >> >> I needed to inheirt from the handlerbase class
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> Cheers
> >> >> >> >> ALEX
> >> >> >> >>
> >> >> >> >>
> >> >> >> >>
> >> >> >> >> appleGuy wrote:
> >> >> >> >>>
> >> >> >> >>> Hi,
> >> >> >> >>>
> >> >> >> >>> Ive finally started to get going using Sax. Now im using the
> >> >> Samples
> >> >> >> to
> >> >> >> >>> help coding my own project.
> >> >> >> >>>
> >> >> >> >>> Looking at Sax Count, they seem to have created their own
> >> handler
> >> >> >> class
> >> >> >> >>> (saxcounthandler):
> >> >> >> >>>
> >> >> >> >>> SAXCountHandlers handler;
> >> >> >> >>>     parser->setDocumentHandler(&handler);
> >> >> >> >>>     parser->setErrorHandler(&handler);
> >> >> >> >>>
> >> >> >> >>> How can they do this as The type needed in setDocumentHandler
> >> >> needs
> >> >> >> to
> >> >> >> >>> be type DocumentHandler.
> >> >> >> >>>
> >> >> >> >>> When I try to use my custom class as a handler, it gives an
> >> >> >> error...what
> >> >> >> >>> is special about the SaxCountHandlers..?
> >> >> >> >>>
> >> >> >> >>> Ive used pointers,. they have dereferenced an object, surely im
> >> >> doing
> >> >> >> >>> the same thing?
> >> >> >> >>>
> >> >> >> >>> Many Thanks
> >> >> >> >>> Alex
> >> >> >> >>>
> >> >> >> >>> p.s: Also by DocumentHandler, what does this do exactly. Im
> >> >> thinking
> >> >> >> its
> >> >> >> >>> the controller for the parsing. I.e you can use the parsed data
> >> to
> >> >> >> >>> modify the handler and visa-versa
> >> >> >> >>>
> >> >> >> >>>
> >> >> >> >>>
> >> >> >> >>>
> >> >> >> >>>
> >> >> >> >>
> >> >> >> >>
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >> >>--
> >> >> >>View this message in context:
> >> >> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7921219
> >> >> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> >> >> >
> >> >> >
> >> >> >
> >> >>
> >> >>--
> >> >>View this message in context:
> >> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7928122
> >> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> >> >
> >> >
> >> >
> >>
> >>--
> >>View this message in context:
> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7929328
> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> >
> >
> >
>
>--
>View this message in context: 
>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7929765
>Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by appleGuy <al...@gmail.com>.
Ok, cool

Couldnt I use an STL Map to map the strings to Enums?

Also currently my code compiles fine but i get a runtime error when
executed. Its having problems with the parser->parse(XMLfile) bit. Is it
because my handler class isnt completed or is there other problems.

Thanks
Alex



Alberto Massari wrote:
> 
> At 06.11 18/12/2006 -0800, appleGuy wrote:
> 
>>Ok, ive found it in my library.
>>
>>Could you please do me a massive favour & show a step by step of your
>>process. To be honest im not totally understanding your logic to achieve
my
>>goal. Also because its not documented its harder to impliment.
> 
> Disclaimer: it's a totally untested code...
> 
> #include <xercesc/util/StringPool.hpp>
> 
> class myHandler : public DocumentHandler
> {
> [...]
>      virtual void startDocument();
>      virtual void startElement
>      (
>          const   XMLCh* const    name
>          ,       AttributeList&  attrs
>      );
> 
> protected:
>    XMLStringPool _map;
> };
> 
> void myHandler::startDocument()
> {
>    _map.flushAll();
>    _map.addOrFind(L"loopcardprj");       // id = 1
>    _map.addOrFind(L"_prjsetup"); // id = 2
>    _map.addOrFind(L"title");     // id = 3
>    _map.addOrFind(L"author");    // id = 4
>    _map.addOrFind(L"subject");   // id = 5
>    _map.addOrFind(L"card");      // id = 6
>    _map.addOrFind(L"_questions");        // id = 7
>    _map.addOrFind(L"question");  // id = 8
>    _map.addOrFind(L"q"); // id = 9
>    _map.addOrFind(L"a"); // id = 10
>    _map.addOrFind(L"comment");   // id = 11
> }
> 
> void myHandler::startElement(const XMLCh* const name, AttributeList& 
> attrs)
> {
>    switch(_map.getId(name))
>    {
>      // place the code in the corresponding 'case' branch...
>      case 1:
>      case 2:
>      case 3:
>      case 4:
>      case 5:
>      case 6:
>      case 7:
>      case 8:
>      case 9:
>      case 10:
>      case 11:
>    }
> }
> 
> Alberto
> 
> 
>>Many Thanks Alberto
>>
>>-Alex
>>
>>
>>Alberto Massari wrote:
>> >
>> > At 04.41 18/12/2006 -0800, appleGuy wrote:
>> >
>> >>Ok,
>> >>
>> >>I cant seem to see XMLStringPool in the docs, there is a
>> >>XMLSyncronisedStringPool...
>> >
>> > I guess it was treated as an internal helper class, as it is
>> > explicitly removed from the doc generation step (while
>> > XMLSyncronisedStringPool is a more recent class that escaped the
>> > check...). You can use XMLSyncronisedStringPool (that derives from
>> > XMLStringPool), or just include xercesc/util/StringPool.hpp and use
>> > XMLStringPool...
>> >
>> > Alberto
>> >
>> >>???
>> >>
>> >>-Alex
>> >>
>> >>
>> >>Alberto Massari wrote:
>> >> >
>> >> > At 15.05 17/12/2006 -0800, appleGuy wrote:
>> >> >
>> >> >>Hi,
>> >> >>
>> >> >>Ive been getting there with this Sax buisness...
>> >> >>
>> >> >>Now my handler class is on the way (the problem I had earlier is
>> >> sorted)
>> >> >>
>> >> >>However How do I make comparisons efficently using SAX...I mean when
>> it
>> >>get
>> >> >>the tag, i need to compare it & find the right variable to assign
>> the
>> >> >>character data too (the data between the tags)
>> >> >
>> >> > I would add to my handler class an instance of type XMLStringPool,
>> >> > initialize it by adding to it the names I am interested in (using
>> >> > addOrFind), then use getId to convert the node name into one of
>> these
>> >> > known ids.
>> >> >
>> >> > Alberto
>> >> >
>> >> >
>> >> >>Cheers
>> >> >>Alex
>> >> >>
>> >> >>
>> >> >>appleGuy wrote:
>> >> >> >
>> >> >> > Ok,
>> >> >> >
>> >> >> > Im going to include my code for this problem.
>> >> >> > I get an error when the parse function is called:
>> >> >> > parser->parse(XMLfile)....Ive got no idea why
>> >> >> >
>> >> >> > Also this was formed from the SaxCount Code included with the
>> Xerces
>> >> >> > distro.
>> >> >> >
>> >> >> > Currently I dont see it doing anything. I need to be able to
>> change
>> >> >> > variable & containers in the DocumentHandler Class
>> >> >> >
>> >> >> > Cheers
>> >> >> > Alex
>> >> >> >
>> >> >> >
>> >> >> > bool prjLoad::loadXML_prj(char *prj_filename){
>> >> >> >       //Start XML Xerces Framework
>> >> >> >       try {
>> >> >> >             XMLPlatformUtils::Initialize();
>> >> >> >         }
>> >> >> >         catch (const XMLException& toCatch) {
>> >> >> >             char* message =
>> >> XMLString::transcode(toCatch.getMessage());
>> >> >> >             cout << "Error during initialization! :\n"
>> >> >> >                  << message << "\n";
>> >> >> >             XMLString::release(&message);
>> >> >> >                       return false;
>> >> >> >         }
>> >> >> >
>> >> >> >               //Create New Parser (SAX)
>> >> >> >         SAXParser* parser = new SAXParser();
>> >> >> >
>> >> >> >               //File Input Validation
>> >> >> >         parser->setDoValidation(true);
>> >> >> >         parser->setDoNamespaces(true);
>> >> >> >
>> >> >> >               //Create our SAX handler object and install it on
>> >> >> the parser (Doc &
>> >> >> > Error Handler)
>> >> >> >               //Using Project as Handler
>> >> >> >               parser->setDocumentHandler(prj);
>> >> >> >               parser->setErrorHandler(prj);
>> >> >> >
>> >> >> >               //Load File through Xerces
>> >> >> >               XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>> >> >> >         xmlFileHandle.open(prj_filename);
>> >> >> >
>> >> >> >               //Load Each Line From File To Array xmlFile
>> >> >> >               bool flag = true;
>> >> >> >               while (flag == true)
>> >> >> >     {
>> >> >> >         char token[1000];
>> >> >> >         //Set array to zeros
>> >> >> >         memset(token,0,sizeof(token));
>> >> >> >
>> >> >> >               //Sequential Search
>> >> >> >               if(!(xmlFileHandle.eof())){
>> >> >> >                       xmlFileHandle.getline(token,
>> sizeof(token));
>> >> >> >
>> >> >> >                       //Check If Line Contains Anything
>> >> >> >                       if(!(token))
>> >> >> >                               continue;
>> >> >> >                       else {
>> >> >> >                               //Load into New Derived Variable
>> >> >> for overloading & Safety
>> >> >> >                               const char *XMLfile = token;
>> >> >> >
>> >> >> >                               //Debug
>> >> >> >                               cout << "Parsing: " << XMLfile <<
>> >> endl;
>> >> >> >
>> >> >> >                               //ERROR WIPE -> NEEDS IMPLIMENTING
>> >> >> >
>> >> >> >                               try {
>> >> >> >                                       parser->parse(XMLfile);
>> >> >> >                               }
>> >> >> >                               catch(int debug /*Use Exception in
>> >> >> class*/){
>> >> >> >                                       cout << "ERROR OCCURED" <<
>> >> endl;
>> >> >> >                               }
>> >> >> >
>> >> >> >                       }
>> >> >> >
>> >> >> >
>> >> >> >               }
>> >> >> >               //ELSE STATEMENT FOR EOF-> Set Flag to false
>> >> >> therefore exiting while
>> >> >> > loop
>> >> >> >               else
>> >> >> >                       flag = false;
>> >> >> >
>> >> >> >
>> >> >> >       }
>> >> >> >
>> >> >> >               return true;
>> >> >> > }
>> >> >> >
>> >> >> >
>> >> >> > appleGuy wrote:
>> >> >> >>
>> >> >> >> Its Ok,
>> >> >> >>
>> >> >> >> I needed to inheirt from the handlerbase class
>> >> >> >>
>> >> >> >>
>> >> >> >> Cheers
>> >> >> >> ALEX
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> appleGuy wrote:
>> >> >> >>>
>> >> >> >>> Hi,
>> >> >> >>>
>> >> >> >>> Ive finally started to get going using Sax. Now im using the
>> >> Samples
>> >> >> to
>> >> >> >>> help coding my own project.
>> >> >> >>>
>> >> >> >>> Looking at Sax Count, they seem to have created their own
>> handler
>> >> >> class
>> >> >> >>> (saxcounthandler):
>> >> >> >>>
>> >> >> >>> SAXCountHandlers handler;
>> >> >> >>>     parser->setDocumentHandler(&handler);
>> >> >> >>>     parser->setErrorHandler(&handler);
>> >> >> >>>
>> >> >> >>> How can they do this as The type needed in setDocumentHandler
>> >> needs
>> >> >> to
>> >> >> >>> be type DocumentHandler.
>> >> >> >>>
>> >> >> >>> When I try to use my custom class as a handler, it gives an
>> >> >> error...what
>> >> >> >>> is special about the SaxCountHandlers..?
>> >> >> >>>
>> >> >> >>> Ive used pointers,. they have dereferenced an object, surely im
>> >> doing
>> >> >> >>> the same thing?
>> >> >> >>>
>> >> >> >>> Many Thanks
>> >> >> >>> Alex
>> >> >> >>>
>> >> >> >>> p.s: Also by DocumentHandler, what does this do exactly. Im
>> >> thinking
>> >> >> its
>> >> >> >>> the controller for the parsing. I.e you can use the parsed data
>> to
>> >> >> >>> modify the handler and visa-versa
>> >> >> >>>
>> >> >> >>>
>> >> >> >>>
>> >> >> >>>
>> >> >> >>>
>> >> >> >>
>> >> >> >>
>> >> >> >
>> >> >> >
>> >> >>
>> >> >>--
>> >> >>View this message in context:
>> >> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7921219
>> >> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> >> >
>> >> >
>> >> >
>> >>
>> >>--
>> >>View this message in context:
>> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7928122
>> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> >
>> >
>> >
>>
>>--
>>View this message in context: 
>>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7929328
>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7929765
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by Alberto Massari <am...@datadirect.com>.
At 06.11 18/12/2006 -0800, appleGuy wrote:

>Ok, ive found it in my library.
>
>Could you please do me a massive favour & show a step by step of your
>process. To be honest im not totally understanding your logic to achieve my
>goal. Also because its not documented its harder to impliment.

Disclaimer: it's a totally untested code...

#include <xercesc/util/StringPool.hpp>

class myHandler : public DocumentHandler
{
[...]
     virtual void startDocument();
     virtual void startElement
     (
         const   XMLCh* const    name
         ,       AttributeList&  attrs
     );

protected:
   XMLStringPool _map;
};

void myHandler::startDocument()
{
   _map.flushAll();
   _map.addOrFind(L"loopcardprj");       // id = 1
   _map.addOrFind(L"_prjsetup"); // id = 2
   _map.addOrFind(L"title");     // id = 3
   _map.addOrFind(L"author");    // id = 4
   _map.addOrFind(L"subject");   // id = 5
   _map.addOrFind(L"card");      // id = 6
   _map.addOrFind(L"_questions");        // id = 7
   _map.addOrFind(L"question");  // id = 8
   _map.addOrFind(L"q"); // id = 9
   _map.addOrFind(L"a"); // id = 10
   _map.addOrFind(L"comment");   // id = 11
}

void myHandler::startElement(const XMLCh* const name, AttributeList&  attrs)
{
   switch(_map.getId(name))
   {
     // place the code in the corresponding 'case' branch...
     case 1:
     case 2:
     case 3:
     case 4:
     case 5:
     case 6:
     case 7:
     case 8:
     case 9:
     case 10:
     case 11:
   }
}

Alberto


>Many Thanks Alberto
>
>-Alex
>
>
>Alberto Massari wrote:
> >
> > At 04.41 18/12/2006 -0800, appleGuy wrote:
> >
> >>Ok,
> >>
> >>I cant seem to see XMLStringPool in the docs, there is a
> >>XMLSyncronisedStringPool...
> >
> > I guess it was treated as an internal helper class, as it is
> > explicitly removed from the doc generation step (while
> > XMLSyncronisedStringPool is a more recent class that escaped the
> > check...). You can use XMLSyncronisedStringPool (that derives from
> > XMLStringPool), or just include xercesc/util/StringPool.hpp and use
> > XMLStringPool...
> >
> > Alberto
> >
> >>???
> >>
> >>-Alex
> >>
> >>
> >>Alberto Massari wrote:
> >> >
> >> > At 15.05 17/12/2006 -0800, appleGuy wrote:
> >> >
> >> >>Hi,
> >> >>
> >> >>Ive been getting there with this Sax buisness...
> >> >>
> >> >>Now my handler class is on the way (the problem I had earlier is
> >> sorted)
> >> >>
> >> >>However How do I make comparisons efficently using SAX...I mean when it
> >>get
> >> >>the tag, i need to compare it & find the right variable to assign the
> >> >>character data too (the data between the tags)
> >> >
> >> > I would add to my handler class an instance of type XMLStringPool,
> >> > initialize it by adding to it the names I am interested in (using
> >> > addOrFind), then use getId to convert the node name into one of these
> >> > known ids.
> >> >
> >> > Alberto
> >> >
> >> >
> >> >>Cheers
> >> >>Alex
> >> >>
> >> >>
> >> >>appleGuy wrote:
> >> >> >
> >> >> > Ok,
> >> >> >
> >> >> > Im going to include my code for this problem.
> >> >> > I get an error when the parse function is called:
> >> >> > parser->parse(XMLfile)....Ive got no idea why
> >> >> >
> >> >> > Also this was formed from the SaxCount Code included with the Xerces
> >> >> > distro.
> >> >> >
> >> >> > Currently I dont see it doing anything. I need to be able to change
> >> >> > variable & containers in the DocumentHandler Class
> >> >> >
> >> >> > Cheers
> >> >> > Alex
> >> >> >
> >> >> >
> >> >> > bool prjLoad::loadXML_prj(char *prj_filename){
> >> >> >       //Start XML Xerces Framework
> >> >> >       try {
> >> >> >             XMLPlatformUtils::Initialize();
> >> >> >         }
> >> >> >         catch (const XMLException& toCatch) {
> >> >> >             char* message =
> >> XMLString::transcode(toCatch.getMessage());
> >> >> >             cout << "Error during initialization! :\n"
> >> >> >                  << message << "\n";
> >> >> >             XMLString::release(&message);
> >> >> >                       return false;
> >> >> >         }
> >> >> >
> >> >> >               //Create New Parser (SAX)
> >> >> >         SAXParser* parser = new SAXParser();
> >> >> >
> >> >> >               //File Input Validation
> >> >> >         parser->setDoValidation(true);
> >> >> >         parser->setDoNamespaces(true);
> >> >> >
> >> >> >               //Create our SAX handler object and install it on
> >> >> the parser (Doc &
> >> >> > Error Handler)
> >> >> >               //Using Project as Handler
> >> >> >               parser->setDocumentHandler(prj);
> >> >> >               parser->setErrorHandler(prj);
> >> >> >
> >> >> >               //Load File through Xerces
> >> >> >               XERCES_STD_QUALIFIER ifstream xmlFileHandle;
> >> >> >         xmlFileHandle.open(prj_filename);
> >> >> >
> >> >> >               //Load Each Line From File To Array xmlFile
> >> >> >               bool flag = true;
> >> >> >               while (flag == true)
> >> >> >     {
> >> >> >         char token[1000];
> >> >> >         //Set array to zeros
> >> >> >         memset(token,0,sizeof(token));
> >> >> >
> >> >> >               //Sequential Search
> >> >> >               if(!(xmlFileHandle.eof())){
> >> >> >                       xmlFileHandle.getline(token, sizeof(token));
> >> >> >
> >> >> >                       //Check If Line Contains Anything
> >> >> >                       if(!(token))
> >> >> >                               continue;
> >> >> >                       else {
> >> >> >                               //Load into New Derived Variable
> >> >> for overloading & Safety
> >> >> >                               const char *XMLfile = token;
> >> >> >
> >> >> >                               //Debug
> >> >> >                               cout << "Parsing: " << XMLfile <<
> >> endl;
> >> >> >
> >> >> >                               //ERROR WIPE -> NEEDS IMPLIMENTING
> >> >> >
> >> >> >                               try {
> >> >> >                                       parser->parse(XMLfile);
> >> >> >                               }
> >> >> >                               catch(int debug /*Use Exception in
> >> >> class*/){
> >> >> >                                       cout << "ERROR OCCURED" <<
> >> endl;
> >> >> >                               }
> >> >> >
> >> >> >                       }
> >> >> >
> >> >> >
> >> >> >               }
> >> >> >               //ELSE STATEMENT FOR EOF-> Set Flag to false
> >> >> therefore exiting while
> >> >> > loop
> >> >> >               else
> >> >> >                       flag = false;
> >> >> >
> >> >> >
> >> >> >       }
> >> >> >
> >> >> >               return true;
> >> >> > }
> >> >> >
> >> >> >
> >> >> > appleGuy wrote:
> >> >> >>
> >> >> >> Its Ok,
> >> >> >>
> >> >> >> I needed to inheirt from the handlerbase class
> >> >> >>
> >> >> >>
> >> >> >> Cheers
> >> >> >> ALEX
> >> >> >>
> >> >> >>
> >> >> >>
> >> >> >> appleGuy wrote:
> >> >> >>>
> >> >> >>> Hi,
> >> >> >>>
> >> >> >>> Ive finally started to get going using Sax. Now im using the
> >> Samples
> >> >> to
> >> >> >>> help coding my own project.
> >> >> >>>
> >> >> >>> Looking at Sax Count, they seem to have created their own handler
> >> >> class
> >> >> >>> (saxcounthandler):
> >> >> >>>
> >> >> >>> SAXCountHandlers handler;
> >> >> >>>     parser->setDocumentHandler(&handler);
> >> >> >>>     parser->setErrorHandler(&handler);
> >> >> >>>
> >> >> >>> How can they do this as The type needed in setDocumentHandler
> >> needs
> >> >> to
> >> >> >>> be type DocumentHandler.
> >> >> >>>
> >> >> >>> When I try to use my custom class as a handler, it gives an
> >> >> error...what
> >> >> >>> is special about the SaxCountHandlers..?
> >> >> >>>
> >> >> >>> Ive used pointers,. they have dereferenced an object, surely im
> >> doing
> >> >> >>> the same thing?
> >> >> >>>
> >> >> >>> Many Thanks
> >> >> >>> Alex
> >> >> >>>
> >> >> >>> p.s: Also by DocumentHandler, what does this do exactly. Im
> >> thinking
> >> >> its
> >> >> >>> the controller for the parsing. I.e you can use the parsed data to
> >> >> >>> modify the handler and visa-versa
> >> >> >>>
> >> >> >>>
> >> >> >>>
> >> >> >>>
> >> >> >>>
> >> >> >>
> >> >> >>
> >> >> >
> >> >> >
> >> >>
> >> >>--
> >> >>View this message in context:
> >> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7921219
> >> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> >> >
> >> >
> >> >
> >>
> >>--
> >>View this message in context:
> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7928122
> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> >
> >
> >
>
>--
>View this message in context: 
>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7929328
>Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by appleGuy <al...@gmail.com>.
Ok, ive found it in my library.

Could you please do me a massive favour & show a step by step of your
process. To be honest im not totally understanding your logic to achieve my
goal. Also because its not documented its harder to impliment.

Many Thanks Alberto

-Alex


Alberto Massari wrote:
> 
> At 04.41 18/12/2006 -0800, appleGuy wrote:
> 
>>Ok,
>>
>>I cant seem to see XMLStringPool in the docs, there is a
>>XMLSyncronisedStringPool...
> 
> I guess it was treated as an internal helper class, as it is 
> explicitly removed from the doc generation step (while 
> XMLSyncronisedStringPool is a more recent class that escaped the 
> check...). You can use XMLSyncronisedStringPool (that derives from 
> XMLStringPool), or just include xercesc/util/StringPool.hpp and use 
> XMLStringPool...
> 
> Alberto
> 
>>???
>>
>>-Alex
>>
>>
>>Alberto Massari wrote:
>> >
>> > At 15.05 17/12/2006 -0800, appleGuy wrote:
>> >
>> >>Hi,
>> >>
>> >>Ive been getting there with this Sax buisness...
>> >>
>> >>Now my handler class is on the way (the problem I had earlier is
>> sorted)
>> >>
>> >>However How do I make comparisons efficently using SAX...I mean when it
>>get
>> >>the tag, i need to compare it & find the right variable to assign the
>> >>character data too (the data between the tags)
>> >
>> > I would add to my handler class an instance of type XMLStringPool,
>> > initialize it by adding to it the names I am interested in (using
>> > addOrFind), then use getId to convert the node name into one of these
>> > known ids.
>> >
>> > Alberto
>> >
>> >
>> >>Cheers
>> >>Alex
>> >>
>> >>
>> >>appleGuy wrote:
>> >> >
>> >> > Ok,
>> >> >
>> >> > Im going to include my code for this problem.
>> >> > I get an error when the parse function is called:
>> >> > parser->parse(XMLfile)....Ive got no idea why
>> >> >
>> >> > Also this was formed from the SaxCount Code included with the Xerces
>> >> > distro.
>> >> >
>> >> > Currently I dont see it doing anything. I need to be able to change
>> >> > variable & containers in the DocumentHandler Class
>> >> >
>> >> > Cheers
>> >> > Alex
>> >> >
>> >> >
>> >> > bool prjLoad::loadXML_prj(char *prj_filename){
>> >> >       //Start XML Xerces Framework
>> >> >       try {
>> >> >             XMLPlatformUtils::Initialize();
>> >> >         }
>> >> >         catch (const XMLException& toCatch) {
>> >> >             char* message =
>> XMLString::transcode(toCatch.getMessage());
>> >> >             cout << "Error during initialization! :\n"
>> >> >                  << message << "\n";
>> >> >             XMLString::release(&message);
>> >> >                       return false;
>> >> >         }
>> >> >
>> >> >               //Create New Parser (SAX)
>> >> >         SAXParser* parser = new SAXParser();
>> >> >
>> >> >               //File Input Validation
>> >> >         parser->setDoValidation(true);
>> >> >         parser->setDoNamespaces(true);
>> >> >
>> >> >               //Create our SAX handler object and install it on
>> >> the parser (Doc &
>> >> > Error Handler)
>> >> >               //Using Project as Handler
>> >> >               parser->setDocumentHandler(prj);
>> >> >               parser->setErrorHandler(prj);
>> >> >
>> >> >               //Load File through Xerces
>> >> >               XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>> >> >         xmlFileHandle.open(prj_filename);
>> >> >
>> >> >               //Load Each Line From File To Array xmlFile
>> >> >               bool flag = true;
>> >> >               while (flag == true)
>> >> >     {
>> >> >         char token[1000];
>> >> >         //Set array to zeros
>> >> >         memset(token,0,sizeof(token));
>> >> >
>> >> >               //Sequential Search
>> >> >               if(!(xmlFileHandle.eof())){
>> >> >                       xmlFileHandle.getline(token, sizeof(token));
>> >> >
>> >> >                       //Check If Line Contains Anything
>> >> >                       if(!(token))
>> >> >                               continue;
>> >> >                       else {
>> >> >                               //Load into New Derived Variable
>> >> for overloading & Safety
>> >> >                               const char *XMLfile = token;
>> >> >
>> >> >                               //Debug
>> >> >                               cout << "Parsing: " << XMLfile <<
>> endl;
>> >> >
>> >> >                               //ERROR WIPE -> NEEDS IMPLIMENTING
>> >> >
>> >> >                               try {
>> >> >                                       parser->parse(XMLfile);
>> >> >                               }
>> >> >                               catch(int debug /*Use Exception in
>> >> class*/){
>> >> >                                       cout << "ERROR OCCURED" <<
>> endl;
>> >> >                               }
>> >> >
>> >> >                       }
>> >> >
>> >> >
>> >> >               }
>> >> >               //ELSE STATEMENT FOR EOF-> Set Flag to false
>> >> therefore exiting while
>> >> > loop
>> >> >               else
>> >> >                       flag = false;
>> >> >
>> >> >
>> >> >       }
>> >> >
>> >> >               return true;
>> >> > }
>> >> >
>> >> >
>> >> > appleGuy wrote:
>> >> >>
>> >> >> Its Ok,
>> >> >>
>> >> >> I needed to inheirt from the handlerbase class
>> >> >>
>> >> >>
>> >> >> Cheers
>> >> >> ALEX
>> >> >>
>> >> >>
>> >> >>
>> >> >> appleGuy wrote:
>> >> >>>
>> >> >>> Hi,
>> >> >>>
>> >> >>> Ive finally started to get going using Sax. Now im using the
>> Samples
>> >> to
>> >> >>> help coding my own project.
>> >> >>>
>> >> >>> Looking at Sax Count, they seem to have created their own handler
>> >> class
>> >> >>> (saxcounthandler):
>> >> >>>
>> >> >>> SAXCountHandlers handler;
>> >> >>>     parser->setDocumentHandler(&handler);
>> >> >>>     parser->setErrorHandler(&handler);
>> >> >>>
>> >> >>> How can they do this as The type needed in setDocumentHandler
>> needs
>> >> to
>> >> >>> be type DocumentHandler.
>> >> >>>
>> >> >>> When I try to use my custom class as a handler, it gives an
>> >> error...what
>> >> >>> is special about the SaxCountHandlers..?
>> >> >>>
>> >> >>> Ive used pointers,. they have dereferenced an object, surely im
>> doing
>> >> >>> the same thing?
>> >> >>>
>> >> >>> Many Thanks
>> >> >>> Alex
>> >> >>>
>> >> >>> p.s: Also by DocumentHandler, what does this do exactly. Im
>> thinking
>> >> its
>> >> >>> the controller for the parsing. I.e you can use the parsed data to
>> >> >>> modify the handler and visa-versa
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>>
>> >> >>
>> >> >>
>> >> >
>> >> >
>> >>
>> >>--
>> >>View this message in context:
>> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7921219
>> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
>> >
>> >
>> >
>>
>>--
>>View this message in context: 
>>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7928122
>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7929328
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by Alberto Massari <am...@datadirect.com>.
At 04.41 18/12/2006 -0800, appleGuy wrote:

>Ok,
>
>I cant seem to see XMLStringPool in the docs, there is a
>XMLSyncronisedStringPool...

I guess it was treated as an internal helper class, as it is 
explicitly removed from the doc generation step (while 
XMLSyncronisedStringPool is a more recent class that escaped the 
check...). You can use XMLSyncronisedStringPool (that derives from 
XMLStringPool), or just include xercesc/util/StringPool.hpp and use 
XMLStringPool...

Alberto

>???
>
>-Alex
>
>
>Alberto Massari wrote:
> >
> > At 15.05 17/12/2006 -0800, appleGuy wrote:
> >
> >>Hi,
> >>
> >>Ive been getting there with this Sax buisness...
> >>
> >>Now my handler class is on the way (the problem I had earlier is sorted)
> >>
> >>However How do I make comparisons efficently using SAX...I mean when it
>get
> >>the tag, i need to compare it & find the right variable to assign the
> >>character data too (the data between the tags)
> >
> > I would add to my handler class an instance of type XMLStringPool,
> > initialize it by adding to it the names I am interested in (using
> > addOrFind), then use getId to convert the node name into one of these
> > known ids.
> >
> > Alberto
> >
> >
> >>Cheers
> >>Alex
> >>
> >>
> >>appleGuy wrote:
> >> >
> >> > Ok,
> >> >
> >> > Im going to include my code for this problem.
> >> > I get an error when the parse function is called:
> >> > parser->parse(XMLfile)....Ive got no idea why
> >> >
> >> > Also this was formed from the SaxCount Code included with the Xerces
> >> > distro.
> >> >
> >> > Currently I dont see it doing anything. I need to be able to change
> >> > variable & containers in the DocumentHandler Class
> >> >
> >> > Cheers
> >> > Alex
> >> >
> >> >
> >> > bool prjLoad::loadXML_prj(char *prj_filename){
> >> >       //Start XML Xerces Framework
> >> >       try {
> >> >             XMLPlatformUtils::Initialize();
> >> >         }
> >> >         catch (const XMLException& toCatch) {
> >> >             char* message = XMLString::transcode(toCatch.getMessage());
> >> >             cout << "Error during initialization! :\n"
> >> >                  << message << "\n";
> >> >             XMLString::release(&message);
> >> >                       return false;
> >> >         }
> >> >
> >> >               //Create New Parser (SAX)
> >> >         SAXParser* parser = new SAXParser();
> >> >
> >> >               //File Input Validation
> >> >         parser->setDoValidation(true);
> >> >         parser->setDoNamespaces(true);
> >> >
> >> >               //Create our SAX handler object and install it on
> >> the parser (Doc &
> >> > Error Handler)
> >> >               //Using Project as Handler
> >> >               parser->setDocumentHandler(prj);
> >> >               parser->setErrorHandler(prj);
> >> >
> >> >               //Load File through Xerces
> >> >               XERCES_STD_QUALIFIER ifstream xmlFileHandle;
> >> >         xmlFileHandle.open(prj_filename);
> >> >
> >> >               //Load Each Line From File To Array xmlFile
> >> >               bool flag = true;
> >> >               while (flag == true)
> >> >     {
> >> >         char token[1000];
> >> >         //Set array to zeros
> >> >         memset(token,0,sizeof(token));
> >> >
> >> >               //Sequential Search
> >> >               if(!(xmlFileHandle.eof())){
> >> >                       xmlFileHandle.getline(token, sizeof(token));
> >> >
> >> >                       //Check If Line Contains Anything
> >> >                       if(!(token))
> >> >                               continue;
> >> >                       else {
> >> >                               //Load into New Derived Variable
> >> for overloading & Safety
> >> >                               const char *XMLfile = token;
> >> >
> >> >                               //Debug
> >> >                               cout << "Parsing: " << XMLfile << endl;
> >> >
> >> >                               //ERROR WIPE -> NEEDS IMPLIMENTING
> >> >
> >> >                               try {
> >> >                                       parser->parse(XMLfile);
> >> >                               }
> >> >                               catch(int debug /*Use Exception in
> >> class*/){
> >> >                                       cout << "ERROR OCCURED" << endl;
> >> >                               }
> >> >
> >> >                       }
> >> >
> >> >
> >> >               }
> >> >               //ELSE STATEMENT FOR EOF-> Set Flag to false
> >> therefore exiting while
> >> > loop
> >> >               else
> >> >                       flag = false;
> >> >
> >> >
> >> >       }
> >> >
> >> >               return true;
> >> > }
> >> >
> >> >
> >> > appleGuy wrote:
> >> >>
> >> >> Its Ok,
> >> >>
> >> >> I needed to inheirt from the handlerbase class
> >> >>
> >> >>
> >> >> Cheers
> >> >> ALEX
> >> >>
> >> >>
> >> >>
> >> >> appleGuy wrote:
> >> >>>
> >> >>> Hi,
> >> >>>
> >> >>> Ive finally started to get going using Sax. Now im using the Samples
> >> to
> >> >>> help coding my own project.
> >> >>>
> >> >>> Looking at Sax Count, they seem to have created their own handler
> >> class
> >> >>> (saxcounthandler):
> >> >>>
> >> >>> SAXCountHandlers handler;
> >> >>>     parser->setDocumentHandler(&handler);
> >> >>>     parser->setErrorHandler(&handler);
> >> >>>
> >> >>> How can they do this as The type needed in setDocumentHandler needs
> >> to
> >> >>> be type DocumentHandler.
> >> >>>
> >> >>> When I try to use my custom class as a handler, it gives an
> >> error...what
> >> >>> is special about the SaxCountHandlers..?
> >> >>>
> >> >>> Ive used pointers,. they have dereferenced an object, surely im doing
> >> >>> the same thing?
> >> >>>
> >> >>> Many Thanks
> >> >>> Alex
> >> >>>
> >> >>> p.s: Also by DocumentHandler, what does this do exactly. Im thinking
> >> its
> >> >>> the controller for the parsing. I.e you can use the parsed data to
> >> >>> modify the handler and visa-versa
> >> >>>
> >> >>>
> >> >>>
> >> >>>
> >> >>>
> >> >>
> >> >>
> >> >
> >> >
> >>
> >>--
> >>View this message in context:
> >>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7921219
> >>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> >
> >
> >
>
>--
>View this message in context: 
>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7928122
>Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by appleGuy <al...@gmail.com>.
Ok,

I cant seem to see XMLStringPool in the docs, there is a
XMLSyncronisedStringPool...

???

-Alex


Alberto Massari wrote:
> 
> At 15.05 17/12/2006 -0800, appleGuy wrote:
> 
>>Hi,
>>
>>Ive been getting there with this Sax buisness...
>>
>>Now my handler class is on the way (the problem I had earlier is sorted)
>>
>>However How do I make comparisons efficently using SAX...I mean when it
get
>>the tag, i need to compare it & find the right variable to assign the
>>character data too (the data between the tags)
> 
> I would add to my handler class an instance of type XMLStringPool, 
> initialize it by adding to it the names I am interested in (using 
> addOrFind), then use getId to convert the node name into one of these 
> known ids.
> 
> Alberto
> 
> 
>>Cheers
>>Alex
>>
>>
>>appleGuy wrote:
>> >
>> > Ok,
>> >
>> > Im going to include my code for this problem.
>> > I get an error when the parse function is called:
>> > parser->parse(XMLfile)....Ive got no idea why
>> >
>> > Also this was formed from the SaxCount Code included with the Xerces
>> > distro.
>> >
>> > Currently I dont see it doing anything. I need to be able to change
>> > variable & containers in the DocumentHandler Class
>> >
>> > Cheers
>> > Alex
>> >
>> >
>> > bool prjLoad::loadXML_prj(char *prj_filename){
>> >       //Start XML Xerces Framework
>> >       try {
>> >             XMLPlatformUtils::Initialize();
>> >         }
>> >         catch (const XMLException& toCatch) {
>> >             char* message = XMLString::transcode(toCatch.getMessage());
>> >             cout << "Error during initialization! :\n"
>> >                  << message << "\n";
>> >             XMLString::release(&message);
>> >                       return false;
>> >         }
>> >
>> >               //Create New Parser (SAX)
>> >         SAXParser* parser = new SAXParser();
>> >
>> >               //File Input Validation
>> >         parser->setDoValidation(true);
>> >         parser->setDoNamespaces(true);
>> >
>> >               //Create our SAX handler object and install it on 
>> the parser (Doc &
>> > Error Handler)
>> >               //Using Project as Handler
>> >               parser->setDocumentHandler(prj);
>> >               parser->setErrorHandler(prj);
>> >
>> >               //Load File through Xerces
>> >               XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>> >         xmlFileHandle.open(prj_filename);
>> >
>> >               //Load Each Line From File To Array xmlFile
>> >               bool flag = true;
>> >               while (flag == true)
>> >     {
>> >         char token[1000];
>> >         //Set array to zeros
>> >         memset(token,0,sizeof(token));
>> >
>> >               //Sequential Search
>> >               if(!(xmlFileHandle.eof())){
>> >                       xmlFileHandle.getline(token, sizeof(token));
>> >
>> >                       //Check If Line Contains Anything
>> >                       if(!(token))
>> >                               continue;
>> >                       else {
>> >                               //Load into New Derived Variable 
>> for overloading & Safety
>> >                               const char *XMLfile = token;
>> >
>> >                               //Debug
>> >                               cout << "Parsing: " << XMLfile << endl;
>> >
>> >                               //ERROR WIPE -> NEEDS IMPLIMENTING
>> >
>> >                               try {
>> >                                       parser->parse(XMLfile);
>> >                               }
>> >                               catch(int debug /*Use Exception in
>> class*/){
>> >                                       cout << "ERROR OCCURED" << endl;
>> >                               }
>> >
>> >                       }
>> >
>> >
>> >               }
>> >               //ELSE STATEMENT FOR EOF-> Set Flag to false 
>> therefore exiting while
>> > loop
>> >               else
>> >                       flag = false;
>> >
>> >
>> >       }
>> >
>> >               return true;
>> > }
>> >
>> >
>> > appleGuy wrote:
>> >>
>> >> Its Ok,
>> >>
>> >> I needed to inheirt from the handlerbase class
>> >>
>> >>
>> >> Cheers
>> >> ALEX
>> >>
>> >>
>> >>
>> >> appleGuy wrote:
>> >>>
>> >>> Hi,
>> >>>
>> >>> Ive finally started to get going using Sax. Now im using the Samples
>> to
>> >>> help coding my own project.
>> >>>
>> >>> Looking at Sax Count, they seem to have created their own handler
>> class
>> >>> (saxcounthandler):
>> >>>
>> >>> SAXCountHandlers handler;
>> >>>     parser->setDocumentHandler(&handler);
>> >>>     parser->setErrorHandler(&handler);
>> >>>
>> >>> How can they do this as The type needed in setDocumentHandler needs
>> to
>> >>> be type DocumentHandler.
>> >>>
>> >>> When I try to use my custom class as a handler, it gives an
>> error...what
>> >>> is special about the SaxCountHandlers..?
>> >>>
>> >>> Ive used pointers,. they have dereferenced an object, surely im doing
>> >>> the same thing?
>> >>>
>> >>> Many Thanks
>> >>> Alex
>> >>>
>> >>> p.s: Also by DocumentHandler, what does this do exactly. Im thinking
>> its
>> >>> the controller for the parsing. I.e you can use the parsed data to
>> >>> modify the handler and visa-versa
>> >>>
>> >>>
>> >>>
>> >>>
>> >>>
>> >>
>> >>
>> >
>> >
>>
>>--
>>View this message in context: 
>>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7921219
>>Sent from the Xerces - C - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7928122
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by Alberto Massari <am...@datadirect.com>.
At 15.05 17/12/2006 -0800, appleGuy wrote:

>Hi,
>
>Ive been getting there with this Sax buisness...
>
>Now my handler class is on the way (the problem I had earlier is sorted)
>
>However How do I make comparisons efficently using SAX...I mean when it get
>the tag, i need to compare it & find the right variable to assign the
>character data too (the data between the tags)

I would add to my handler class an instance of type XMLStringPool, 
initialize it by adding to it the names I am interested in (using 
addOrFind), then use getId to convert the node name into one of these 
known ids.

Alberto


>Cheers
>Alex
>
>
>appleGuy wrote:
> >
> > Ok,
> >
> > Im going to include my code for this problem.
> > I get an error when the parse function is called:
> > parser->parse(XMLfile)....Ive got no idea why
> >
> > Also this was formed from the SaxCount Code included with the Xerces
> > distro.
> >
> > Currently I dont see it doing anything. I need to be able to change
> > variable & containers in the DocumentHandler Class
> >
> > Cheers
> > Alex
> >
> >
> > bool prjLoad::loadXML_prj(char *prj_filename){
> >       //Start XML Xerces Framework
> >       try {
> >             XMLPlatformUtils::Initialize();
> >         }
> >         catch (const XMLException& toCatch) {
> >             char* message = XMLString::transcode(toCatch.getMessage());
> >             cout << "Error during initialization! :\n"
> >                  << message << "\n";
> >             XMLString::release(&message);
> >                       return false;
> >         }
> >
> >               //Create New Parser (SAX)
> >         SAXParser* parser = new SAXParser();
> >
> >               //File Input Validation
> >         parser->setDoValidation(true);
> >         parser->setDoNamespaces(true);
> >
> >               //Create our SAX handler object and install it on 
> the parser (Doc &
> > Error Handler)
> >               //Using Project as Handler
> >               parser->setDocumentHandler(prj);
> >               parser->setErrorHandler(prj);
> >
> >               //Load File through Xerces
> >               XERCES_STD_QUALIFIER ifstream xmlFileHandle;
> >         xmlFileHandle.open(prj_filename);
> >
> >               //Load Each Line From File To Array xmlFile
> >               bool flag = true;
> >               while (flag == true)
> >     {
> >         char token[1000];
> >         //Set array to zeros
> >         memset(token,0,sizeof(token));
> >
> >               //Sequential Search
> >               if(!(xmlFileHandle.eof())){
> >                       xmlFileHandle.getline(token, sizeof(token));
> >
> >                       //Check If Line Contains Anything
> >                       if(!(token))
> >                               continue;
> >                       else {
> >                               //Load into New Derived Variable 
> for overloading & Safety
> >                               const char *XMLfile = token;
> >
> >                               //Debug
> >                               cout << "Parsing: " << XMLfile << endl;
> >
> >                               //ERROR WIPE -> NEEDS IMPLIMENTING
> >
> >                               try {
> >                                       parser->parse(XMLfile);
> >                               }
> >                               catch(int debug /*Use Exception in class*/){
> >                                       cout << "ERROR OCCURED" << endl;
> >                               }
> >
> >                       }
> >
> >
> >               }
> >               //ELSE STATEMENT FOR EOF-> Set Flag to false 
> therefore exiting while
> > loop
> >               else
> >                       flag = false;
> >
> >
> >       }
> >
> >               return true;
> > }
> >
> >
> > appleGuy wrote:
> >>
> >> Its Ok,
> >>
> >> I needed to inheirt from the handlerbase class
> >>
> >>
> >> Cheers
> >> ALEX
> >>
> >>
> >>
> >> appleGuy wrote:
> >>>
> >>> Hi,
> >>>
> >>> Ive finally started to get going using Sax. Now im using the Samples to
> >>> help coding my own project.
> >>>
> >>> Looking at Sax Count, they seem to have created their own handler class
> >>> (saxcounthandler):
> >>>
> >>> SAXCountHandlers handler;
> >>>     parser->setDocumentHandler(&handler);
> >>>     parser->setErrorHandler(&handler);
> >>>
> >>> How can they do this as The type needed in setDocumentHandler needs to
> >>> be type DocumentHandler.
> >>>
> >>> When I try to use my custom class as a handler, it gives an error...what
> >>> is special about the SaxCountHandlers..?
> >>>
> >>> Ive used pointers,. they have dereferenced an object, surely im doing
> >>> the same thing?
> >>>
> >>> Many Thanks
> >>> Alex
> >>>
> >>> p.s: Also by DocumentHandler, what does this do exactly. Im thinking its
> >>> the controller for the parsing. I.e you can use the parsed data to
> >>> modify the handler and visa-versa
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >
> >
>
>--
>View this message in context: 
>http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7921219
>Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by appleGuy <al...@gmail.com>.
Hi,

Ive been getting there with this Sax buisness...

Now my handler class is on the way (the problem I had earlier is sorted)

However How do I make comparisons efficently using SAX...I mean when it get
the tag, i need to compare it & find the right variable to assign the
character data too (the data between the tags)

Cheers
Alex


appleGuy wrote:
> 
> Ok,
> 
> Im going to include my code for this problem.
> I get an error when the parse function is called:
> parser->parse(XMLfile)....Ive got no idea why
> 
> Also this was formed from the SaxCount Code included with the Xerces
> distro.
> 
> Currently I dont see it doing anything. I need to be able to change
> variable & containers in the DocumentHandler Class
> 
> Cheers
> Alex
> 
> 
> bool prjLoad::loadXML_prj(char *prj_filename){
> 	//Start XML Xerces Framework
> 	try {
>             XMLPlatformUtils::Initialize();
>         }
>         catch (const XMLException& toCatch) {
>             char* message = XMLString::transcode(toCatch.getMessage());
>             cout << "Error during initialization! :\n"
>                  << message << "\n";
>             XMLString::release(&message);
> 			return false;
>         }
> 
> 		//Create New Parser (SAX)
>         SAXParser* parser = new SAXParser();
> 
> 		//File Input Validation
>         parser->setDoValidation(true);    
>         parser->setDoNamespaces(true);   
> 
> 		//Create our SAX handler object and install it on the parser (Doc &
> Error Handler)
> 		//Using Project as Handler
> 		parser->setDocumentHandler(prj);
> 		parser->setErrorHandler(prj);
> 
> 		//Load File through Xerces
> 		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
>         xmlFileHandle.open(prj_filename);
> 
> 		//Load Each Line From File To Array xmlFile
> 		bool flag = true;
> 		while (flag == true)
>     {
>         char token[1000];
>         //Set array to zeros
>         memset(token,0,sizeof(token));
> 
> 		//Sequential Search
> 		if(!(xmlFileHandle.eof())){
> 			xmlFileHandle.getline(token, sizeof(token));
> 
> 			//Check If Line Contains Anything
> 			if(!(token))
> 				continue;
> 			else {
> 				//Load into New Derived Variable for overloading & Safety
> 				const char *XMLfile = token;
> 
> 				//Debug
> 				cout << "Parsing: " << XMLfile << endl;
> 
> 				//ERROR WIPE -> NEEDS IMPLIMENTING
> 
> 				try {
> 					parser->parse(XMLfile);
> 				}
> 				catch(int debug /*Use Exception in class*/){
> 					cout << "ERROR OCCURED" << endl;
> 				}
> 
> 			}
> 			
> 		
> 		}
> 		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore exiting while
> loop
> 		else
> 			flag = false;
> 
> 
> 	}
> 
> 		return true;
> }
> 
> 
> appleGuy wrote:
>> 
>> Its Ok,
>> 
>> I needed to inheirt from the handlerbase class
>> 
>> 
>> Cheers
>> ALEX
>> 
>> 
>> 
>> appleGuy wrote:
>>> 
>>> Hi,
>>> 
>>> Ive finally started to get going using Sax. Now im using the Samples to
>>> help coding my own project.
>>> 
>>> Looking at Sax Count, they seem to have created their own handler class
>>> (saxcounthandler):
>>> 
>>> SAXCountHandlers handler;
>>>     parser->setDocumentHandler(&handler);
>>>     parser->setErrorHandler(&handler);
>>> 
>>> How can they do this as The type needed in setDocumentHandler needs to
>>> be type DocumentHandler.
>>> 
>>> When I try to use my custom class as a handler, it gives an error...what
>>> is special about the SaxCountHandlers..?
>>> 
>>> Ive used pointers,. they have dereferenced an object, surely im doing
>>> the same thing?
>>> 
>>> Many Thanks
>>> Alex
>>> 
>>> p.s: Also by DocumentHandler, what does this do exactly. Im thinking its
>>> the controller for the parsing. I.e you can use the parsed data to
>>> modify the handler and visa-versa
>>> 
>>> 
>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7921219
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by appleGuy <al...@gmail.com>.
Ok,

Im going to include my code for this problem.
I get an error when the parse function is called:
parser->parse(XMLfile)....Ive got no idea why

Also this was formed from the SaxCount Code included with the Xerces distro.

Currently I dont see it doing anything. I need to be able to change variable
& containers in the DocumentHandler Class

Cheers
Alex


bool prjLoad::loadXML_prj(char *prj_filename){
	//Start XML Xerces Framework
	try {
            XMLPlatformUtils::Initialize();
        }
        catch (const XMLException& toCatch) {
            char* message = XMLString::transcode(toCatch.getMessage());
            cout << "Error during initialization! :\n"
                 << message << "\n";
            XMLString::release(&message);
			return false;
        }

		//Create New Parser (SAX)
        SAXParser* parser = new SAXParser();

		//File Input Validation
        parser->setDoValidation(true);    
        parser->setDoNamespaces(true);   

		//Create our SAX handler object and install it on the parser (Doc & Error
Handler)
		//Using Project as Handler
		parser->setDocumentHandler(prj);
		parser->setErrorHandler(prj);

		//Load File through Xerces
		XERCES_STD_QUALIFIER ifstream xmlFileHandle;
        xmlFileHandle.open(prj_filename);

		//Load Each Line From File To Array xmlFile
		bool flag = true;
		while (flag == true)
    {
        char token[1000];
        //Set array to zeros
        memset(token,0,sizeof(token));

		//Sequential Search
		if(!(xmlFileHandle.eof())){
			xmlFileHandle.getline(token, sizeof(token));

			//Check If Line Contains Anything
			if(!(token))
				continue;
			else {
				//Load into New Derived Variable for overloading & Safety
				const char *XMLfile = token;

				//Debug
				cout << "Parsing: " << XMLfile << endl;

				//ERROR WIPE -> NEEDS IMPLIMENTING

				try {
					parser->parse(XMLfile);
				}
				catch(int debug /*Use Exception in class*/){
					cout << "ERROR OCCURED" << endl;
				}

			}
			
		
		}
		//ELSE STATEMENT FOR EOF-> Set Flag to false therefore exiting while loop
		else
			flag = false;


	}

		return true;
}


appleGuy wrote:
> 
> Its Ok,
> 
> I needed to inheirt from the handlerbase class
> 
> 
> Cheers
> ALEX
> 
> 
> 
> appleGuy wrote:
>> 
>> Hi,
>> 
>> Ive finally started to get going using Sax. Now im using the Samples to
>> help coding my own project.
>> 
>> Looking at Sax Count, they seem to have created their own handler class
>> (saxcounthandler):
>> 
>> SAXCountHandlers handler;
>>     parser->setDocumentHandler(&handler);
>>     parser->setErrorHandler(&handler);
>> 
>> How can they do this as The type needed in setDocumentHandler needs to be
>> type DocumentHandler.
>> 
>> When I try to use my custom class as a handler, it gives an error...what
>> is special about the SaxCountHandlers..?
>> 
>> Ive used pointers,. they have dereferenced an object, surely im doing the
>> same thing?
>> 
>> Many Thanks
>> Alex
>> 
>> p.s: Also by DocumentHandler, what does this do exactly. Im thinking its
>> the controller for the parsing. I.e you can use the parsed data to modify
>> the handler and visa-versa
>> 
>> 
>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7918375
Sent from the Xerces - C - Users mailing list archive at Nabble.com.


Re: Parsing Using SAX

Posted by appleGuy <al...@gmail.com>.
Its Ok,

I needed to inheirt from the handlerbase class


Cheers
ALEX



appleGuy wrote:
> 
> Hi,
> 
> Ive finally started to get going using Sax. Now im using the Samples to
> help coding my own project.
> 
> Looking at Sax Count, they seem to have created their own handler class
> (saxcounthandler):
> 
> SAXCountHandlers handler;
>     parser->setDocumentHandler(&handler);
>     parser->setErrorHandler(&handler);
> 
> How can they do this as The type needed in setDocumentHandler needs to be
> type DocumentHandler.
> 
> When I try to use my custom class as a handler, it gives an error...what
> is special about the SaxCountHandlers..?
> 
> Ive used pointers,. they have dereferenced an object, surely im doing the
> same thing?
> 
> Many Thanks
> Alex
> 
> p.s: Also by DocumentHandler, what does this do exactly. Im thinking its
> the controller for the parsing. I.e you can use the parsed data to modify
> the handler and visa-versa
> 
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Parsing-Using-SAX-tf2835675.html#a7917517
Sent from the Xerces - C - Users mailing list archive at Nabble.com.