|
Glad to hear that it has been a help.
Please send me a description of the source that you wrote (or
the source itself) that is giving you trouble ... hard to tell exactly what it
is without seeing it ... I have an idea ... maybe ... we'll see :)
Todd
----- Original Message -----
Sent: Wednesday, March 28, 2001 1:34
PM
Subject: Re: Domprint and overwriting
files
Hi,
Thanks a million for your help I have taken your
suggestions.
At the moment I am opening a file inserting new data and
saving the new file; the only trouble is that the information between the tags
is being saved but the tags aren’t.
I.e. I open and parse a file with a structure similar to
this:
<Exception_Event>
<ID>0</ID>
<message>feeder not
found</message>
</Exception_Event>
but my new saved file has a structure like this:
0
feeder not found
Can you help?
Thanks,
Emma
>From: "Todd Firsich" <[EMAIL PROTECTED]>
>Reply-To: [EMAIL PROTECTED]
>To: <[EMAIL PROTECTED]>
>Subject: Re: Domprint and overwriting files
>Date: Mon, 26 Mar 2001 15:34:09 -0600
>
>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]
>
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]
|