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 Michel Morgan <mf...@hotmail.com> on 2008/09/23 00:03:39 UTC
Prettyprint & newline ?
I am a beginner and started to use xerces-c-src_2_8_0 with C++ in VisualStudio 2005I have the following code which is supposed to read Test1.txt then dump it to Test2.txtContent of Test1.txt is listed under the code.The problem is, when I open output file "Test2.txt" using "notepad" I see all lines combined such as <?xml version="1.0" encoding="UTF-8" standalone="no" ?> [] [] <Items> [] <Item a="1"> [] </Item> [] </Items> [] []
Am I doing somthing wrong? I wish to be able to split these into several lines
Thanks for your help
code----#include <xercesc/parsers/XercesDOMParser.hpp>#include <xercesc/dom/DOM.hpp>#include <xercesc/sax/HandlerBase.hpp>#include <xercesc/util/XMLString.hpp>#include <xercesc/util/PlatformUtils.hpp>#include <xercesc/framework/LocalFileFormatTarget.hpp>XERCES_CPP_NAMESPACE_USEint main(int argc, char *argv[]){ XMLPlatformUtils::Initialize(); XercesDOMParser* parser= new XercesDOMParser(); parser->parse("Test1.txt"); DOMDocument* MyDoc=parser->getDocument(); DOMImplementation *impl =MyDoc->getImplementation(); DOMWriter *theSerializer =impl->createDOMWriter(); theSerializer->setNewLine(XMLString::transcode("\n\r") ); theSerializer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true); XMLFormatTarget *myFormTarget; myFormTarget = new LocalFileFormatTarget("Test2.txt"); theSerializer->writeNode(myFormTarget, *MyDoc); xercesc::XMLPlatformUtils::Terminate();}Input (Test1.txt)-----------------<?xml version="1.0" encoding="UTF-8" standalone="no" ?><Items> <Item a="1"> </Item
></Items>Output (Test2.txt)-----------------<?xml version="1.0" encoding="UTF-8" standalone="no" ?> [] [] <Items> [] <Item a="1"> [] </Item> [] </Items> [] []
_________________________________________________________________
RE: Prettyprint & newline ???
Posted by Jesse Pelton <js...@PKC.com>.
You're still setting XMLUni::fgDOMWRTFormatPrettyPrint, right? If so, the output should be pretty-printed. (Note that "pretty" is a matter of taste. I modify the implementation in xercesc\DOM\Impl\DOMWriterImpl.cpp to emit fewer line breaks and less indenting in some cases.)
If you're setting the flag and it's not getting pretty-printed, it may be time for a session with a debugger to figure out why.
-----Original Message-----
From: Michel Morgan [mailto:mfmg9@hotmail.com]
Sent: Wed 9/24/2008 5:04 PM
To: c-dev@xerces.apache.org
Subject: RE: Prettyprint & newline ???
Thanks Dave for your answer. That seemed to help splitting the header "<?xml version="1.0"....." and body "<Items ..." into two separate lines. However, the body is still a one-line printout.Is there an easy way to be able to split the body further to look more like a tree, preferably with appropriate tab indent?My alternative is to iterate through the DOM tree and output the file myself, but I am hoping that there is a magical command in xerces that I am not aware of to do that.> Date: Mon, 22 Sep 2008 21:52:31 -0700> From: dbertoni@apache.org> To: c-dev@xerces.apache.org> Subject: Re: Prettyprint & newline ???> > Michel Morgan wrote:> > I am a beginner and started to use xerces-c-src_2_8_0 with C++ in > > VisualStudio 2005> > I have the following code which is supposed to read Test1.txt then dump > > it to Test2.txt> > Content of Test1.txt is listed under the code.> > The problem is, when I open output file "Test2.txt" using "notepad" I > > see all lines combined such as> >
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> [] [] <Items> [] > > <Item a="1"> [] </Item> [] </Items> [] []> > > > Am I doing somthing wrong? I wish to be able to split these into several > > lines> > > > Thanks for your help> > > > code> > ----> > #include <xercesc/parsers/XercesDOMParser.hpp>> > #include <xercesc/dom/DOM.hpp>> > #include <xercesc/sax/HandlerBase.hpp>> > #include <xercesc/util/XMLString.hpp>> > #include <xercesc/util/PlatformUtils.hpp>> > #include <xercesc/framework/LocalFileFormatTarget.hpp>> > XERCES_CPP_NAMESPACE_USE> > int main(int argc, char *argv[])> > {> > XMLPlatformUtils::Initialize();> > XercesDOMParser* parser= new XercesDOMParser();> > parser->parse("Test1.txt");> > DOMDocument* MyDoc=parser->getDocument();> > DOMImplementation *impl =MyDoc->getImplementation();> > DOMWriter *theSerializer =impl->createDOMWriter();> > > > theSerializer->setNewLine(XMLString::transcode("\n\r") );> This is a memory leak. You need to free the pointer re
turn by the > transcode function:> > XMLCh* lfSeq = XMLString::transcode("\r\n");> theSerialize->setNewLine(lfSeq);> XMLString::release(&lfSeq);> > Also, the DOS sequence is CR/LF, so you want "\r\n" instead of "\n\r".> > Dave> > ---------------------------------------------------------------------> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org> For additional commands, e-mail: c-dev-help@xerces.apache.org>
_________________________________________________________________
RE: Prettyprint & newline ?
Posted by Michel Morgan <mf...@hotmail.com>.
Thanks Dave for your answer. That seemed to help splitting the header "<?xml version="1.0"....." and body "<Items ..." into two separate lines. However, the body is still a one-line printout.Is there an easy way to be able to split the body further to look more like a tree, preferably with appropriate tab indent?My alternative is to iterate through the DOM tree and output the file myself, but I am hoping that there is a magical command in xerces that I am not aware of to do that.> Date: Mon, 22 Sep 2008 21:52:31 -0700> From: dbertoni@apache.org> To: c-dev@xerces.apache.org> Subject: Re: Prettyprint & newline ?> > Michel Morgan wrote:> > I am a beginner and started to use xerces-c-src_2_8_0 with C++ in > > VisualStudio 2005> > I have the following code which is supposed to read Test1.txt then dump > > it to Test2.txt> > Content of Test1.txt is listed under the code.> > The problem is, when I open output file "Test2.txt" using "notepad" I > > see all lines combined such as> >
<?xml version="1.0" encoding="UTF-8" standalone="no" ?> [] [] <Items> [] > > <Item a="1"> [] </Item> [] </Items> [] []> > > > Am I doing somthing wrong? I wish to be able to split these into several > > lines> > > > Thanks for your help> > > > code> > ----> > #include <xercesc/parsers/XercesDOMParser.hpp>> > #include <xercesc/dom/DOM.hpp>> > #include <xercesc/sax/HandlerBase.hpp>> > #include <xercesc/util/XMLString.hpp>> > #include <xercesc/util/PlatformUtils.hpp>> > #include <xercesc/framework/LocalFileFormatTarget.hpp>> > XERCES_CPP_NAMESPACE_USE> > int main(int argc, char *argv[])> > {> > XMLPlatformUtils::Initialize();> > XercesDOMParser* parser= new XercesDOMParser();> > parser->parse("Test1.txt");> > DOMDocument* MyDoc=parser->getDocument();> > DOMImplementation *impl =MyDoc->getImplementation();> > DOMWriter *theSerializer =impl->createDOMWriter();> > > > theSerializer->setNewLine(XMLString::transcode("\n\r") );> This is a memory leak. You need to free the pointer re
turn by the > transcode function:> > XMLCh* lfSeq = XMLString::transcode("\r\n");> theSerialize->setNewLine(lfSeq);> XMLString::release(&lfSeq);> > Also, the DOS sequence is CR/LF, so you want "\r\n" instead of "\n\r".> > Dave> > ---------------------------------------------------------------------> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org> For additional commands, e-mail: c-dev-help@xerces.apache.org>
_________________________________________________________________
Re: Prettyprint & newline ?
Posted by David Bertoni <db...@apache.org>.
Michel Morgan wrote:
> I am a beginner and started to use xerces-c-src_2_8_0 with C++ in
> VisualStudio 2005
> I have the following code which is supposed to read Test1.txt then dump
> it to Test2.txt
> Content of Test1.txt is listed under the code.
> The problem is, when I open output file "Test2.txt" using "notepad" I
> see all lines combined such as
> <?xml version="1.0" encoding="UTF-8" standalone="no" ?> [] [] <Items> []
> <Item a="1"> [] </Item> [] </Items> [] []
>
> Am I doing somthing wrong? I wish to be able to split these into several
> lines
>
> Thanks for your help
>
> code
> ----
> #include <xercesc/parsers/XercesDOMParser.hpp>
> #include <xercesc/dom/DOM.hpp>
> #include <xercesc/sax/HandlerBase.hpp>
> #include <xercesc/util/XMLString.hpp>
> #include <xercesc/util/PlatformUtils.hpp>
> #include <xercesc/framework/LocalFileFormatTarget.hpp>
> XERCES_CPP_NAMESPACE_USE
> int main(int argc, char *argv[])
> {
> XMLPlatformUtils::Initialize();
> XercesDOMParser* parser= new XercesDOMParser();
> parser->parse("Test1.txt");
> DOMDocument* MyDoc=parser->getDocument();
> DOMImplementation *impl =MyDoc->getImplementation();
> DOMWriter *theSerializer =impl->createDOMWriter();
>
> theSerializer->setNewLine(XMLString::transcode("\n\r") );
This is a memory leak. You need to free the pointer return by the
transcode function:
XMLCh* lfSeq = XMLString::transcode("\r\n");
theSerialize->setNewLine(lfSeq);
XMLString::release(&lfSeq);
Also, the DOS sequence is CR/LF, so you want "\r\n" instead of "\n\r".
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org