Emma
I might be able to get you in the right direction. I needed to write out to
a file instead of to stdout. Here is what I changed. Please note that this
is not thoroughly tested.
First, I changed the constructor to DOMPrintFormatTarget to pass it an
ostream and added a class member as well. Then, I changed writeChars() to
use toFile instread of cout.
// -------------------------------------------------------------------------
--
// Local classes
// -------------------------------------------------------------------------
--
class DOMPrintFormatTarget : public XMLFormatTarget
{
public:
DOMPrintFormatTarget( ostream& outputStream) : toFile( outputStream )
{}
~DOMPrintFormatTarget() {}
// -----------------------------------------------------------------------
// Implementations of the format target interface
// -----------------------------------------------------------------------
void writeChars(const XMLByte* const toWrite)
{
// Surprisingly, Solaris was the only platform on which
// required the char* cast to print out the string correctly.
// Without the cast, it was printing the pointer value in hex.
// Quite annoying, considering every other platform printed
// the string with the explicit cast to char* below.
toFile << (char *) toWrite;
}
private:
// -----------------------------------------------------------------------
// Unimplemented methods.
// -----------------------------------------------------------------------
DOMPrintFormatTarget(const DOMPrintFormatTarget& other);
void operator=(const DOMPrintFormatTarget& rhs);
ostream& toFile;
};
Next, I used command line input to provide the output file name. I did have
to comment out the command line parameter counter logic in DOMPrint since my
version allowed more inputs (I needed to also allow the user the capability
to modify the values of a user specified node ... blah, blah, blah).
Anyway, I added the following forward reference ...
// -------------------------------------------------------------------------
--
// Forward references
// -------------------------------------------------------------------------
--
void usage();
ostream& operator<<(ostream& target, const DOMString& toWrite);
ostream& operator<<(ostream& target, DOM_Node& toWrite);
XMLFormatter& operator<< (XMLFormatter& strm, const DOMString& s);
// New functions
int modNode( DOM_Node& node, DOMString* values, int numValues );
and then the following (comment out the parmInd check and add the outputfile
check)
//
// And now we have to have only one parameter left and it must be
// the file name.
//
// if (parmInd + 1 != argC)
// {
// usage();
// XMLPlatformUtils::Terminate();
// return 1;
// }
gXmlFile = argV[parmInd];
ofstream gXmlOutFile ( argV[++parmInd], ios::out );
if ( !gXmlOutFile )
{
cerr << "Output file " << argV[parmInd-1]
<< " could not be opened" << endl;
exit(1);
}
Then ... change the DOMPrintFormatTarget new to include the output file ...
DOMPrintFormatTarget* formatTarget = new
OMPrintFormatTarget( gXmlOutFile );
... and modify the try block to include gXmlOutFile ...
try
{
gFormatter = new XMLFormatter(gEncodingName, formatTarget,
XMLFormatter::NoEscapes,
gUnRepFlags);
gXmlOutFile << doc << flush;
gXmlOutFile.close();
}
catch (XMLException& e)
{
cerr << "An error occurred during creation of output transcoder.
Msg is:"
<< endl
<< DOMString(e.getMessage()) << endl;
retval = 3;
}
delete formatTarget;
delete gFormatter;
It is neither pretty nor 100% tested, but it is giving me the right answers
so far.
Good luck
Todd Firsich
USAA Bank Applications
----- Original Message -----
From: Emma Towey
To: [EMAIL PROTECTED]
Sent: Saturday, March 24, 2001 5:38 AM
Subject: Re: Domprint and overwriting files
I need to be able to call DOMPrint with a filepath/filename as the
parameter, manipulate data ie append new data within DOMPrint and have the
new file saved and returned back to me. I don't want to have to set the
filepath inside the settings of the project or on the command line.
Any suggestions??
Emma
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
--------------------------------------------------------------------- To
unsubscribe, e-mail: [EMAIL PROTECTED] For additional
commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]