使用 CDATA 块时的 TinyXml 保存格式

发布于 2024-09-26 11:04:58 字数 775 浏览 5 评论 0原文

如果我有这个测试代码:

    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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乖乖兔^ω^ 2024-10-03 11:04:58

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文