标签: tinyxml2

获取tinyxml2中的子元素

这可能是一个新手问题,但我是tinyxml2的新手,无法找到任何相关信息.

我试图使用tinyxml2循环遍历XML文件.

<images>
    <correctImage>image1.png</correctImage>
    <image>image2.png</image>
    <image>image3.png</image>
</images>
Run Code Online (Sandbox Code Playgroud)

我有图像元素的XMLElement,但我不知道如何获取内部元素.

任何一只手都会受到赞赏.

为了记录,这是我获取XML元素的方式:

tinyxml2::XMLElement *levelElement = doc.FirstChildElement("reactor")->FirstChildElement("level")->FirstChildElement("images");
Run Code Online (Sandbox Code Playgroud)

提前致谢.

c++ tinyxml2

9
推荐指数
1
解决办法
1万
查看次数

如何在TinyXML2中将XMLElement转换为字符串

在TinyXml 1中,可以使用<<运算符将子元素转换为字符串,例如

TiXmlElement * pxmlChild = pxmlParent->FirstChildElement( "child" );
std::stringstream ss;
ss << (*pxmlChild);
Run Code Online (Sandbox Code Playgroud)

这在TinyXml2中似乎不可能.如何在TinyXml2中将元素转换为xml字符串?

编辑:特别是我在xml之后,例如,如果xml是:

<parent>
    <child>
        <value>abc</value>
    </child>
<parent>
Run Code Online (Sandbox Code Playgroud)

我想要子元素的xml,例如

<child>
    <value>abc</value>
</child>
Run Code Online (Sandbox Code Playgroud)

c++ xml tinyxml tinyxml2

5
推荐指数
2
解决办法
6353
查看次数

在tinyxml2中添加文本

我正在尝试使用TinyXML2创建XML文件.虽然有很多关于加载的示例和教程,但保存似乎很少.我基本上想要最终得到:

<node>text</node>
Run Code Online (Sandbox Code Playgroud)

我知道我可以通过添加元素来获取"节点"部分,但是如何设置文本部分?Element有一个"GetText"但我找不到"SetText".还有一个XMLText类,但没有设置文本的方法!

c++ xml tinyxml2

5
推荐指数
1
解决办法
4915
查看次数

如何使用 tinyxml2 解析空元素?

使用 tinyXml2,我可以解析

<MSG_TIME>2010-07-01 14:28:20</MSG_TIME>
很好,但是
<MSG_TIME></MSG_TIME>
<MSG_TIME/>
当它们是完全有效的 XML(据我所知)时,它们都会在 C++ 中抛出异常。有没有人对此有修复或建议?我不控制这个 XML 的来源,我需要容错。

c++ tinyxml2

4
推荐指数
1
解决办法
1553
查看次数

如何使用tinyxml2查询字符串属性?

嗨,有人知道如何使用tinyxml2在字符串变量中查询属性吗?

例:

<pattern>
    <distances numberOfDistances="1" realWorldPixelSize="0.26428571428571429">
        <markerDistance linkName="AB" distance="58.624385902531891"/>
    </distances>
</pattern>
Run Code Online (Sandbox Code Playgroud)

为了获取distance属性,我使用

for (tinyxml2::XMLElement* child = distancesElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
    {
        double distance;
        child->QueryAttribute("distance", &distance);
        distances.push_back(MarkerDistance(linkName, distance));
    }
Run Code Online (Sandbox Code Playgroud)

我以为字符串是这样的:

std::string linkName;
child->QueryAttribute("linkName", &linkName);
Run Code Online (Sandbox Code Playgroud)

但是对于字符串,似乎没有重载。

c++ xml tinyxml2

4
推荐指数
1
解决办法
3838
查看次数

在 C++ 中使用 tinyxml2 读取 xml 文件

我不知道如何在 C++ 中使用 tinyxml2 读取这个 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<empleados>
 <cantidad>UnaCantidad</cantidad>
 <empleado>
  <idEmpleado>1</idEmpleado>
  <nombre>UnNombre1</nombre>
  <apellidos>UnosApellidos1</apellidos>
 </empleado>
 <empleado>
  <idEmpleado>2</idEmpleado>
  <nombre>UnNombre2</nombre>
  <apellidos>UnosApellidos2</apellidos>
 </empleado>
</empleados> 
Run Code Online (Sandbox Code Playgroud)

这就是我现在正在做的,不起作用:

tinyxml2::XMLDocument xml_doc;

tinyxml2::XMLError eResult = xml_doc.LoadFile(xml_path);
XMLCheckResult(eResult);

tinyxml2::XMLNode* root = xml_doc.FirstChild();
if (root == nullptr) return tinyxml2::XML_ERROR_FILE_READ_ERROR;

tinyxml2::XMLElement* element = root->FirstChildElement("cantidad");
if (element == nullptr) return tinyxml2::XML_ERROR_PARSING_ELEMENT;

int xml_count;
eResult = element->QueryIntText(&xml_count);
XMLCheckResult(eResult);

Empleado* empleados= Empleado[xml_count];

element = root->FirstChildElement("empleado");
Empleado e;
int i = 0;

while (element != nullptr && i < xml_count)
{
    tinyxml2::XMLElement* item …
Run Code Online (Sandbox Code Playgroud)

c++ xml tinyxml2

3
推荐指数
1
解决办法
2万
查看次数

在C++项目中使用tinyXml2

我是tinyXml2的新手.我正在尝试解析xml文件并在根标记中打印文本.这是我的代码.

#include<stdio.h>
#include "tinyxml2.h"

using namespace std;

int main()
{
    XMLDocument doc;
    doc.LoadFile("input.xml");
    const char *title = doc.FirstChildElement("root")->GetText();
    printf("%s\n", title);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在建立这个我得到一个错误说XMLDocument was not declared in this scope.

问题是什么?

c++ tinyxml2

1
推荐指数
1
解决办法
4163
查看次数

为什么我在C++中使用tinyXML2获取NULL指针?

我是XML解析商务的新手.很抱歉愚蠢的问题.

我想浏览我的XML:

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
      <author>Gambardella, Matthew</author>
      <title>XML Developer's Guide</title>
      <genre>Computer</genre>
      <price>44.95</price>
      <publish_date>2000-10-01</publish_date>
      <description>An in-depth look at creating applications 
      with XML.</description>
   </book>
   <book id="bk102">
      <author>Ralls, Kim</author>
      <title>Midnight Rain</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-12-16</publish_date>
      <description>A former architect battles corporate zombies, 
      an evil sorceress, and her own childhood to become queen 
      of the world.</description>
   </book>
   <book id="bk103">
      <author>Corets, Eva</author>
      <title>Maeve Ascendant</title>
      <genre>Fantasy</genre>
      <price>5.95</price>
      <publish_date>2000-11-17</publish_date>
      <description>After the collapse of a nanotechnology 
      society in England, the young survivors lay the 
      foundation for a new …
Run Code Online (Sandbox Code Playgroud)

c++ tinyxml2

1
推荐指数
1
解决办法
186
查看次数

标签 统计

c++ ×8

tinyxml2 ×8

xml ×4

tinyxml ×1