如何给xml文档添加换行?
#import<msxml3.dll>voidExit(){CoUninitialize();}intmain(){CoInitialize(NULL);//初始化COM...
#import <msxml3.dll>
void Exit()
{
CoUninitialize();
}
int main()
{
CoInitialize(NULL); // 初始化COM环境
//atexit(Exit);
MSXML2::IXMLDOMDocumentPtr pDOMDoc;
pDOMDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30)); // 创建XMLDOMDocument对象
MSXML2::IXMLDOMProcessingInstructionPtr pDOMPI;
pDOMPI=pDOMDoc->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); // 创建XML声明
pDOMDoc->appendChild(pDOMPI); // 添加XML声明
MSXML2::IXMLDOMElementPtr pDOMRoot;
pDOMDoc->raw_createElement((_bstr_t)"China", &pDOMRoot); // 创建[根]节点
pDOMRoot->setAttribute("Area", "3600000"); // 设置[根]节点属性
pDOMDoc->appendChild(pDOMRoot); // 向Document中添加根节点
MSXML2::IXMLDOMElementPtr pDOMNode;
pDOMDoc->raw_createElement((_bstr_t)"City", &pDOMNode);
pDOMNode->Puttext("Chongqing"); // 为节点赋值
pDOMRoot->appendChild(pDOMNode); // 向[根]节点中添加子节点
pDOMDoc->raw_createElement((_bstr_t)"City", &pDOMNode);
pDOMNode->Puttext("Beijing");
pDOMRoot->appendChild(pDOMNode);
pDOMDoc->raw_createElement((_bstr_t)"City", &pDOMNode);
pDOMNode->Puttext("Beijing");
pDOMRoot->appendChild(pDOMNode);
pDOMDoc->raw_createElement((_bstr_t)"City", &pDOMNode);
pDOMNode->Puttext("Beijing");
pDOMRoot->appendChild(pDOMNode);
pDOMDoc->save("Test.xml"); // 储存XML Document
return 0;
}
输出后让它变成
<?xml version="1.0" encoding="UTF-8"?>
<China Area="3600000">
<City>Chongqing</City>
<City>Beijing</City>
<City>Beijing</City>
<City>Beijing</City>
</China> 展开
void Exit()
{
CoUninitialize();
}
int main()
{
CoInitialize(NULL); // 初始化COM环境
//atexit(Exit);
MSXML2::IXMLDOMDocumentPtr pDOMDoc;
pDOMDoc.CreateInstance(__uuidof(MSXML2::DOMDocument30)); // 创建XMLDOMDocument对象
MSXML2::IXMLDOMProcessingInstructionPtr pDOMPI;
pDOMPI=pDOMDoc->createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""); // 创建XML声明
pDOMDoc->appendChild(pDOMPI); // 添加XML声明
MSXML2::IXMLDOMElementPtr pDOMRoot;
pDOMDoc->raw_createElement((_bstr_t)"China", &pDOMRoot); // 创建[根]节点
pDOMRoot->setAttribute("Area", "3600000"); // 设置[根]节点属性
pDOMDoc->appendChild(pDOMRoot); // 向Document中添加根节点
MSXML2::IXMLDOMElementPtr pDOMNode;
pDOMDoc->raw_createElement((_bstr_t)"City", &pDOMNode);
pDOMNode->Puttext("Chongqing"); // 为节点赋值
pDOMRoot->appendChild(pDOMNode); // 向[根]节点中添加子节点
pDOMDoc->raw_createElement((_bstr_t)"City", &pDOMNode);
pDOMNode->Puttext("Beijing");
pDOMRoot->appendChild(pDOMNode);
pDOMDoc->raw_createElement((_bstr_t)"City", &pDOMNode);
pDOMNode->Puttext("Beijing");
pDOMRoot->appendChild(pDOMNode);
pDOMDoc->raw_createElement((_bstr_t)"City", &pDOMNode);
pDOMNode->Puttext("Beijing");
pDOMRoot->appendChild(pDOMNode);
pDOMDoc->save("Test.xml"); // 储存XML Document
return 0;
}
输出后让它变成
<?xml version="1.0" encoding="UTF-8"?>
<China Area="3600000">
<City>Chongqing</City>
<City>Beijing</City>
<City>Beijing</City>
<City>Beijing</City>
</China> 展开
2个回答
展开全部
& lt; br/ & gt; 去掉空格
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<br>是换行代码, ;空格键,<pre></pre>也是啊
追问
我要写到txt文件中去,现在的问题是写进去后它整个就是一行!《br、pre等的只是用于html中的
追答
哦,以为你要写代码!!你要写文本文件?我不太明白
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询