You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Prashant Deshmukh <pv...@bsil.com> on 2003/04/08 15:21:12 UTC

Help! DOMDocument::setEndcoding function not working.

Hi,
I am using Xerces-DOM parser to bulid an XML document. The CreateDocument() function of DOMImplementation creates a document with encoding "UTF-16". What should I do to build the xml document in "UTF-8" format ?
I have tried functions DOMDocument::setEncoding(XMLCh* ) and DOMDocument::setActual Encoding(XMLCh* ) but this didn't solve my problem.
--------------------------------
My Operating System: Windows XP
IDE: MS Visual Studio 6.0
Xerces version.incl,v 1.12 2002/11/19 16:07:33
--------------------------------

I have tried following solutions(//1//, //2//, //3//) one by one but didn't work I am getting the same encoding "UTF-16" in response.xml file I am building.

Regards,
Prashant Deshmukh
BSIL -IN- MUM


Here is my Source Code
=================================================
DOMImplementation* impl;
DOMDocument* doc;
try

{
XMLPlatformUtils::Initialize();
impl =  DOMImplementationRegistry::getDOMImplementation(X("Core"));
}
catch(const XMLException& toCatch)
{
char *pMsg = XMLString::transcode(toCatch.getMessage());
cerr << "Error during Xerces-c Initialization.\n"
<< "  Exception message:"
<< pMsg;
XMLString::release(&pMsg);
return 0;
}

doc = impl->createDocument(0,X("Segment"),0);

const char * l_strEncoding ="UTF-8";
XMLCh* l_XMLEncode =XMLString::transcode(l_strEncoding );
//+++++++++++Consider one line of code at a time ++++++++//
//1// I HAVE TRIED THIS
doc->setActualEncoding(l_XMLEncode);

//2// AND I HAVE TRIED THIS
doc->setEncoding(l_XMLEncode);

//3// AND I HAVE ALSO TRIED THIS
doc->setEncoding(L"UTF-8 (LE)");
//++++++++++++++++++++++++++++++++++++++++++++++++++++//

DOMWriter *theSerializer = ((DOMImplementationLS*)impl)->createDOMWriter();
XMLCh* l_strXMLchars  = theSerializer->writeToString(*doc);
char* resVector = XMLString::transcode(l_strXMLchars);

FILE* fp;
fp = fopen("response.xml","w");
fwrite(resVector,sizeof(char),strlen(resVector),fp);
fclose(fp);
if(theSerializer != NULL)
{
delete theSerializer;
theSerializer = NULL;
}
if(myFormTarget != NULL)
{
delete myFormTarget;
myFormTarget = NULL;
}
doc->release();
XMLPlatformUtils::Terminate();

RE: Help! DOMDocument::setEndcoding function not working.

Posted by Prashant Deshmukh <pv...@bsil.com>.
Thanks PengYong,
You are right the DOMWriter::SetEncoding is for serializing and not for buillding document.
In my very first mail I have said that DOMImplementation::CreateDocument() method creats document with 
default encoding "UTF-16". 
Calling DOMDocument::setEncoding() afer that doesn't change the encoding. I have tried a couple of other solutions but nothing worked..:(
I hope u understand the problem and revert me back with a solution :)

Regards,
Prashant


-----Original Message-----
From: PeiYong Zhang [mailto:peiyongz_xml@ca.ibm.com]
Sent: Wednesday, April 09, 2003 1:56 AM
To: xerces-c-dev@xml.apache.org; pvd@bsil.com
Subject: Re: Help! DOMDocument::setEndcoding function not working.


> Actually I want to write the generated XML document to a string(char* ).
> which will be returned to the calling function and will be parsed further
for processing other things.

   You can plug a MemBufFormatTarget into DOMWriter and get the sting from
MemBufFormatTarget::getRawBuffer().

> I have tried with setting encoding with DOMWriter::SetEncoding function as
u have suggested but it didn't work:(.

     This DOMWriter::SetEncoding is meant for the encoding in which the
serialized result from DOMWriter, not
     for the DOM built.

Rgds,
PeiYong

