1

私は tinyxml2 を使用しており、XML のいくつかの要素を C++ で解析したいと考えています。例えば

<root>
     <First x="1" y="2">
     <Second x = "1">
     <Second y = "2">
</root>

「Second」要素の x のみを解析できます。

#include <stdio.h>
#include "tinyxml2.h"
#include <iostream>
#include <string>
#include <iomanip>
using namespace tinyxml2;
using namespace std;
int main(){
     tinyxml2::XMLError eResult = xml_doc.LoadFile("test.xml");
     if (eResult != tinyxml2::XML_SUCCESS) return false;

     tinyxml2::XMLNode* root = xml_doc.FirstChildElement("root");
     if (root == nullptr) return false;

     tinyxml2::XMLElement* First = root->FirstChildElement("First");
     if (First == nullptr) return false;

     double x1 = std::stod(First->Attribute("x"));
     double y1 = std::stod(First->Attribute("y"));

     tinyxml2::XMLElement* Second = root->FirstChildElement("Second");
     if (Second == nullptr) return false;

     double x2 = std::stod(Second->Attribute("x"));
     double y2 = std::stod(Second->Attribute("y"));

     system("pause");
}

「First」要素または「Second y」に対して同じ方法を試していると、エラーが表示されます。私は何をすべきか?

4

1 に答える 1