I'm new to Poco and trying to use the XML parser to parse a file.
In the code below the parse() function throws a SAXParseException.
The stack call is
XML_ERROR_INVALID_TOKEN
ParseEngine::handleError
ParseEngine::parseByteInputStream
Surprisingly I still get the expected output on the console after the exception.
Is there something wrong with my xml file ? or am I doing something wrong in specifying the file as an input source ?
"plants.xml" that I use, is readable by my internet browser and is actually a copy of the file here :
plant_catalog.xml
Here's the code :
void visitSubTree(Node* node);
int _tmain(int argc, _TCHAR* argv[])
{
try
{
fstream file;
file.open("plants.xml",ios_base::in);
InputSource src;
src.setByteStream(file);
DOMParser parser;
Document* pDoc = parser.parse(&src);
Node* currentNode = pDoc->firstChild();
while ((currentNode != NULL) && currentNode->nodeType() != Node::ELEMENT_NODE)
{
currentNode = currentNode->nextSibling();
}
visitSubTree(currentNode);
file.close();
}
catch (Exception& exc)
{
cout << exc.displayText() << endl;
}
catch (...)
{
cout << "Exception C++" <
}
return 1;
}
void visitSubTree(Node* node) {
Node* attribNode = NULL;
Node* childNode = NULL;
NamedNodeMap* attribs;
Node* nodeIter = node->firstChild();
while (nodeIter != NULL)
{
cout << "NodeName : " << nodeIter->nodeName() << " - NodeType :" << nodeIter->nodeType() << " - NodeValue = " << nodeIter->getNodeValue() << endl;
if (nodeIter->hasAttributes())
{
attribs = nodeIter->attributes();
for (unsigned int i=0; i
{
attribNode = attribs->item(i);
cout << "Attribute = NodeName : " << attribNode->nodeName() << "- NodeType : " << attribNode->nodeType() << "- NodeValue : " << attribNode->nodeValue() << endl;
}
}
visitSubTree(nodeIter);
nodeIter = nodeIter->nextSibling();
}
}





