使用 CDATA 块时的 TinyXml 保存格式
如果我有这个测试代码:
TiXmlElement *parentElem = new TiXmlElement("ParentNode");
TiXmlElement *newElem = new TiXmlElement("TestNode");
TiXmlText *textElem = new TiXmlText("Test Content");
//textElem->SetCDATA(true);
newElem->LinkEndChild(textElem);
parentElem->LinkEndChild(newElem);
随着注释行我得到输出 XML:
<ParentNode>
<TestNode>Test Content</TestNode>
</ParentNode>
取消注释我得到的行:
<ParentNode>
<TestNode>
<![CDATA[Test Content]]>
</TestNode>
</ParentNode>
现在理想情况下它仍然是一行,但我真的不介意将 CDATA 内容嵌套...但是事实上,关闭
上的缩进是很痛苦的。这是 TinyXml 的可控部分,还是一个错误,或者就是这样?
If I have this test code:
TiXmlElement *parentElem = new TiXmlElement("ParentNode");
TiXmlElement *newElem = new TiXmlElement("TestNode");
TiXmlText *textElem = new TiXmlText("Test Content");
//textElem->SetCDATA(true);
newElem->LinkEndChild(textElem);
parentElem->LinkEndChild(newElem);
With the line commented I get output XML:
<ParentNode>
<TestNode>Test Content</TestNode>
</ParentNode>
Uncommenting the line I get:
<ParentNode>
<TestNode>
<![CDATA[Test Content]]>
</TestNode>
</ParentNode>
Now ideally it would still all be one line, but I don't really mind it putting the CDATA content nested... but the fact indentation is screwed up on the closing <TestNode>
is a pain. Is this a controllable part of TinyXml, or a bug, or just the way it is?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TinyXML 的输出格式看起来像是一个错误。
使用 TiXmlPrinter 进行输出而不是 TiXmlDocument 输出(我假设您正在使用它?)可能会起作用。 TiXmlPrinter 使用不同的打印路径,并且可能不会有相同的错误。
Looks like a bug in the output formatting if TinyXML.
It may work to use TiXmlPrinter for output instead of the TiXmlDocument output (which I assume you are using?). TiXmlPrinter uses a different print path, and may not have the same bug.