----- Original Message -----
From: "Prashant Deshmukh" <pv...@bsil.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, April 08, 2003 11:32 AM
Subject: RE: Help! DOMDocument::setEndcoding function not working.


> Thanks David,
> Actually I want to write the generated XML document to a string(char* ).
> which will be returned to the calling function and will be parsed further
for processing other things.
> Let me know if it makes any differance while parsing for encoding UTF-8
and UTF-16 ?
> This doubt came to my mind because my browser MS Internet Explorer(version
6.02) does not support UTF-16 encoding.
> -------------
> I have tried with setting encoding with DOMWriter::SetEncoding function as
u have suggested but it didn't work:(.
>
> Regards,
> Prashant
>
> -----Original Message-----
> From: David J Craigon [mailto:david-xercescdev@arabidopsis.info]
> Sent: Tuesday, April 08, 2003 7:45 PM
> To: xerces-c-dev@xml.apache.org
> Subject: Re: Help! DOMDocument::setEndcoding function not working.
>
>
> (an non-expert writes...)
>
> The important distinction here I think is between the encoding used to
> serialize (i.e. make the document into a text file), and the encoding
> used internally by Xerces. The encoding used internally by Xerces if
> UTF-16, and you're stuck with it -like it or lump it. The encoding you
> write to is set using a method of the DOMWriter
> (DOMWriter::SetEncoding). This is where you want to set UTF-8. According
> to the documentation, though this should be the default, so this should
> not be necessary.
>
> I notice in your code snippet you're attempting to use FILE * to output
> your DOM.  If you really just want to output to a file, construct a
> LocalFileFormatTarget, and pass that to DOMWriter::writeNode.
>
> Given all this, I'm not sure what setEncoding and setActualEncoding are
> supposed to do. Anyone?
>
> *Caution- this message was written by a known fool, and thereby may be
> compete rubbish from start to finish*
>
> David
>
> Prashant Deshmukh wrote:
>
> > Hi,
> > I am using Xerces-DOM parser to bulid an XML document. The
> > CreateDocument() function of DOMImplementation creates a document with
> > encoding "UTF-16". What should I do to build the xml document in
> > "UTF-8" format ?
> > I have tried functions DOMDocument::setEncoding(XMLCh* ) and
> > DOMDocument::setActual Encoding(XMLCh* ) but this didn't solve my
problem.
> > --------------------------------
> > My Operating System: Windows XP
> > IDE: MS Visual Studio 6.0
> > Xerces version.incl,v 1.12 2002/11/19 16:07:33
> > --------------------------------
> >
> > I have tried following solutions(//1//, //2//, //3//) one by one but
> > didn't work I am getting the same encoding "UTF-16" in response.xml
> > file I am building.
> >
> > *Regards,
> > Prashant Deshmukh*
> > *BSIL -IN- MUM*
> >
> >
> > Here is my Source Code
> > =================================================
> > DOMImplementation* impl;
> > DOMDocument* doc;
> > try
> >
> > {
> > XMLPlatformUtils::Initialize();
> > impl =  DOMImplementationRegistry::getDOMImplementation(X("Core"));
> > }
> > catch(const XMLException& toCatch)
> > {
> > char *pMsg = XMLString::transcode(toCatch.getMessage());
> > cerr << "Error during Xerces-c Initialization.\n"
> > << "  Exception message:"
> > << pMsg;
> > XMLString::release(&pMsg);
> > return 0;
> > }
> >
> > doc = impl->createDocument(0,X("Segment"),0);
> >
> > const char * l_strEncoding ="UTF-8";
> > XMLCh* l_XMLEncode =XMLString::transcode(l_strEncoding );
> > //+++++++++++Consider one line of code at a time ++++++++//
> > //1// I HAVE TRIED THIS
> > doc->setActualEncoding(l_XMLEncode);
> >
> > //2// AND I HAVE TRIED THIS
> > doc->setEncoding(l_XMLEncode);
> >
> > //3// AND I HAVE ALSO TRIED THIS
> > doc->setEncoding(L"UTF-8 (LE)");
> > //++++++++++++++++++++++++++++++++++++++++++++++++++++//
> >
> > DOMWriter *theSerializer =
> > ((DOMImplementationLS*)impl)->createDOMWriter();
> > XMLCh* l_strXMLchars  = theSerializer->writeToString(*doc);
> > char* resVector = XMLString::transcode(l_strXMLchars);
> >
> > FILE* fp;
> > fp = fopen("response.xml","w");
> > fwrite(resVector,sizeof(char),strlen(resVector),fp);
> > fclose(fp);
> > if(theSerializer != NULL)
> > {
> > delete theSerializer;
> > theSerializer = NULL;
> > }
> > if(myFormTarget != NULL)
> > {
> > delete myFormTarget;
> > myFormTarget = NULL;
> > }
> > doc->release();
> > XMLPlatformUtils::Terminate();
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org

Re: Help! DOMDocument::setEndcoding function not working.

Posted by PeiYong Zhang <pe...@ca.ibm.com>.
> Actually I want to write the generated XML document to a string(char* ).
> which will be returned to the calling function and will be parsed further
for processing other things.

   You can plug a MemBufFormatTarget into DOMWriter and get the sting from
MemBufFormatTarget::getRawBuffer().

> I have tried with setting encoding with DOMWriter::SetEncoding function as
u have suggested but it didn't work:(.

     This DOMWriter::SetEncoding is meant for the encoding in which the
serialized result from DOMWriter, not
     for the DOM built.

Rgds,
PeiYong

----- Original Message -----
From: "Prashant Deshmukh" <pv...@bsil.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, April 08, 2003 11:32 AM
Subject: RE: Help! DOMDocument::setEndcoding function not working.


> Thanks David,
> Actually I want to write the generated XML document to a string(char* ).
> which will be returned to the calling function and will be parsed further
for processing other things.
> Let me know if it makes any differance while parsing for encoding UTF-8
and UTF-16 ?
> This doubt came to my mind because my browser MS Internet Explorer(version
6.02) does not support UTF-16 encoding.
> -------------
> I have tried with setting encoding with DOMWriter::SetEncoding function as
u have suggested but it didn't work:(.
>
> Regards,
> Prashant
>
> -----Original Message-----
> From: David J Craigon [mailto:david-xercescdev@arabidopsis.info]
> Sent: Tuesday, April 08, 2003 7:45 PM
> To: xerces-c-dev@xml.apache.org
> Subject: Re: Help! DOMDocument::setEndcoding function not working.
>
>
> (an non-expert writes...)
>
> The important distinction here I think is between the encoding used to
> serialize (i.e. make the document into a text file), and the encoding
> used internally by Xerces. The encoding used internally by Xerces if
> UTF-16, and you're stuck with it -like it or lump it. The encoding you
> write to is set using a method of the DOMWriter
> (DOMWriter::SetEncoding). This is where you want to set UTF-8. According
> to the documentation, though this should be the default, so this should
> not be necessary.
>
> I notice in your code snippet you're attempting to use FILE * to output
> your DOM.  If you really just want to output to a file, construct a
> LocalFileFormatTarget, and pass that to DOMWriter::writeNode.
>
> Given all this, I'm not sure what setEncoding and setActualEncoding are
> supposed to do. Anyone?
>
> *Caution- this message was written by a known fool, and thereby may be
> compete rubbish from start to finish*
>
> David
>
> Prashant Deshmukh wrote:
>
> > Hi,
> > I am using Xerces-DOM parser to bulid an XML document. The
> > CreateDocument() function of DOMImplementation creates a document with
> > encoding "UTF-16". What should I do to build the xml document in
> > "UTF-8" format ?
> > I have tried functions DOMDocument::setEncoding(XMLCh* ) and
> > DOMDocument::setActual Encoding(XMLCh* ) but this didn't solve my
problem.
> > --------------------------------
> > My Operating System: Windows XP
> > IDE: MS Visual Studio 6.0
> > Xerces version.incl,v 1.12 2002/11/19 16:07:33
> > --------------------------------
> >
> > I have tried following solutions(//1//, //2//, //3//) one by one but
> > didn't work I am getting the same encoding "UTF-16" in response.xml
> > file I am building.
> >
> > *Regards,
> > Prashant Deshmukh*
> > *BSIL -IN- MUM*
> >
> >
> > Here is my Source Code
> > =================================================
> > DOMImplementation* impl;
> > DOMDocument* doc;
> > try
> >
> > {
> > XMLPlatformUtils::Initialize();
> > impl =  DOMImplementationRegistry::getDOMImplementation(X("Core"));
> > }
> > catch(const XMLException& toCatch)
> > {
> > char *pMsg = XMLString::transcode(toCatch.getMessage());
> > cerr << "Error during Xerces-c Initialization.\n"
> > << "  Exception message:"
> > << pMsg;
> > XMLString::release(&pMsg);
> > return 0;
> > }
> >
> > doc = impl->createDocument(0,X("Segment"),0);
> >
> > const char * l_strEncoding ="UTF-8";
> > XMLCh* l_XMLEncode =XMLString::transcode(l_strEncoding );
> > //+++++++++++Consider one line of code at a time ++++++++//
> > //1// I HAVE TRIED THIS
> > doc->setActualEncoding(l_XMLEncode);
> >
> > //2// AND I HAVE TRIED THIS
> > doc->setEncoding(l_XMLEncode);
> >
> > //3// AND I HAVE ALSO TRIED THIS
> > doc->setEncoding(L"UTF-8 (LE)");
> > //++++++++++++++++++++++++++++++++++++++++++++++++++++//
> >
> > DOMWriter *theSerializer =
> > ((DOMImplementationLS*)impl)->createDOMWriter();
> > XMLCh* l_strXMLchars  = theSerializer->writeToString(*doc);
> > char* resVector = XMLString::transcode(l_strXMLchars);
> >
> > FILE* fp;
> > fp = fopen("response.xml","w");
> > fwrite(resVector,sizeof(char),strlen(resVector),fp);
> > fclose(fp);
> > if(theSerializer != NULL)
> > {
> > delete theSerializer;
> > theSerializer = NULL;
> > }
> > if(myFormTarget != NULL)
> > {
> > delete myFormTarget;
> > myFormTarget = NULL;
> > }
> > doc->release();
> > XMLPlatformUtils::Terminate();
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


Re: Help! DOMDocument::setEndcoding function not working.

Posted by PeiYong Zhang <pe...@ca.ibm.com>.
Prashant,

     Assuming u wanna do this: Create a DOM tree using the  DOM interface,
and then return a string form of this DOM tree.

     . Create the DOM tree first, need **not** care what encoding used in
the DOM tree
     . plug a MemBufFormatTarget to the DOMWriter and do
DOMWriter::setEncoding('utf-16')
     . invoke getRawBuffer() on the MemBufFormatTarget to get a XMLByte
stream of the
       xml document which is in the encoding 'utf-16'.

     To verify, plug a LocalFileFormatTarget instead, and threw the result
file to IE.

Rgds,
PeiYong


----- Original Message -----
From: "Prashant Deshmukh" <pv...@bsil.com>
To: <xe...@xml.apache.org>
Sent: Tuesday, April 08, 2003 11:32 AM
Subject: RE: Help! DOMDocument::setEndcoding function not working.


> Thanks David,
> Actually I want to write the generated XML document to a string(char* ).
> which will be returned to the calling function and will be parsed further
for processing other things.
> Let me know if it makes any differance while parsing for encoding UTF-8
and UTF-16 ?
> This doubt came to my mind because my browser MS Internet Explorer(version
6.02) does not support UTF-16 encoding.
> -------------
> I have tried with setting encoding with DOMWriter::SetEncoding function as
u have suggested but it didn't work:(.
>
> Regards,
> Prashant
>
> -----Original Message-----
> From: David J Craigon [mailto:david-xercescdev@arabidopsis.info]
> Sent: Tuesday, April 08, 2003 7:45 PM
> To: xerces-c-dev@xml.apache.org
> Subject: Re: Help! DOMDocument::setEndcoding function not working.
>
>
> (an non-expert writes...)
>
> The important distinction here I think is between the encoding used to
> serialize (i.e. make the document into a text file), and the encoding
> used internally by Xerces. The encoding used internally by Xerces if
> UTF-16, and you're stuck with it -like it or lump it. The encoding you
> write to is set using a method of the DOMWriter
> (DOMWriter::SetEncoding). This is where you want to set UTF-8. According
> to the documentation, though this should be the default, so this should
> not be necessary.
>
> I notice in your code snippet you're attempting to use FILE * to output
> your DOM.  If you really just want to output to a file, construct a
> LocalFileFormatTarget, and pass that to DOMWriter::writeNode.
>
> Given all this, I'm not sure what setEncoding and setActualEncoding are
> supposed to do. Anyone?
>
> *Caution- this message was written by a known fool, and thereby may be
> compete rubbish from start to finish*
>
> David
>
> Prashant Deshmukh wrote:
>
> > Hi,
> > I am using Xerces-DOM parser to bulid an XML document. The
> > CreateDocument() function of DOMImplementation creates a document with
> > encoding "UTF-16". What should I do to build the xml document in
> > "UTF-8" format ?
> > I have tried functions DOMDocument::setEncoding(XMLCh* ) and
> > DOMDocument::setActual Encoding(XMLCh* ) but this didn't solve my
problem.
> > --------------------------------
> > My Operating System: Windows XP
> > IDE: MS Visual Studio 6.0
> > Xerces version.incl,v 1.12 2002/11/19 16:07:33
> > --------------------------------
> >
> > I have tried following solutions(//1//, //2//, //3//) one by one but
> > didn't work I am getting the same encoding "UTF-16" in response.xml
> > file I am building.
> >
> > *Regards,
> > Prashant Deshmukh*
> > *BSIL -IN- MUM*
> >
> >
> > Here is my Source Code
> > =================================================
> > DOMImplementation* impl;
> > DOMDocument* doc;
> > try
> >
> > {
> > XMLPlatformUtils::Initialize();
> > impl =  DOMImplementationRegistry::getDOMImplementation(X("Core"));
> > }
> > catch(const XMLException& toCatch)
> > {
> > char *pMsg = XMLString::transcode(toCatch.getMessage());
> > cerr << "Error during Xerces-c Initialization.\n"
> > << "  Exception message:"
> > << pMsg;
> > XMLString::release(&pMsg);
> > return 0;
> > }
> >
> > doc = impl->createDocument(0,X("Segment"),0);
> >
> > const char * l_strEncoding ="UTF-8";
> > XMLCh* l_XMLEncode =XMLString::transcode(l_strEncoding );
> > //+++++++++++Consider one line of code at a time ++++++++//
> > //1// I HAVE TRIED THIS
> > doc->setActualEncoding(l_XMLEncode);
> >
> > //2// AND I HAVE TRIED THIS
> > doc->setEncoding(l_XMLEncode);
> >
> > //3// AND I HAVE ALSO TRIED THIS
> > doc->setEncoding(L"UTF-8 (LE)");
> > //++++++++++++++++++++++++++++++++++++++++++++++++++++//
> >
> > DOMWriter *theSerializer =
> > ((DOMImplementationLS*)impl)->createDOMWriter();
> > XMLCh* l_strXMLchars  = theSerializer->writeToString(*doc);
> > char* resVector = XMLString::transcode(l_strXMLchars);
> >
> > FILE* fp;
> > fp = fopen("response.xml","w");
> > fwrite(resVector,sizeof(char),strlen(resVector),fp);
> > fclose(fp);
> > if(theSerializer != NULL)
> > {
> > delete theSerializer;
> > theSerializer = NULL;
> > }
> > if(myFormTarget != NULL)
> > {
> > delete myFormTarget;
> > myFormTarget = NULL;
> > }
> > doc->release();
> > XMLPlatformUtils::Terminate();
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


RE: Help! DOMDocument::setEndcoding function not working.

Posted by Prashant Deshmukh <pv...@bsil.com>.
Thanks David,
Actually I want to write the generated XML document to a string(char* ).
which will be returned to the calling function and will be parsed further for processing other things.
Let me know if it makes any differance while parsing for encoding UTF-8 and UTF-16 ?
This doubt came to my mind because my browser MS Internet Explorer(version 6.02) does not support UTF-16 encoding.
-------------
	I have tried with setting encoding with DOMWriter::SetEncoding function as u have suggested but it didn't work:(.

Regards,
Prashant

-----Original Message-----
From: David J Craigon [mailto:david-xercescdev@arabidopsis.info]
Sent: Tuesday, April 08, 2003 7:45 PM
To: xerces-c-dev@xml.apache.org
Subject: Re: Help! DOMDocument::setEndcoding function not working.


(an non-expert writes...)

The important distinction here I think is between the encoding used to
serialize (i.e. make the document into a text file), and the encoding
used internally by Xerces. The encoding used internally by Xerces if
UTF-16, and you're stuck with it -like it or lump it. The encoding you
write to is set using a method of the DOMWriter
(DOMWriter::SetEncoding). This is where you want to set UTF-8. According
to the documentation, though this should be the default, so this should
not be necessary.

I notice in your code snippet you're attempting to use FILE * to output
your DOM.  If you really just want to output to a file, construct a
LocalFileFormatTarget, and pass that to DOMWriter::writeNode.

Given all this, I'm not sure what setEncoding and setActualEncoding are
supposed to do. Anyone?

*Caution- this message was written by a known fool, and thereby may be
compete rubbish from start to finish*

David

Prashant Deshmukh wrote:

> Hi,
> I am using Xerces-DOM parser to bulid an XML document. The 
> CreateDocument() function of DOMImplementation creates a document with 
> encoding "UTF-16". What should I do to build the xml document in 
> "UTF-8" format ?
> I have tried functions DOMDocument::setEncoding(XMLCh* ) and 
> DOMDocument::setActual Encoding(XMLCh* ) but this didn't solve my problem.
> --------------------------------
> My Operating System: Windows XP
> IDE: MS Visual Studio 6.0
> Xerces version.incl,v 1.12 2002/11/19 16:07:33
> --------------------------------
>  
> I have tried following solutions(//1//, //2//, //3//) one by one but 
> didn't work I am getting the same encoding "UTF-16" in response.xml 
> file I am building.
>  
> *Regards,
> Prashant Deshmukh*
> *BSIL -IN- MUM*
>  
>
> Here is my Source Code
> =================================================
> DOMImplementation* impl;
> DOMDocument* doc;
> try
>  
> {
> XMLPlatformUtils::Initialize();
> impl =  DOMImplementationRegistry::getDOMImplementation(X("Core"));
> }
> catch(const XMLException& toCatch)
> {
> char *pMsg = XMLString::transcode(toCatch.getMessage());
> cerr << "Error during Xerces-c Initialization.\n"
> << "  Exception message:"
> << pMsg;
> XMLString::release(&pMsg);
> return 0;
> }
>  
> doc = impl->createDocument(0,X("Segment"),0);
>  
> const char * l_strEncoding ="UTF-8";
> XMLCh* l_XMLEncode =XMLString::transcode(l_strEncoding );
> //+++++++++++Consider one line of code at a time ++++++++//
> //1// I HAVE TRIED THIS
> doc->setActualEncoding(l_XMLEncode);
>  
> //2// AND I HAVE TRIED THIS
> doc->setEncoding(l_XMLEncode);
>  
> //3// AND I HAVE ALSO TRIED THIS
> doc->setEncoding(L"UTF-8 (LE)");
> //++++++++++++++++++++++++++++++++++++++++++++++++++++//
>  
> DOMWriter *theSerializer = 
> ((DOMImplementationLS*)impl)->createDOMWriter();
> XMLCh* l_strXMLchars  = theSerializer->writeToString(*doc);
> char* resVector = XMLString::transcode(l_strXMLchars);
>  
> FILE* fp;
> fp = fopen("response.xml","w");
> fwrite(resVector,sizeof(char),strlen(resVector),fp);
> fclose(fp);
> if(theSerializer != NULL)
> {
> delete theSerializer;
> theSerializer = NULL;
> }
> if(myFormTarget != NULL)
> {
> delete myFormTarget;
> myFormTarget = NULL;
> }
> doc->release();
> XMLPlatformUtils::Terminate();





---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org

Re: Help! DOMDocument::setEndcoding function not working.

Posted by David J Craigon <da...@arabidopsis.info>.
(an non-expert writes...)

The important distinction here I think is between the encoding used to
serialize (i.e. make the document into a text file), and the encoding
used internally by Xerces. The encoding used internally by Xerces if
UTF-16, and you're stuck with it -like it or lump it. The encoding you
write to is set using a method of the DOMWriter
(DOMWriter::SetEncoding). This is where you want to set UTF-8. According
to the documentation, though this should be the default, so this should
not be necessary.

I notice in your code snippet you're attempting to use FILE * to output
your DOM.  If you really just want to output to a file, construct a
LocalFileFormatTarget, and pass that to DOMWriter::writeNode.

Given all this, I'm not sure what setEncoding and setActualEncoding are
supposed to do. Anyone?

*Caution- this message was written by a known fool, and thereby may be
compete rubbish from start to finish*

David

Prashant Deshmukh wrote:

> Hi,
> I am using Xerces-DOM parser to bulid an XML document. The 
> CreateDocument() function of DOMImplementation creates a document with 
> encoding "UTF-16". What should I do to build the xml document in 
> "UTF-8" format ?
> I have tried functions DOMDocument::setEncoding(XMLCh* ) and 
> DOMDocument::setActual Encoding(XMLCh* ) but this didn't solve my problem.
> --------------------------------
> My Operating System: Windows XP
> IDE: MS Visual Studio 6.0
> Xerces version.incl,v 1.12 2002/11/19 16:07:33
> --------------------------------
>  
> I have tried following solutions(//1//, //2//, //3//) one by one but 
> didn't work I am getting the same encoding "UTF-16" in response.xml 
> file I am building.
>  
> *Regards,
> Prashant Deshmukh*
> *BSIL -IN- MUM*
>  
>
> Here is my Source Code
> =================================================
> DOMImplementation* impl;
> DOMDocument* doc;
> try
>  
> {
> XMLPlatformUtils::Initialize();
> impl =  DOMImplementationRegistry::getDOMImplementation(X("Core"));
> }
> catch(const XMLException& toCatch)
> {
> char *pMsg = XMLString::transcode(toCatch.getMessage());
> cerr << "Error during Xerces-c Initialization.\n"
> << "  Exception message:"
> << pMsg;
> XMLString::release(&pMsg);
> return 0;
> }
>  
> doc = impl->createDocument(0,X("Segment"),0);
>  
> const char * l_strEncoding ="UTF-8";
> XMLCh* l_XMLEncode =XMLString::transcode(l_strEncoding );
> //+++++++++++Consider one line of code at a time ++++++++//
> //1// I HAVE TRIED THIS
> doc->setActualEncoding(l_XMLEncode);
>  
> //2// AND I HAVE TRIED THIS
> doc->setEncoding(l_XMLEncode);
>  
> //3// AND I HAVE ALSO TRIED THIS
> doc->setEncoding(L"UTF-8 (LE)");
> //++++++++++++++++++++++++++++++++++++++++++++++++++++//
>  
> DOMWriter *theSerializer = 
> ((DOMImplementationLS*)impl)->createDOMWriter();
> XMLCh* l_strXMLchars  = theSerializer->writeToString(*doc);
> char* resVector = XMLString::transcode(l_strXMLchars);
>  
> FILE* fp;
> fp = fopen("response.xml","w");
> fwrite(resVector,sizeof(char),strlen(resVector),fp);
> fclose(fp);
> if(theSerializer != NULL)
> {
> delete theSerializer;
> theSerializer = NULL;
> }
> if(myFormTarget != NULL)
> {
> delete myFormTarget;
> myFormTarget = NULL;
> }
> doc->release();
> XMLPlatformUtils::Terminate();





---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org