hi,
I am using the xerces-c API for c++ to read an XML document. But when i try
to read it is not able to read the whole document, it contains 153 elements
of type row, but when parsed using the functions, it is able to identify
only 62 of them(first 62). How come this happen?
I am attaching the code i am using to parse through the file and the
corresponding xml file.
regards
Jinesh K J
P.S: the XML appears to be of size more than 100kb. Thus i can't attach the
XML file. Sorry for that.
--
My Feelings,Expressions-
http://logbookofanobserver.blogspot.com
SMC : My computer, My language http://smc.org.in
സ്വതന്ത്ര മലയാളം കമ്പ്യൂട്ടിങ്ങ്, എന്റെ കമ്പ്യൂട്ടറിന് എന്റെ ഭാഷ
void GetConfig::readConfigFile(string& configFile)
throw( std::runtime_error )
{
int flag = 0;
// Test to see if the file is ok.
struct stat fileStatus;
int iretStat = stat(configFile.c_str(), &fileStatus);
if( iretStat == ENOENT )
throw ( std::runtime_error("Path file_name does not exist, or path is an empty string.") );
else if( iretStat == ENOTDIR )
throw ( std::runtime_error("A component of the path is not a directory."));
else if( iretStat == ELOOP )
throw ( std::runtime_error("Too many symbolic links encountered while traversing the path."));
else if( iretStat == EACCES )
throw ( std::runtime_error("Permission denied."));
else if( iretStat == ENAMETOOLONG )
throw ( std::runtime_error("File can not be read\n"));
//Configure DOM parser
m_ConfigFileParser->setValidationScheme( XercesDOMParser::Val_Never );
m_ConfigFileParser->setDoNamespaces( false );
m_ConfigFileParser->setDoSchema( false );
m_ConfigFileParser->setLoadExternalDTD( false );
try
{
m_ConfigFileParser->parse( configFile.c_str() );
// no need to free this pointer - owned by the parent parser object
DOMDocument* xmlDoc = m_ConfigFileParser->getDocument();
// Get the top-level element.
DOMElement* elementRoot = xmlDoc->getDocumentElement();
if( !elementRoot ) throw(std::runtime_error( "empty XML document" ));
//Get the children of root node.
// Get size of the list so as to go through the list.
DOMNodeList* children = elementRoot->getChildNodes();
const XMLSize_t nodeCount = children->getLength();
//Go through the list of children till end.(Actually parses each row).
for( XMLSize_t xx = 0; xx < nodeCount; ++xx )
{
DOMNode* CurrentNode = children->item(xx);
//Get children of the current node(get fields of each row).
DOMNodeList* CurrentChildren = CurrentNode->getChildNodes();
const XMLSize_t childCount = CurrentChildren->getLength();
//Go through the list of fields of each row.
for(XMLSize_t yy = 0; yy < childCount; ++yy)
{
DOMNode* currentField = CurrentChildren->item(yy);
if( currentField->getNodeType() && // true is not NULL
currentField->getNodeType() == DOMNode::ELEMENT_NODE ) // is element
{
// Found node which is an Element. Re-cast node as element
DOMElement* currentElement
= dynamic_cast< xercesc::DOMElement* >( currentField );
//check the atrribute value 'name' and compare with required fields. If matches get the content by getTextContent()
// cout<<"inside the inner loop"<<endl;
const XMLCh* xmlch_name = currentElement->getTagName();
// =currentElement->getAttribute(XMLString::transcode("name"));
if(XMLString::equals(xmlch_name,ATTR_Block)&&flag==1)
{
const XMLCh* value = currentElement->getTextContent();
m_OptionA = XMLString::transcode(value);
// cout<<m_OptionA<<"\t";
location.push_back(atoi(m_OptionA));
}
if(XMLString::equals(xmlch_name,ATTR_Line)&&flag==1)
{
const XMLCh* value = currentElement->getTextContent();
m_OptionA = XMLString::transcode(value);
// cout<<m_OptionA<<"\t";
location.push_back(atoi(m_OptionA));
}
if(XMLString::equals(xmlch_name,ATTR_Word)&&flag==1)
{
const XMLCh* value = currentElement->getTextContent();
m_OptionA = XMLString::transcode(value);
// cout<<m_OptionA<<"\t";
location.push_back(atoi(m_OptionA));
}
if(XMLString::equals(xmlch_name,ATTR_rectLeft)&&flag==1)
{
const XMLCh* value = currentElement->getTextContent();
m_OptionA = XMLString::transcode(value);
// cout<<m_OptionA<<"\t";
bounds.push_back(atoi(m_OptionA));
}
if(XMLString::equals(xmlch_name,ATTR_rectRight)&&flag==1)
{
const XMLCh* value = currentElement->getTextContent();
m_OptionA = XMLString::transcode(value);
// cout<<m_OptionA<<"\t";
bounds.push_back(atoi(m_OptionA));
}
if(XMLString::equals(xmlch_name,ATTR_rectTop)&&flag==1)
{
const XMLCh* value = currentElement->getTextContent();
m_OptionA = XMLString::transcode(value);
// cout<<m_OptionA<<"\t";
bounds.push_back(atoi(m_OptionA));
}
if(XMLString::equals(xmlch_name,ATTR_rectBot)&&flag==1)
{
const XMLCh* value = currentElement->getTextContent();
m_OptionA = XMLString::transcode(value);
// cout<<m_OptionA<<endl;
bounds.push_back(atoi(m_OptionA));
}
if(XMLString::equals(xmlch_name,ATTR_BookCode))
{
const XMLCh* value = currentElement->getTextContent();
m_OptionA = XMLString::transcode(value);
bookCode = atoi(m_OptionA);
if(strcmp(m_OptionA,code)==0) flag=1;
else flag =0;
}
if(XMLString::equals(xmlch_name,ATTR_Text)&&flag==1)
{
const XMLCh* value = currentElement->getTextContent();
text = XMLString::transcode(value);
}
if(XMLString::equals(xmlch_name,ATTR_PageNo))
{
const XMLCh* value = currentElement->getTextContent();
m_OptionA = XMLString::transcode(value);
page = atoi(m_OptionA);
if(flag1==0){
// cout<<page<<endl;
pages.push_back(page);}
if(page==pageno) flag=1;
else flag = 0;
}
if(XMLString::equals(xmlch_name,ATTR_Location)&&flag==1)
{
const XMLCh* value = currentElement->getTextContent();
loc = XMLString::transcode(value);
}
}
}
}
}
catch( xercesc::XMLException& e )
{
char* message = xercesc::XMLString::transcode( e.getMessage() );
ostringstream errBuf;
errBuf << "Error parsing file: " << message << flush;
XMLString::release( &message );
}
}