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 "Steele, Raymond" <ra...@lmco.com> on 2010/12/16 19:17:30 UTC
XML Declaration
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: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
RE: EXTERNAL: Re: XML Declaration
Posted by "Steele, Raymond" <ra...@lmco.com>.
I see thanks! I will add another. Thanks for your help.
Raymond
From: Gareth Reakes [mailto:gareth@we7.com]
Sent: Thursday, December 16, 2010 11:45 AM
To: c-dev@xerces.apache.org
Subject: Re: EXTERNAL: Re: XML Declaration
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:gareth@we7.com]
Sent: Thursday, December 16, 2010 11:32 AM
To: c-dev@xerces.apache.org<ma...@xerces.apache.org>
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: c-dev-unsubscribe@xerces.apache.org<ma...@xerces.apache.org>
For additional commands, e-mail: c-dev-help@xerces.apache.org<ma...@xerces.apache.org>
--
Gareth Reakes, CTO WE7 - Great Music, Free
+44-20-7117-0809 http://www.we7.com<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<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
RE: EXTERNAL: Re: XML Declaration
Posted by "Steele, Raymond" <ra...@lmco.com>.
That did it.
Raymond
From: Gareth Reakes [mailto:gareth@we7.com]
Sent: Thursday, December 16, 2010 11:45 AM
To: c-dev@xerces.apache.org
Subject: Re: EXTERNAL: Re: XML Declaration
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:gareth@we7.com]
Sent: Thursday, December 16, 2010 11:32 AM
To: c-dev@xerces.apache.org<ma...@xerces.apache.org>
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: c-dev-unsubscribe@xerces.apache.org<ma...@xerces.apache.org>
For additional commands, e-mail: c-dev-help@xerces.apache.org<ma...@xerces.apache.org>
--
Gareth Reakes, CTO WE7 - Great Music, Free
+44-20-7117-0809 http://www.we7.com<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<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
RE: EXTERNAL: Re: XML Declaration
Posted by "Steele, Raymond" <ra...@lmco.com>.
Thanks,
I will take a closer look at those documents. I do have some difficulty understanding, but I will concentrate more on them instead of jumping around from reference to reference. Thanks for the information.
Raymond
From: Gareth Reakes [mailto:gareth@we7.com]
Sent: Friday, December 17, 2010 1:39 AM
To: c-dev@xerces.apache.org
Subject: Re: EXTERNAL: Re: XML Declaration
Hi Raymond,
A good place to start are the docs, examples and FAQ. You need to release things you transcode as talked about here:
http://xerces.apache.org/xerces-c/apiDocs-3/classXMLString.html#91b02742b80418fbc6c54b7dd353ad8c
Other memory is managed at document level and you need to release that to get it back. Take a look at some common questions in the FAQ:
http://xerces.apache.org/xerces-c/faq-parse-2.html
and also examples like CreateDOMDocument where you will see easy easy ways to handle transcoding issues.
Gareth
On 17 Dec 2010, at 00:33, Steele, Raymond wrote:
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
Raymond
From: Gareth Reakes [mailto:gareth@we7.com]
Sent: Thursday, December 16, 2010 11:45 AM
To: c-dev@xerces.apache.org<ma...@xerces.apache.org>
Subject: Re: EXTERNAL: Re: XML Declaration
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:gareth@we7.com]
Sent: Thursday, December 16, 2010 11:32 AM
To: c-dev@xerces.apache.org<ma...@xerces.apache.org>
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: c-dev-unsubscribe@xerces.apache.org<ma...@xerces.apache.org>
For additional commands, e-mail: c-dev-help@xerces.apache.org<ma...@xerces.apache.org>
--
Gareth Reakes, CTO WE7 - Great Music, Free
+44-20-7117-0809 http://www.we7.com<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<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<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
Re: EXTERNAL: Re: XML Declaration
Posted by Gareth Reakes <ga...@we7.com>.
Hi Raymond,
A good place to start are the docs, examples and FAQ. You need to release things you transcode as talked about here:
http://xerces.apache.org/xerces-c/apiDocs-3/classXMLString.html#91b02742b80418fbc6c54b7dd353ad8c
Other memory is managed at document level and you need to release that to get it back. Take a look at some common questions in the FAQ:
http://xerces.apache.org/xerces-c/faq-parse-2.html
and also examples like CreateDOMDocument where you will see easy easy ways to handle transcoding issues.
Gareth
On 17 Dec 2010, at 00:33, Steele, Raymond wrote:
> 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
>
>
> Raymond
>
> From: Gareth Reakes [mailto:gareth@we7.com]
> Sent: Thursday, December 16, 2010 11:45 AM
> To: c-dev@xerces.apache.org
> Subject: Re: EXTERNAL: Re: XML Declaration
>
>
> 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:gareth@we7.com]
> Sent: Thursday, December 16, 2010 11:32 AM
> To: c-dev@xerces.apache.org
> 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: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
>
>
> --
> 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
>
>
>
--
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
RE: EXTERNAL: Re: XML Declaration
Posted by "Steele, Raymond" <ra...@lmco.com>.
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
Raymond
From: Gareth Reakes [mailto:gareth@we7.com]
Sent: Thursday, December 16, 2010 11:45 AM
To: c-dev@xerces.apache.org
Subject: Re: EXTERNAL: Re: XML Declaration
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:gareth@we7.com]
Sent: Thursday, December 16, 2010 11:32 AM
To: c-dev@xerces.apache.org<ma...@xerces.apache.org>
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: c-dev-unsubscribe@xerces.apache.org<ma...@xerces.apache.org>
For additional commands, e-mail: c-dev-help@xerces.apache.org<ma...@xerces.apache.org>
--
Gareth Reakes, CTO WE7 - Great Music, Free
+44-20-7117-0809 http://www.we7.com<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<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
Re: EXTERNAL: Re: XML Declaration
Posted by Gareth Reakes <ga...@we7.com>.
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:gareth@we7.com]
> Sent: Thursday, December 16, 2010 11:32 AM
> To: c-dev@xerces.apache.org
> 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: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
>
> --
> 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
RE: EXTERNAL: Re: XML Declaration
Posted by "Steele, Raymond" <ra...@lmco.com>.
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:gareth@we7.com]
Sent: Thursday, December 16, 2010 11:32 AM
To: c-dev@xerces.apache.org
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: c-dev-unsubscribe@xerces.apache.org<ma...@xerces.apache.org>
For additional commands, e-mail: c-dev-help@xerces.apache.org<ma...@xerces.apache.org>
--
Gareth Reakes, CTO WE7 - Great Music, Free
+44-20-7117-0809 http://www.we7.com<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
Re: XML Declaration
Posted by Gareth Reakes <ga...@we7.com>.
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: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
--
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