You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-users@xalan.apache.org by da...@us.ibm.com on 2004/02/05 22:14:41 UTC

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"                                                                                                                 
                      <Richard.Liu@boe         To:      <xa...@xml.apache.org>                                                         
                      ing.com>                 cc:      <da...@us.ibm.com>                                                                 
                                               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