Prettyprint & newline ?‏‏

View: New views
4 Messages — Rating Filter:   Alert me  

Prettyprint & newline ?‏‏

by Michel Morgan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
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") );
     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> [] []
 





Get your information fix on your phone. With MSN Mobile you get regular news, sports and  finance updates. Try it today!

Re: Prettyprint & newline ?‏‏

by David Bertoni :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
For additional commands, e-mail: c-dev-help@...


RE: Prettyprint & newline ?‏‏

by Michel Morgan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
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@...
> To: c-dev@...
> 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 co de.
> > 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@...
> For additional commands, e-mail: c-de v-help@...
>



RE: Prettyprint & newline ???

by Jesse Pelton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...]
Sent: Wed 9/24/2008 5:04 PM
To: c-dev@...
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@...> To: c-dev@...> 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@...> For additional commands, e-mail: c-dev-help@...>
_________________________________________________________________




---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@...
For additional commands, e-mail: c-dev-help@...

winmail.dat (5K) Download Attachment
LightInTheBox - Buy quality products at wholesale price!