c++ XML file parsing problem

hi everybody
i want to parse an XML file with xerces Dom parser but could not succeed here is code for my xml file which i have to change
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
<name>fs.default.name</name>
<value> name</value>
</property>

</configuration>

all i want to change the <value> name </value> to <value>next></value>
in the file how to do this?
i wrote a c++ dom parser code also but can't change the parameter my c++ code is following:


#include<string.h>
#include<iostream>
#include<sstream>
#include<sys/types.h>
#include<unistd.h>
#include<errno.h>
#include<sys/stat.h>
#include "parser1.hpp"
using namespace xercesc ;
using namespace std;

GetConfig::GetConfig()
{
XMLPlatformUtils::Initialize();
TAG_configuration =XMLString::transcode("configuration");
TAG_property = XMLString::transcode("property");
TAG_name=XMLString::transcode("name");
TAG_value=XMLString::transcode("value");
m_ConfigFileParser=new XercesDOMParser;
}
GetConfig::~GetConfig()
{
delete m_ConfigFileParser;

XMLString::release( &TAG_configuration );
XMLString::release( &TAG_property );
//XMLString::release( &TAG_value );
//XMLString::release( &TAG_name );
XMLPlatformUtils::Terminate();
}
void GetConfig :: readConfigFile(string& configFile)
throw( std::runtime_error )
{
/*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 );

m_ConfigFileParser->parse( configFile.c_str() );
DOMDocument* doc = m_ConfigFileParser->getDocument();
DOMElement* root = dynamic_cast<DOMElement*>( doc->getFirstChild() );

if ( root ) {
cout<<"hi";
DOMElement* property = dynamic_cast<DOMElement*>( root->getElementsByTagName(XMLString::transcode( "property")));
if ( property )
{
DOMElement* value = dynamic_cast<DOMElement*>( property->getElementsByTagName(XMLString::transcode("value")) );
if ( value )
{ cout<<XMLString::transcode(value->getTextContent());
value->setTextContent( XMLString::transcode(" next") ); // this will update the element named "value"
}
}
}


//DOMDocument* xmlDoc = m_ConfigFileParser->getDocument();
//DOMElement* elementRoot = xmlDoc->getDocumentElement();

//DOMNodeList* children = elementRoot->getChildNodes();

}

int main()
{
string configFile="/home/manish.yadav/Desktop/sel.xml";

GetConfig appConfig;

appConfig.readConfigFile(configFile);


return 0;
}

But the code not working can any body tell me what i'm doing wrong ?
can anybody tell me how to change the xml file using Xerces ?
Last edited on
Topic archived. No new replies allowed.