Thanks, 

I fixed the problem by moving the createDocument and the serializer->write 
outside of the loop. 

I am new to this and I am now struggling because I am not sure how to convert 
my c-style character arrays to the format the xerces accepts. In the below 
snippet, I was able to convert the char[2] c_id to a c++ string and then 
transcode that to set the text content. I am still not sure how that works and 
I am afraid I am not releasing it as I think I should. 

 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)

If I have the following data:

char c_type; (8-bits)

which currently has the value of 'L'. How would I can I use that data to 
setTextContent of the c_type element below.

 DOMElement* c_type = document->createElement(XMLString::transcode("c_type"));
 string new_c_id;
 c_id->setTextContent(XMLString::transcode(new_c_id.c_str()));
 rootElement->appendChild(c_id)
 

Raymond


-----Original Message-----
From: Hilario Perez Corona [mailto:[email protected]] 
Sent: Thursday, December 16, 2010 1:10 PM
To: [email protected]
Subject: EXTERNAL: Re: XML Declaration

My guess is that you are creating several Root nodes. So it thinks that you
are creating separate XML files each time.

You should have something like this instead:

<RECORDS>
    <S_RPS><c_id>AAA</c_id></S_RPS>
    <S_RPS><c_id>AAA</c_id></S_RPS>
    <S_RPS><c_id>AAA</c_id></S_RPS>
    <S_RPS><c_id>AAA</c_id></S_RPS>
    <S_RPS><c_id>AAA</c_id></S_RPS>
</RECORDS>

An XML can only have 1 root node.

On Thu, Dec 16, 2010 at 10:17 AM, Steele, Raymond
<[email protected]>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!
>
>
>
>
>
>
>
>


-- 
Hilario Perez Corona
"No Religion Higher Than Truth"

Reply via email to