You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xerces.apache.org by "Sharma, Gaurav" <Ga...@Safenet-inc.com> on 2011/05/23 09:22:52 UTC
Regarding xml declaration
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.
RE: Regarding xml declaration
Posted by "Sharma, Gaurav" <Ga...@Safenet-inc.com>.
Hi Alberto,
Could you please help me out and look into the issue?
Regards
Gaurav Sharma
________________________________
From: Sharma, Gaurav
Sent: Monday, May 23, 2011 1:30 PM
To: 'c-users@xerces.apache.org'
Subject: RE: Regarding xml declaration
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:Alberto.Massari@progress.com]
Sent: Monday, May 23, 2011 1:19 PM
To: c-users@xerces.apache.org
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.
Re: Regarding xml declaration
Posted by Alberto Massari <Al...@progress.com>.
If you use writeToString, the encoding will always be UTF-16, as the
XMLCh* buffer where the XML is serialized is defined as UTF-16, and the
encoding in the XML declaration must match the encoding of the raw bytes
where it is stored.
If you want to have a byte stream encoded in UTF-8 you have to use the
write() method, providing a MemBufFormatTarget as output storage.
Alberto
Il 23/05/2011 16:12, Sharma, Gaurav ha scritto:
> 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:Alberto.Massari@progress.com]
> Sent: Monday, May 23, 2011 6:35 PM
> To: c-users@xerces.apache.org
> 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:Alberto.Massari@progress.com]
>> Sent: Monday, May 23, 2011 1:19 PM
>> To: c-users@xerces.apache.org
>> 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.
>
>
> .
>
RE: Regarding xml declaration
Posted by "Sharma, Gaurav" <Ga...@Safenet-inc.com>.
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:Alberto.Massari@progress.com]
Sent: Monday, May 23, 2011 6:35 PM
To: c-users@xerces.apache.org
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:Alberto.Massari@progress.com]
> Sent: Monday, May 23, 2011 1:19 PM
> To: c-users@xerces.apache.org
> 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.
Re: Regarding xml declaration
Posted by Alberto Massari <Al...@progress.com>.
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:Alberto.Massari@progress.com]
> Sent: Monday, May 23, 2011 1:19 PM
> To: c-users@xerces.apache.org
> 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.
>
>
> .
>
RE: Regarding xml declaration
Posted by "Sharma, Gaurav" <Ga...@Safenet-inc.com>.
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:Alberto.Massari@progress.com]
Sent: Monday, May 23, 2011 1:19 PM
To: c-users@xerces.apache.org
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.
Re: Regarding xml declaration
Posted by Alberto Massari <Al...@progress.com>.
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.
>
>
>