Hello,
Using Xerces 3.1.0-C++, I am creating a DOMDocument to stdout. I am trying to
retrieve all the records in a .data file, which is in the form of a C struct.
Each record has multiple records with many elements. When I run the
application, the XML Declaration is repeated for each record. I do not like
this behavior and cannot figure out how to stop it. Can someone shed some
light? Thanks in advance. Here is a sample of the code.
XMLPlatform::Initialize ();
DOMImplmentation* implement =
DOMImplementationRegistry::getDOMImplementation(XMLString:transcode("Core"));
for ( int i=0; i<5; i++)
{
DOMDocument* document = implement->createDocument(0,
XMLString::transcode("S_RPS"), 0);
DOMElement* rootElement = document->getDocumentElement();
DOMElement* c_id =
document->createElement(XMLString::transcode("c_id"));
string new_c_id(struct_name[i].c_id, sizeof(struct_name[i].c_id));
c_id->setTextContent(XMLString::transcode(new_c_id.c_str()));
rootElement->appendChild(c_id)
DOMLSSerializer* serializer =
(DOMImplementationLS*)implement)->createLSSerializer();
DOMLSOutput* output =
((DOMImplementationLS*)implement)->createLSOutput();
DOMConfiguration* config = serializer->getDomConfig();
config->setParameter(XMLuni::fgDOMWRTFormatPrettyPrint, true);
StdOutFormatTarget* target = new StdOutFormatTarget();
output->setByteStream(target);
serializer->write(document, output);
delete target;
output->release();
serializer->release();
}
This will produce:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<S_RPS>
<c_id>AA</c_id>
</S_RPS>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<S_RPS>
<c_id>AA</c_id>
</S_RPS>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<S_RPS>
<c_id>AA</c_id>
</S_RPS>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<S_RPS>
<c_id>AA</c_id>
</S_RPS>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<S_RPS>
<c_id>AA</c_id>
</S_RPS>
Why does it keep repeating the <?xml version="1.0" encoding="UTF-8"
standalone="no" ?> ?
Thanks!