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 "jerome.mariette" <je...@mbari.org> on 2007/07/10 22:46:16 UTC
Write/read XML
Hi everybody,
I'm trying to write an XML file that I previously read (it's in order to
include small metadata xml file into a bigger one).
But I can't figure out how to add a tree to an already existed tree.
here is my code
const char* gXmlFile = "myXML.xml";
const XMLCh* gEncodingName = 0;
const XMLFormatter* gFormatter = 0;
//
// Create our parser, then attach an error handler to the parser.
// The parser will call back to methods of the ErrorHandler if it
// discovers errors during the course of parsing the XML document.
//
XercesDOMParser *parser = new XercesDOMParser;
parser->setValidationScheme(XercesDOMParser::Val_Auto);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setValidationSchemaFullChecking(false);
parser->setCreateEntityReferenceNodes(false);
//
// Parse the XML file, catching any XML exceptions that might
propogate
// out of it.
//
bool errorsOccured = false;
try
{
parser->parse(gXmlFile);
int errorCount = parser->getErrorCount();
if (errorCount > 0)
errorsOccured = true;
}
catch (const XMLException& e)
{
std::cerr << "An error occured during parsing\n Message: "
<< e.getMessage() << std::endl;
errorsOccured = true;
}
catch (const DOMException& e)
{
std::cerr << "A DOM error occured during parsing\n DOMException
code: "
<< e.code << std::endl;
errorsOccured = true;
}
catch (...)
{
std::cerr << "An error occured during parsing\n " << std::endl;
errorsOccured = true;
}
// If the parse was successful, output the document data from the DOM
tree
if (!errorsOccured ) ///&& !errReporter->getSawErrors())
{
DOMNode* metadata = parser->getDocument();
itsStreamWriter->writeNode(itsXMLFileFormatTarget, *metadata);
}
this code compile fine, sounds like the reading is ok, but when the Node is
not written.
What am I doing wrong ??
thx
--
View this message in context: http://www.nabble.com/Write-read-XML-tf4058365.html#a11529052
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
RE: Write/read XML
Posted by "jerome.mariette" <je...@mbari.org>.
thx a lot :) it's working !!
Jesse Pelton wrote:
>
> It sounds like you want to import nodes from one document into another.
> You can then serialize the containing document. See
> DOMDocument::importNode().
>
> -----Original Message-----
> From: jerome.mariette [mailto:jerome@mbari.org]
> Sent: Tuesday, July 10, 2007 4:46 PM
> To: c-dev@xerces.apache.org
> Subject: Write/read XML
>
>
> Hi everybody,
> I'm trying to write an XML file that I previously read (it's in order to
> include small metadata xml file into a bigger one).
> But I can't figure out how to add a tree to an already existed tree.
> here is my code
>
> const char* gXmlFile = "myXML.xml";
> const XMLCh* gEncodingName = 0;
> const XMLFormatter* gFormatter = 0;
>
> //
> // Create our parser, then attach an error handler to the
> parser.
> // The parser will call back to methods of the ErrorHandler
> if it
> // discovers errors during the course of parsing the XML
> document.
> //
> XercesDOMParser *parser = new XercesDOMParser;
> parser->setValidationScheme(XercesDOMParser::Val_Auto);
> parser->setDoNamespaces(false);
> parser->setDoSchema(false);
> parser->setValidationSchemaFullChecking(false);
> parser->setCreateEntityReferenceNodes(false);
>
> //
> // Parse the XML file, catching any XML exceptions that
> might
> propogate
> // out of it.
> //
> bool errorsOccured = false;
> try
> {
> parser->parse(gXmlFile);
> int errorCount = parser->getErrorCount();
> if (errorCount > 0)
> errorsOccured = true;
> }
> catch (const XMLException& e)
> {
> std::cerr << "An error occured during parsing\n Message:
> "
> << e.getMessage() << std::endl;
> errorsOccured = true;
> }
> catch (const DOMException& e)
> {
> std::cerr << "A DOM error occured during parsing\n
> DOMException
> code: "
> << e.code << std::endl;
> errorsOccured = true;
> }
> catch (...)
> {
> std::cerr << "An error occured during parsing\n " <<
> std::endl;
> errorsOccured = true;
> }
> // If the parse was successful, output the document data from the
> DOM
> tree
> if (!errorsOccured ) ///&& !errReporter->getSawErrors())
> {
> DOMNode* metadata = parser->getDocument();
> itsStreamWriter->writeNode(itsXMLFileFormatTarget,
> *metadata);
> }
>
> this code compile fine, sounds like the reading is ok, but when the Node
> is
> not written.
> What am I doing wrong ??
>
> thx
> --
> View this message in context:
> http://www.nabble.com/Write-read-XML-tf4058365.html#a11529052
> Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Write-read-XML-tf4058365.html#a11639998
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
RE: Write/read XML
Posted by Jesse Pelton <js...@PKC.com>.
It sounds like you want to import nodes from one document into another.
You can then serialize the containing document. See
DOMDocument::importNode().
-----Original Message-----
From: jerome.mariette [mailto:jerome@mbari.org]
Sent: Tuesday, July 10, 2007 4:46 PM
To: c-dev@xerces.apache.org
Subject: Write/read XML
Hi everybody,
I'm trying to write an XML file that I previously read (it's in order to
include small metadata xml file into a bigger one).
But I can't figure out how to add a tree to an already existed tree.
here is my code
const char* gXmlFile = "myXML.xml";
const XMLCh* gEncodingName = 0;
const XMLFormatter* gFormatter = 0;
//
// Create our parser, then attach an error handler to the
parser.
// The parser will call back to methods of the ErrorHandler
if it
// discovers errors during the course of parsing the XML
document.
//
XercesDOMParser *parser = new XercesDOMParser;
parser->setValidationScheme(XercesDOMParser::Val_Auto);
parser->setDoNamespaces(false);
parser->setDoSchema(false);
parser->setValidationSchemaFullChecking(false);
parser->setCreateEntityReferenceNodes(false);
//
// Parse the XML file, catching any XML exceptions that
might
propogate
// out of it.
//
bool errorsOccured = false;
try
{
parser->parse(gXmlFile);
int errorCount = parser->getErrorCount();
if (errorCount > 0)
errorsOccured = true;
}
catch (const XMLException& e)
{
std::cerr << "An error occured during parsing\n Message:
"
<< e.getMessage() << std::endl;
errorsOccured = true;
}
catch (const DOMException& e)
{
std::cerr << "A DOM error occured during parsing\n
DOMException
code: "
<< e.code << std::endl;
errorsOccured = true;
}
catch (...)
{
std::cerr << "An error occured during parsing\n " <<
std::endl;
errorsOccured = true;
}
// If the parse was successful, output the document data from the
DOM
tree
if (!errorsOccured ) ///&& !errReporter->getSawErrors())
{
DOMNode* metadata = parser->getDocument();
itsStreamWriter->writeNode(itsXMLFileFormatTarget,
*metadata);
}
this code compile fine, sounds like the reading is ok, but when the Node
is
not written.
What am I doing wrong ??
thx
--
View this message in context:
http://www.nabble.com/Write-read-XML-tf4058365.html#a11529052
Sent from the Xerces - C - Dev mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org