Hi Richard,
It works that way because output is buffered. In general, the formatter
has not finished its work until you call endDocument(), because you have
not finished the stream of events that serializes the document.
Dave
"Liu, Richard"
<[EMAIL PROTECTED] To:
<[email protected]>
ing.com> cc: <[EMAIL PROTECTED]>
Subject: RE: A problem of
example "SerializeNodeSet" in Xalan 1.6 and 1.7
02/06/2004 02:44
PM
Hi, Dave:
Thanks a lot for your help.
Today I resolved the problem why std::ostrstream and std::stringstream
do not work for me.
They do not work because I extract the string before the line
"theFormatter.endDocument();"
If in my code I write:
cout << "$$$$$$$$$$$$$$$$$$$$ outs.str()" << outs.str() << endl;
theFormatter.endDocument();
The code does NOT work.
However, if I change the position of the above code, say:
theFormatter.endDocument();
cout << "$$$$$$$$$$$$$$$$$$$$ outs.str()" << outs.str() << endl;
The example works now.
I do not know why we have to do this way, but it works.
There should be no problem on linux red hat.
Thanks for your help again.
Sincerely
Richard Liu
Software Engineer at Boeing
-----Original Message-----
From: Liu, Richard
Sent: Thursday, February 05, 2004 5:44 PM
To: [email protected]
Cc: [EMAIL PROTECTED]
Subject: RE: A problem of example "SerializeNodeSet" in Xalan 1.6 and
1.7
Hi, Dave:
I believe the above E-mail address: [email protected] is the
correct address to send to.
Thanks for your reply.
I am still desperately want to make the sample code ("SerializeNodeSet")
working. It still does NOT work using ostrstream, My code change is
almost the same as your change.
But I am using linux version (Red Hat 8.0).
Following is my compiling line:
g++ -c -g -D_DEBUG -Wno-deprecated -LANG:std -D_REENTRANT -D_PTHREADS
-I/proj/fcs/xalan/xml-xalan/c/src -I/proj/fcs/xerces-c-src_2_3_0/include
SerializeNodeSet.cxx
g++ -o ./SerializeNodeSet -g -D_DEBUG -Wno-deprecated -LANG:std
-D_REENTRANT -D_PTHREADS SerializeNodeSet.o
-L/proj/fcs/xalan/xml-xalan/c/lib -lxalan-c
If I type "g++ -v" on my linux console window, it shows the following:
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --host=i386-redhat-linux --with-system-zlib
--enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
Following is the diff of my file and the original sample file. I still
can NOT print out the result of treeWalker.
14d70
< #include <strstream>
28a85,86
>
>
55d112
< XALAN_USING_STD(ostrstream)
166,168c223
<
< std::ostrstream outs;
< XalanStdOutputStream
theStream(outs);
---
> XalanStdOutputStream
theStream(cout);
171d225
<
206,207d259
<
<
209,210d260
<
<
213,216d262
< cout.write (outs.str(),
outs.pcount());
< cout << endl;
< outs.freeze(false);
<
I believe the Xalan library just does NOT work on this linux version.
Also, I have tested the ostringstream a few days ago. My code change is the
same as what you showed me. It just does NOT work.
Let me know if you have any more ideas ?
Thanks a lot
Richard Liu
Software Developer at Boeing
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 05, 2004 3:15 PM
To: [email protected]
Cc: Liu, Richard
Subject: Re: A problem of example "SerializeNodeSet" in Xalan 1.6 and
1.7
Hi Richard,
You'll notice you sent your email to the subscribe address, instead of
actually to the list. Please make sure you send directly to the list.
Also, the Xalan-C user list would be a better venue for this sort of
question. Please subscribe to that list before you reply to the list, or
before you post another question.
I don't know why you are having problems using either std::ostrstream or
std::ostringstream. DOMString will not work because the FormatterToXML
will need an actual output stream because it assumes it must transcode. We
don't have a FormatterListener derivative that can serialize XML to a
DOMString because it's never been requested before, and it's not clear why
that is any better than one of the standard output streams, or a custom
memory stream based on std::ostream.
Here are my diffs for modifying the SerializeNodeSet sample to work with
both std::ostrstream and std::ostringstream. I tested this on Win32 using
MSVC 6.0, SP5.
cvs diff SerializeNodeSet.cpp (in directory
V:\xml-xalan\c\samples\SerializeNodeSet\)
Index: SerializeNodeSet.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/samples/SerializeNodeSet/SerializeNodeSet.cpp,v
retrieving revision 1.10
diff -r1.10 SerializeNodeSet.cpp
69c69
<
---
> #include <strstream>
223c223,228
< XalanStdOutputStream
theStream(cout);
---
>
> XALAN_USING_STD(ostrstream)
>
> ostrstream theOstrstream;
> XalanStdOutputStream
theStream(theOstrstream);
>
226c231
< FormatterToXML
theFormatter(thePrintWriter);
---
> FormatterToXML
theFormatter(thePrintWriter);
264a270,273
>
> cout.write(theOstrstream.str(),
theOstrstream.pcount());
> cout << endl;
> theOstrstream.freeze(false);
*****CVS exited normally with code 1*****
cvs diff SerializeNodeSet.cpp (in directory
V:\xml-xalan\c\samples\SerializeNodeSet\)
Index: SerializeNodeSet.cpp
===================================================================
RCS file:
/home/cvs/xml-xalan/c/samples/SerializeNodeSet/SerializeNodeSet.cpp,v
retrieving revision 1.10
diff -r1.10 SerializeNodeSet.cpp
69c69
<
---
> #include <sstream>
223c223,228
< XalanStdOutputStream
theStream(cout);
---
>
> XALAN_USING_STD(ostringstream)
>
> ostringstream theOstrstream;
> XalanStdOutputStream
theStream(theOstrstream);
>
226c231
< FormatterToXML
theFormatter(thePrintWriter);
---
> FormatterToXML
theFormatter(thePrintWriter);
264a270,271
>
> cout << theOstrstream.str() << endl;
*****CVS exited normally with code 1*****
Dave
"Liu, Richard"
<[EMAIL PROTECTED] To:
<[EMAIL PROTECTED]>
ing.com> cc:
<[EMAIL PROTECTED]>
Subject: A problem of
example "SerializeNodeSet" in Xalan 1.6 and 1.7
02/03/2004 12:17
PM
Hi, David and all:
I have a problem of example code "SerializeNodeSet" in Xalan 1.6 and 1.7.
My problem is not the example itself. The example prints out the
traverseSubtree value correctly into std output.
My problem is how can I print the traverseSubtree value into a string or
DOMString.
I have tried several approach:
1) Using DOMString and DOMStringPrintWriter.
I just changed a few lines of original demo code.
Instead of of using original code in the following several
lines:
XalanStdOutputStream
theStream(cout);
XalanOutputStreamPrintWriter thePrintWriter(theStream);
FormatterToXML
theFormatter(thePrintWriter);
FormatterTreeWalker
theWalker(theFormatter);
I used:
XalanDOMString myDOMString;
DOMStringPrintWriter myPrinterWriter (myDOMString);
FormatterToXML
theFormatter(myPrinterWriter);
FormatterTreeWalker theWalker(theFormatter);
After traverseSubtree, I can NOT get correct result in the
myDOMString. Why ????????
2) I also used std::ostream variant, class ostringstream.
I only change a few lines of code show in the following:
std::ostringstream outs.
XalanStdOutputStream theStream(outs);
XalanOutputStreamPrintWriter
thePrintWriter(theStream);
FormatterToXML
theFormatter(thePrintWriter);
FormatterTreeWalker
theWalker(theFormatter);
After traverseSubtree, I can not get anything out of my outs.
3) I also tried ostrstream, it did not work too.
Anybody can tell me what's going wrong?
Any hint will be greatly appreciated.
Sincerely
Richard Liu
Software Engineer at Boeing