Thread: Need help with Xerces/C++ Parser

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    9

    Need help with Xerces/C++ Parser

    There is no simple solution to this problem as I thought it would be. Can anyone help please?
    I am trying to print out the names of the elements and the attributes. Here are the files and code I have. The IDE is MSVC++ 7.1

    Sax2count.cpp main file:
    Code:
    const Attributes* myAtts = new VecAttributesImpl();
    const Attributes & atts = *myAtts;
    
    const XMLCh *const eleName = new XMLCh;//not sure what to do with the XMLCh
    
    handler.startDocument();
    handler.startElement(eleName,attributes);
    
    //this prints element names to console(xerces unique print method:same as cout)
    XERCES_STD_QUALIFIER cout << xmlFile << ": " <<" START" << " ms ("
    << handler.getElementName()<< " Element Name, "<< XERCES_STD_QUALIFIER endl;
    Handler files:
    Sax2countHandlers.cpp file:
    Code:
    //fElementName defined in const base class
    SAX2CountHandlers::SAX2CountHandlers() :
        fElementCount(0)
    	, fAttrCount(0)
    	, fElementName(0)//here
    		.
                                    .
                                    .
    --------------------------------------------
    void SAX2CountHandlers::startElement(const XMLCh *const eleName,
                               AttributeList & attributes)
    {
     char* message = XMLString::transcode(eleName);
        XERCES_STD_QUALIFIER cerr << "I saw element: "<< message <<        
        XERCES_STD_QUALIFIER endl;
        XMLString::release(&message);
    }
    Sax2countHandlers.hpp file:
    Code:
    public:
    
    // -----------------------------------------------------------------------
    //  Getter methods
    // -----------------------------------------------------------------------
        const XMLCh getElementName() const
        {
            return fElementName;
        }
    
    // -----------------------------------------------------------------------
    //  Handlers for the SAX ContentHandler interface
    // -----------------------------------------------------------------------
    void startElement(const XMLCh* const eleName,  AttributeList& attributes);
    
    //under private
    private:
      const XMLCh  fElementName;
    Console output:
    I saw element:========================================== ===================

    Xml file sample:
    <Scenarios>
    <Signal userName="Richard">
    <ScenarioName>PMOP-OS</ScenarioName>
    <RadioFrequency>3</RadioFrequency>
    <PRF1>33</PRF1>
    <StartFrequency>3</StartFrequency>
    <StopFrequency>3</StopFrequency>
    <ControlNumber>1002</ControlNumber>
    </Signal>
    <Signal userName="Mark">
    <ScenarioName>PMOP-OS</ScenarioName>
    <RadioFrequency>3</RadioFrequency>
    <PRF1>33</PRF1>
    <StartFrequency>3</StartFrequency>
    <StopFrequency>3</StopFrequency>
    <ControlNumber>1002</ControlNumber>
    </Signal>
    .
    .
    .
    Last edited by pipercubusa; 03-17-2005 at 09:15 PM.

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    What problems are you getting?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    9
    There are no build or compile errors, however the element names are not printing out. Once I enter the file name on the command line I get:
    Code:
    Console output:
    I saw element:========================================== ===================
    I think it may be the way in which I am initializing the const XMLCh *const eleName variable within the Sax2count.cpp main file. Not sure how the XMLCh should be initialize in order to get the function to print the element names out.
    Last edited by pipercubusa; 03-18-2005 at 12:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Working with Parser Generators - Functions
    By jason_m in forum C Programming
    Replies: 1
    Last Post: 09-09-2008, 09:38 PM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. Parser Help
    By Barnzey in forum C++ Programming
    Replies: 10
    Last Post: 10-26-2005, 12:10 PM
  4. Problem with a file parser.
    By Hulag in forum C++ Programming
    Replies: 7
    Last Post: 03-17-2005, 09:54 AM
  5. Parser - need help!
    By thelma in forum C Programming
    Replies: 2
    Last Post: 04-05-2004, 08:06 PM