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: [email protected]
Home Page: http://www.din.or.jp/~shimaden/
Hiroyuki Shimada
----------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]