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 Hiroyuki Shimada <sh...@din.or.jp> on 2010/07/02 17:06:09 UTC
DOM Indent
Hello,
I tried to write following code. It works and outputs the "output.xml"
file in the current directory.
But the XML in the file, no new line and no indent like this:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE catalog SYSTEM "file://c:/Oracle Magazine/catalog.dtd"><catalog title="Oracle Magazine"><journal button="2" date="January-February 2004" section="SQL"/></catalog>
Does anyone know the way to output human friendly XML file with new
lines and indents.
Thank you for your help.
try
{
XMLPlatformUtils::Initialize();
} catch (XMLException& e) {
char * msg = XMLString::transcode(e.getMessage());
this->Memo1->Lines->Add(msg);
XMLString::release(&msg);
return;
}
DOMImplementation *impl
= DOMImplementationRegistry::getDOMImplementation(X("Core"));
if (impl != 0) {
try {
DOMDocumentType *doctype = impl->createDocumentType(
X("catalog"), 0,
X("file://c:/Oracle Magazine/catalog.dtd"));
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *document
= impl->createDocument(0, 0, doctype);
DOMElement *catalog = document->createElement(X("catalog"));
catalog->setAttribute(X("title"), X("Oracle Magazine"));
document->appendChild(catalog);
DOMElement *journal = document->createElement(X("journal"));
journal->setAttribute(X("date"), X("January-February 2004"));
journal->setAttribute(X("section"), X("SQL"));
journal->setAttribute(X("button"), X("2"));
catalog->appendChild(journal);
DOMImplementationLS *implls = static_cast<DOMImplementationLS *>(impl);
DOMLSSerializer *serializer = implls->createLSSerializer();
XMLFormatTarget *target
= new LocalFileFormatTarget("output.xml");
DOMLSOutput *output = implls->createLSOutput();
output->setEncoding(X("UTF-8"));
output->setByteStream(target);
serializer->write(document, output);
delete target;
output->release();
serializer->release();
delete document;
delete doctype;
} catch (const XMLException& e) {
char * msg = XMLString::transcode(e.getMessage());
this->Memo1->Lines->Add(msg);
XMLString::release(&msg);
}
} else {
this->Memo1->Lines->Add("DOMImplementation is NULL");
}
XMLPlatformUtils::Terminate();
----------------------------------------------------------------------
Mail: shimaden@din.or.jp
Home Page: http://www.din.or.jp/~shimaden/
Hiroyuki Shimada
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
Re: DOM Indent
Posted by Hiroyuki Shimada <sh...@din.or.jp>.
Hello,
On Sun, 04 Jul 2010 11:07:15 -0700
David Bertoni <db...@apache.org> wrote:
> Please see the "format-pretty-print" option for DOMConfiguration:
>
> http://xerces.apache.org/xerces-c/apiDocs-3/classDOMLSSerializer.html#38fe950589395527f459879563f781a4
Thank you for answer. My problem was resolved.
> In the future, please ask questions like this on the C User list, and
> not on the dev list.
Yes. I will do so.
----------------------------------------------------------------------
Mail: shimaden@din.or.jp
Home Page: http://www.din.or.jp/~shimaden/
Hiroyuki Shimada
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
Re: DOM Indent
Posted by David Bertoni <db...@apache.org>.
On 7/2/2010 8:06 AM, Hiroyuki Shimada wrote:
> Hello,
>
> I tried to write following code. It works and outputs the "output.xml"
> file in the current directory.
>
> But the XML in the file, no new line and no indent like this:
>
> <?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE catalog SYSTEM "file://c:/Oracle Magazine/catalog.dtd"><catalog title="Oracle Magazine"><journal button="2" date="January-February 2004" section="SQL"/></catalog>
>
> Does anyone know the way to output human friendly XML file with new
> lines and indents.
>
> Thank you for your help.
Please see the "format-pretty-print" option for DOMConfiguration:
http://xerces.apache.org/xerces-c/apiDocs-3/classDOMLSSerializer.html#38fe950589395527f459879563f781a4
In the future, please ask questions like this on the C User list, and
not on the dev list.
Thanks!
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
Re: DOM Indent
Posted by Hiroyuki Shimada <sh...@din.or.jp>.
Sorry. Xerces C++ 3.1.1 I am using.
----------------------------------------------------------------------
Mail: shimaden@din.or.jp
Home Page: http://www.din.or.jp/~shimaden/
Hiroyuki Shimada
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org