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 neerav patel <ne...@gmail.com> on 2007/12/12 01:44:37 UTC
Writing XML to File
Hi,
I am new at Xerces and I am developing code in Visual C++ .NET 7.1, not
managed code, just regular C++.
I have managed to write an application that takes the sample
CreateDOMDocument and I want to save that to a file now. I tried looking at
DOMPrint example but nothing is making sense. Can someone give me some
sample code to take an XML file in memory and write to a file.
Thanks in advance.
Re: Writing XML to File
Posted by Justin Dearing <zi...@gmail.com>.
Why not place the xml in a string and cout or printf() it?
On Dec 11, 2007 7:44 PM, neerav patel <ne...@gmail.com> wrote:
> Hi,
>
> I am new at Xerces and I am developing code in Visual C++ .NET 7.1, not
> managed code, just regular C++.
>
> I have managed to write an application that takes the sample
> CreateDOMDocument and I want to save that to a file now. I tried looking at
> DOMPrint example but nothing is making sense. Can someone give me some
> sample code to take an XML file in memory and write to a file.
>
> Thanks in advance.
>
Re: Writing XML to File
Posted by Alberto Massari <am...@datadirect.com>.
Jesse Pelton wrote:
> I think
> theSerializer->writeNode(&outputfile, *doc);
> should be
> theSerializer->writeNode(&file, *doc);
>
> Also, note that "outputfile" is a string holding the name of the file to
> be written.
>
That's what happen when you type inside an e-mail client without
compiling the code...
Thanks Jesse for the correction
Alberto
> -----Original Message-----
> From: Alberto Massari [mailto:amassari@datadirect.com]
> Sent: Wednesday, December 12, 2007 2:23 AM
> To: c-users@xerces.apache.org
> Subject: Re: Writing XML to File
>
> neerav patel wrote:
>
>> Hi,
>>
>> I am new at Xerces and I am developing code in Visual C++ .NET 7.1,
>>
> not
>
>> managed code, just regular C++.
>>
>> I have managed to write an application that takes the sample
>> CreateDOMDocument and I want to save that to a file now. I tried
>>
> looking at
>
>> DOMPrint example but nothing is making sense. Can someone give me
>>
> some
>
>> sample code to take an XML file in memory and write to a file.
>>
>>
>>
> This is the minimum amount of code you need:
>
> DOMImplementation *impl =
> DOMImplementationRegistry::getDOMImplementation(L"LS");
> DOMWriter *theSerializer =
> ((DOMImplementationLS*)impl)->createDOMWriter();
> LocalFileFormatTarget file(outputfile);
> theSerializer->writeNode(&outputfile, *doc);
> theSerializer->release();
>
> Common options that you may want to specify are a specific encoding
> (theSerializer->setEncoding(L"ISO-8859-1")) ), and whether the file
> should be indented
> (theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true) ).
>
> Alberto
>
>
>
>
>
RE: Writing XML to File
Posted by Jesse Pelton <js...@PKC.com>.
I think
theSerializer->writeNode(&outputfile, *doc);
should be
theSerializer->writeNode(&file, *doc);
Also, note that "outputfile" is a string holding the name of the file to
be written.
-----Original Message-----
From: Alberto Massari [mailto:amassari@datadirect.com]
Sent: Wednesday, December 12, 2007 2:23 AM
To: c-users@xerces.apache.org
Subject: Re: Writing XML to File
neerav patel wrote:
> Hi,
>
> I am new at Xerces and I am developing code in Visual C++ .NET 7.1,
not
> managed code, just regular C++.
>
> I have managed to write an application that takes the sample
> CreateDOMDocument and I want to save that to a file now. I tried
looking at
> DOMPrint example but nothing is making sense. Can someone give me
some
> sample code to take an XML file in memory and write to a file.
>
>
This is the minimum amount of code you need:
DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(L"LS");
DOMWriter *theSerializer =
((DOMImplementationLS*)impl)->createDOMWriter();
LocalFileFormatTarget file(outputfile);
theSerializer->writeNode(&outputfile, *doc);
theSerializer->release();
Common options that you may want to specify are a specific encoding
(theSerializer->setEncoding(L"ISO-8859-1")) ), and whether the file
should be indented
(theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true) ).
Alberto
Re: Writing XML to File
Posted by Alberto Massari <am...@datadirect.com>.
neerav patel wrote:
> Hi,
>
> I am new at Xerces and I am developing code in Visual C++ .NET 7.1, not
> managed code, just regular C++.
>
> I have managed to write an application that takes the sample
> CreateDOMDocument and I want to save that to a file now. I tried looking at
> DOMPrint example but nothing is making sense. Can someone give me some
> sample code to take an XML file in memory and write to a file.
>
>
This is the minimum amount of code you need:
DOMImplementation *impl =
DOMImplementationRegistry::getDOMImplementation(L"LS");
DOMWriter *theSerializer =
((DOMImplementationLS*)impl)->createDOMWriter();
LocalFileFormatTarget file(outputfile);
theSerializer->writeNode(&outputfile, *doc);
theSerializer->release();
Common options that you may want to specify are a specific encoding
(theSerializer->setEncoding(L"ISO-8859-1")) ), and whether the file
should be indented
(theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true) ).
Alberto