XML : Reading out XML serves unexpected output in C++

I have a question about reading from a XML file.

My XML File:

  <?xml version="1.0" encoding="UTF-8"?>      <level>         <terrain name="terrain" mesh="terrain.x" texture="terrain.bmp" position="011"></terrain>         <skybox name="skybox" mesh="skybox.x" left="left.jpg" right="right.jpg" bottom="bottom.jpg" top="top.jpg" back="back.jpg" front="front.jpg" position="111"></skybox>         <entity name="tiger" mesh="tiger.x" texture="tiger.bmp" position="000"></entity>  </level>    

My code:

  rapidxml::xml_document<> doc;  rapidxml::xml_node<>* root;    std::ifstream file("level\\noob.xml");        std::vector<char> buffer((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());      buffer.push_back('\0');        doc.parse<0>(&buffer[0]);        root = doc.first_node("level");        for (rapidxml::xml_node<>* terrain = root->first_node("terrain"); terrain; terrain = terrain->next_sibling())      {          std::cout << terrain->first_attribute("name")->value() << std::endl;      }    

So I only want to print the name of the terrain. But the outcome when running is this:

  terrain  skybox  tiger    

I check for the node "terrain" but it still prints the nodes "skybox" and "tiger". How?

No comments:

Post a Comment