Link to home
Start Free TrialLog in
Avatar of camster123
camster123

asked on

How can one write newline characters between TiXmLText elements in a Tiny XML DOM Object using Visual Studio 2008 C++?

I am using TinyXML library in my project to produce a Xml file. (C++ Visual Studio 2008).
I want to write each name in one line but all of them between a couple tags. I would like the output format below:
   <?xml version="1.0"?>
    <opencv_storage>
    <images>
    ./images/cam01.jpg
    ./images/cam02.jpg
    ./images/cam03.jpg
    ./images/cam04.jpg
    ./images/cam05.jpg
    ./images/cam06.jpg
    ./images/cam07.jpg
    ./images/cam08.jpg
    ./images/cam09.jpg
    ./images/cam10.jpg
    ./images/cam11.jpg
    ./images/cam12.jpg
    ./images/cam13.jpg
    ./images/cam14.jpg
    </images>
    </opencv_storage>
but I dont know How can I write the new line between them . by my code here:
  TiXmlDocument document;
  TiXmlElement* msg;
  TiXmlDeclaration* dec1 = new TiXmlDeclaration("1.0","","");
  document.LinkEndChild(dec1);

  TiXmlElement * root = new TiXmlElement( "opencv_storage" );  
  document.LinkEndChild( root );
  msg = new TiXmlElement("images");

  openFileDialog1->Title = "Select an Image file";

 if (openFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK)

  {
     for each (String^ file in openFileDialog1->SafeFileNames)
         {
         std::stringstream v;
         v << openFileDialog1->FileName;
         TiXmlText* txt = new TiXmlText(v.str());
         msg->LinkEndChild(txt);
         }
              root->LinkEndChild(msg);


          document.SaveFile("VID5.xml");

     }
by this Code I produce such file :
 <?xml version="1.0" ?>
    <opencv_storage>
    <images>C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpgC:\Users\Public  \Pictures\Sample Pictures\Chrysanthemum.jpg
    </images>
    </opencv_storage>
How Can I write a newline character between these names ?
Any help is greatly appreciated.
ASKER CERTIFIED SOLUTION
Avatar of Mark Bullock
Mark Bullock
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of camster123
camster123

ASKER

Thank you for the solution. I believe there is a difference in C++ between endl and '\n'
I think endl will flush the buffer or stream.