【发布时间】:2021-07-14 09:47:00
【问题描述】:
我对 C++ 中的 XML 解析非常陌生。我想解析 XML。所以,我正在使用 PugiXML 库。我主要想从每个子节点中获取值。
这里是我写到这里的示例代码,然后我不明白下一步该做什么。
void XML()
{
//Suppose I'm getting XML data in the form of a string, and store in string variable **xmlString**
//Using 3rd party lib Pugixml parser want to store all the **xmlString data in doc**.
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_string(xmlString.c_str());
// I want value will store the data "Sheet1" as per the syntax. But somehow, doc store the value till here **<?xml version = "1.0" encoding = "UTF-8"?><Graphics**
string value = doc.child("Graphics").child("SheetInfo").attribute("SheetName").value();
}
这是存储在 xmlString 中的示例 XML 数据。
<?xml version = "1.0" encoding = "UTF-8"?>
<Graphics>
<SheetInfo>
<SheetName>Sheet1</SheetName>
<Circle>
<IGDSElement>
<Type>89</Type>
</IGDSElement>
<cPt_x>0.212050</cPt_x>
<cPt_y>0.148307</cPt_y>
<orientation>0</orientation>
</Circle>
<SheetInfo>
<Graphics>
请帮我在去每个节点时解析这个 XML 格式的数据。
【问题讨论】:
标签: c++ xml unit-testing xml-parsing pugixml