Hi Alberto,
Thanks a lot,
I checked my code and somehow instead of DOMDocument, DOMElement was coming in.
After correcting it everything workfine.
Still one issue I am facing that I am not able to print encoding value as
utf-8. By defult its printing UTF-16.
I searched on net and found one of your mail chains and used the code from
there to set the encoding type as follows:
I just added these lines to my write_dom function
xercesc::DOMLSOutput* theOutput =
((xercesc::DOMImplementationLS*)impl)->createLSOutput();
theOutput->setEncoding(tag_names_obj->VALUE_UTF8);
void write_dom(xercesc::DOMDocument* doc,
XMLCh** out_string)
{
xercesc::DOMImplementation *impl =
xercesc::DOMImplementationRegistry::getDOMImplementation(XMLString
::transcode("LS"));
xercesc::DOMLSSerializer *writer =
static_cast<xercesc::DOMImplementationLS*>(impl)->createLSSerializer();
xercesc::DOMLSOutput* theOutput =
((xercesc::DOMImplementationLS*)impl)->createLSOutput();
theOutput->setEncoding(XMLString::transcode("UTF-8"));
writer->getDomConfig()->setParameter(XMLString::transcode("format-pretty-print"),
true);
if
(writer->getDomConfig()->canSetParameter(xercesc::XMLUni::fgDOMXMLDeclaration,
true))
{
writer->getDomConfig()->setParameter(xercesc::XMLUni::fgDOMXMLDeclaration,true);
}
if (out_string != NULL)
{
*out_string = writer->writeToString(doc);
}
writer->release();
}
But somehow it is still prining the same UTF-16 value for encoding type in xml
declaraion.
Could you give me some insight into it as well.
Thanks and Regards
Gaurav Sharma
-----Original Message-----
From: Alberto Massari [mailto:[email protected]]
Sent: Monday, May 23, 2011 6:35 PM
To: [email protected]
Subject: Re: Regarding xml declaration
Hi,
I have tried your code and it works as expected... are you sure you are
using that helper method, instead of serializing just the root element?
e.g. maybe you also have a write_dom(const xerces::DOMElement* elt)
method, that you are invoking as write_dom(doc->getDocumentElement())
Alberto
Il 23/05/2011 09:59, Sharma, Gaurav ha scritto:
> Hi Alberto,
>
>
>
> Below is the code that create and write the dom tree to the file.
>
>
>
> //creation
>
> xercesc::DOMImplementation* impl =
> xercesc::DOMImplementationRegistry::getDOMImplementation("core") ;
>
> xercesc::DOMDocument *doc = impl->createDocument(0, "root", 0);
>
> doc->setXmlVersion(XMLString::transcode("1.0"));
>
>
>
>
>
> //writing to a file
>
> void ClgnDomHelper::write_dom(const xercesc::DOMDocument* doc,
>
> const oef_char_t* out_file_name)
>
> {
>
>
>
> xercesc::DOMImplementation *impl =
> xercesc::DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));
>
> xercesc::DOMLSSerializer *writer =
> static_cast<xercesc::DOMImplementationLS*>(impl)->createLSSerializer();
>
>
> writer->getDomConfig()->setParameter(XMLString::transcode("format-pretty-print"),
> true);
>
> if
> (writer->getDomConfig()->canSetParameter(xercesc::XMLUni::fgDOMXMLDeclaration,
> true))
>
> {
>
>
> writer->getDomConfig()->setParameter(xercesc::XMLUni::fgDOMXMLDeclaration,true);
>
> }
>
>
>
> if (out_file_name != NULL)
>
> {
>
> xercesc::DOMLSOutput *output =
> static_cast<xercesc::DOMImplementationLS*>(impl)->createLSOutput();
>
> xercesc::LocalFileFormatTarget my_form_target(out_file_name);
>
> output->setByteStream(&my_form_target);
>
> writer->write(doc, output);
>
> output->release();
>
> }
>
> writer->release();
>
> }
>
>
>
> Regards
>
> Gaurav Sharma
>
>
>
> -----Original Message-----
> From: Alberto Massari [mailto:[email protected]]
> Sent: Monday, May 23, 2011 1:19 PM
> To: [email protected]
> Subject: Re: Regarding xml declaration
>
>
>
> The XML declaration string is added when serializing the document; can
>
> you tell us how you are doing it?
>
>
>
> Alberto
>
>
>
> Il 23/05/2011 09:22, Sharma, Gaurav ha scritto:
>
>> Hi All,
>> Can anyone of you please tell me that how to specify the xml declaration in
>> the output xml document. I create document using
>> xercesc::DOMImplementation* impl =
>> xercesc::DOMImplementationRegistry::getDOMImplementation("core") ;
>> xercesc::DOMDocument *doc = impl->createDocument(0, "root", 0);
>> But the xml declaration string "<?xml version="1.0" encoding="utf-8"?>"
>> doesn't appear at the top.
>> Please help!
>> Thanks and Regards
>> Gaurav Sharma
>> The information contained in this electronic mail transmission
>> may be privileged and confidential, and therefore, protected
>> from disclosure. If you have received this communication in
>> error, please notify us immediately by replying to this
>> message and deleting it from your computer without copying
>> or disclosing it.
>
>
>
>
> The information contained in this electronic mail transmission
> may be privileged and confidential, and therefore, protected
> from disclosure. If you have received this communication in
> error, please notify us immediately by replying to this
> message and deleting it from your computer without copying
> or disclosing it.
>
>
> .
>
The information contained in this electronic mail transmission
may be privileged and confidential, and therefore, protected
from disclosure. If you have received this communication in
error, please notify us immediately by replying to this
message and deleting it from your computer without copying
or disclosing it.