-1

hi everybody here is my problem I want to parsr a xml file,I just want to change an entity value like that

name to myname i write a code in c++ which is following

#include <string>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <list>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include "/usr/local/include/xercesc/parsers/SAXParser.hpp"
#include "/usr/local/include/xercesc/sax/HandlerBase.hpp"
#include "/usr/local/include/xercesc/util/XMLString.hpp"

using namespace std;
using namespace xercesc;

int main (int argc, char* args[]) {
    XMLPlatformUtils::Initialize();
    char* xmlFile = "/home/manish/conf/mapred-site.xml";
    cout<<xmlFile ;
    SAXParser* parser = new SAXParser();
    parser->setDoNamespaces(true);    // optional

    DocumentHandler* docHandler = new HandlerBase();
    ErrorHandler* errHandler = (ErrorHandler*) docHandler;
    parser->setDocumentHandler(docHandler);
    parser->setErrorHandler(errHandler);

    parser->parse(xmlFile);
    cout<<parser->getRootGrammar();


    delete parser;
    delete docHandler;
    return 0;
}

at my out put i just saw an address i dont know what to do now? how to use this address ? what iit is pointing toward? what should i do to change the parameter of xml file my xml file is following

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

i just want to change "name" to "myname" in this file

can anybody tell me how to do this?

Jerry Coffin
  • 476,176
  • 80
  • 629
  • 1,111
user513164
  • 1,788
  • 3
  • 20
  • 26

1 Answers1

0

If that's really all you want to do, why don't you just do a couple of searches and a string replacement: search for the "" tag using e.g. std::string::find. Then search for the position of the next "" and "" tag. Then you could e.g. use std::string::replace.

WRT the above code: as I outlined in my previous answer,you can't use SAX to modify the xml document. In fact in your code you are not even defining a handler for your specific xml document so how do you expect it to work? I suggest you sit down and try to understand the sax parser example in the examples.

Community
  • 1
  • 1
Ralf
  • 9,405
  • 2
  • 28
  • 46