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>
.
.
.