The second is not a valid XML document. An XML document can only have 1 root element. If you want them to appear is <S_RPS> tags then you can create another element as the root element and attach them all to that.
Gareth On 16 Dec 2010, at 18:33, Steele, Raymond wrote: > Gareth, > > Thanks for such a quick response. When I do as you suggested I receive this > output: > > <?xml version="1.0" encoding="UTF-8" standalone="no" ?> > <S_RPS> > <c_id>AA</c_id> > <c_id>AA</c_id> > <c_id>AA</c_id> > <c_id>AA</c_id> > </S_RPS> > > However, I want to achieve this output: > > <?xml version="1.0" encoding="UTF-8" standalone="no" ?> > <S_RPS> > <c_id>AA</c_id> > </S_RPS> > <S_RPS> > <c_id>AA</c_id> > </S_RPS> > <S_RPS> > <c_id>AA</c_id> > </S_RPS> > <S_RPS> > <c_id>AA</c_id> > </S_RPS> > <S_RPS> > <c_id>AA</c_id> > </S_RPS> > > Once again, thanks for the fast response. That’s awesome. > > Raymond > > From: Gareth Reakes [mailto:[email protected]] > Sent: Thursday, December 16, 2010 11:32 AM > To: [email protected] > Subject: EXTERNAL: Re: XML Declaration > > Hi Raymond, > > It does that because you are creating multiple DOM documents and > each one of those has an XML declaration. You do that here: > > DOMDocument* document = implement->createDocument(0, > XMLString::transcode("S_RPS"), 0); > > > If you move that line and the next: > > DOMElement* rootElement = document->getDocumentElement(); > > out of the loop then you will create 1 document with all the <c_id> elements > inside inside a single <S_PRS> root element. > > Cheers, > > Gareth > > > > On 16 Dec 2010, at 18:17, Steele, Raymond wrote: > > > 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! > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > > > -- > Gareth Reakes, CTO WE7 - Great Music, Free > +44-20-7117-0809 http://www.we7.com > > “The music business is a cruel and shallow money trench, a long plastic > hallway where thieves and pimps run free, and good men die like dogs. There's > also a negative side. “ > - Hunter S. Thompson > > > -- Gareth Reakes, CTO WE7 - Great Music, Free +44-20-7117-0809 http://www.we7.com “The music business is a cruel and shallow money trench, a long plastic hallway where thieves and pimps run free, and good men die like dogs. There's also a negative side. “ - Hunter S. Thompson
