如何使用 FirstCHildElement 从 xml 标记获取值

发布于 2024-11-17 15:02:09 字数 289 浏览 3 评论 0原文

我正在 C++ 工作。我想问一下如何获取值文本:

<message> text </message>

我有

TiXmlHandle handle(&doc);
TiXmlElement* section;
section=doc.FirstChildElement("message");

从现在开始该怎么做?我知道我必须使用 .Element() 但我不知道如何操作。

I am working in C++. I would like to ask how to obtain the value text from:

<message> text </message>

I have

TiXmlHandle handle(&doc);
TiXmlElement* section;
section=doc.FirstChildElement("message");

How to do it from now on? I know I have to work with .Element() but I don't know how.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

鸢与 2024-11-24 15:02:09

您可以使用函数GetText()来获取的内容。我将 XML 内容放入名为 dummy.xml 的文件中,并使用以下代码打印内容:

TiXmlDocument doc("dummy.xml");

if(doc.LoadFile())
{
    TiXmlHandle hDoc(&doc);
    TiXmlElement *pRoot;
    pRoot = doc.FirstChildElement("message");
    printf("pRoot text: %s", pRoot->GetText());

}

You can use the function GetText() to obtain the contents of <message>. I put your XML-contents in a file called dummy.xml and used the following code to print the contents:

TiXmlDocument doc("dummy.xml");

if(doc.LoadFile())
{
    TiXmlHandle hDoc(&doc);
    TiXmlElement *pRoot;
    pRoot = doc.FirstChildElement("message");
    printf("pRoot text: %s", pRoot->GetText());

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