Overview
Features
Download
Documentation
Community
Add-Ons & Services

SAXParseException issue

Please post support and help requests here.

SAXParseException issue

Postby tnarol » 05 Apr 2007, 10:42

Hi,

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; ilength(); i++)

{

attribNode = attribs->item(i);

cout << "Attribute = NodeName : " << attribNode->nodeName() << "- NodeType : " << attribNode->nodeType() << "- NodeValue : " << attribNode->nodeValue() << endl;

}

}

visitSubTree(nodeIter);

nodeIter = nodeIter->nextSibling();

}

}
tnarol
 
Posts: 22
Joined: 21 Mar 2007, 18:56
Location: France

Re: SAXParseException issue

Postby guenter » 11 Apr 2007, 17:35

Hm, I was able to parse the plant_catalog.xml file without problems, both with the SAXParser and the DOMParser sample. Maybe you did something to the file after downloading (like adding some (unprintable) characters after the closing tag?)
guenter
 
Posts: 1134
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: SAXParseException issue

Postby tnarol » 23 May 2007, 12:25

OK it was my mistake... the program was simply not executing from the right location so the file was not found...
tnarol
 
Posts: 22
Joined: 21 Mar 2007, 18:56
Location: France


Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron