On Wednesday 06 April 2011 01:05 PM, Vitaly Prapirny wrote:
Manish Yadav wrote:
hi
thanks for your reply. I searched for DOMLSSerializer class in the
Xerces-C++ and samples but nothing clear.

I don't know what is not clear enough so i can't provide more clear
information about this, sorry.

why can we just sinmple
Domserialization class?

I do know nothing about Domserialization class.

please help me and tell me how to do this ?


You can make your own serializer by traversing a DOM tree and saving
the data of every node to some file. Or you can try some more easy to
use library, e.g., http://www.codesynthesis.com/products/xsd/

Good luck!
    Vitaly
Hi  Thank You for reply and help,
sorry I'm bothering you again but you seems to be the person who can help me .Please help this novice fellow. Can You explain me the proper process how to use xsd ? How to do this in Xerces c++ coz i need it in c++? Here is my actual problem , I want to change a tag value in a xml file using xcerses c++ dom parser
my xml file is this

?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>fs.default.name</name>
<value> name</value>
</property>

</configuration>
I just want to change <value> name </value> to <value>next</value>
nobody in my mates or teachers know about xml parsing top of all there is no proper documentation which explain this process.
 so will You tell me how to do this using xcerces ?
i wrote a c++ code. when i run it on out put it shows paramater changed but when i saw the file on my disk there is no change .
so will you see the code and tell me what i'm doing wrong?
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"
#include <typeinfo>
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 )
{

       // 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 = doc->getDocumentElement();
const XMLCh* tag = xercesc::XMLString::transcode("property");
const XMLCh* tag1 = xercesc::XMLString::transcode("value");
const XMLCh* tag2 = xercesc::XMLString::transcode("name");
//DOMNodeList * list= doc->getElementbyTagName("tag");
//cout<<moot;

//DOMNode * rootElem = doc->getDocumentElement();


cout << "\nfirst";


 //DOMNode *root =  doc->getFirstChild() ;

cout << "\nsecond\n";
cout<< root<<"\n" ;

if ( root )
 {
cout<<"hi\n";
DOMElement* property = dynamic_cast<DOMElement*>( root->getElementsByTagName( tag )->item( 0) );

  if ( property )
 {
    cout<<"hello";
DOMElement* name = dynamic_cast<DOMElement*>( property->getElementsByTagName( tag2 )->item( 0 ) );

if ( name )
{
  cout<<"\nmanish\n";

DOMElement* value = dynamic_cast<DOMElement*>( property->getElementsByTagName( tag1 )->item( 0 ) );

    if ( value )
{
      cout<<XMLString::transcode(value->getTextContent());
       cout<<"\n";
      value->setTextContent( XMLString::transcode(" next") );
     // this will update the element named "value"
      cout<<XMLString::transcode(value->getTextContent());
       cout<<"\n";
    }
  }
}
}




}

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

       GetConfig appConfig;

   appConfig.readConfigFile(configFile);


       return 0;
    }

one more question most of the people say You cant change the xml file through c++ program or dom parser.Most of them say you have traverse the whole file and write back it to a new file reach the node where you need the change and write it to a new file. delete the old file and rename the new file . Is it true? if its true Then will you explain me how to do this ? why cant we change a xml file without writing to a new file ?Is there any way possible so that we can make changes in xml file without writing it to a new file ? if there is a way will you explain me how to do this ?

please help me with these doubts

Manish



Reply via email to