我在我的项目中使用 TinyXML 库来生成 Xml 文件。(C++ 视觉工作室 2010)
当用户按下浏览按钮时,他/她可以选择多个图片或文件。
我想将每个名称写在一行中,但所有名称都在几个标签之间。我的意思是我想在输出中输入这段代码:
<?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>
但我不知道如何在他们之间写下新的一行。通过我的代码:
int NumberOfFile = 0;
array<String^>^ NamesOfSelectedFiles = gcnew array<String^>(100);
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)
{
String ^orig1 = gcnew String(openFileDialog1->FileName);
pin_ptr<const wchar_t> wch1 = PtrToStringChars(orig1);
size_t origsize1 = wcslen(wch1) + 1;
const size_t newsize1 = 100;
size_t convertedChars1 = 0;
char nstring1[newsize1];
wcstombs_s(&convertedChars1, nstring1, origsize1, wch1, _TRUNCATE);
TiXmlText* txt = new TiXmlText(nstring1);
msg->LinkEndChild(txt);
}
root->LinkEndChild(msg);
document.SaveFile("VID5.xml");
}
通过此代码,我生成了这样的文件:
<?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>
如何在这些名称之间写一个换行符?
太感谢了!