简体   繁体   中英

C++ What is the most efficient way of reading XML files?

I'm quite interested in trying to figure out how to read XMLfiles as it seems like the optimal way to create levels for my video game. I am using a program called pyxel edit to design the levels and I can export the sprite sheet as an XML.

  • It's a 2d sprite sheet so the x value indicates the sprites position on the x axis and the y value indicates the sprites position on the y axis.
  • List item

The output looks like this:

<tilemap tileswide="2" tileshigh="2" tilewidth="16" tileheight="16">
   <layer number="0" name="Layer 0">
      <tile x="0" y="0" index="0" rot="0" flipX="false"/>
      <tile x="1" y="0" index="1" rot="0" flipX="false"/>
      <tile x="0" y="1" index="2" rot="0" flipX="false"/>
      <tile x="1" y="1" index="3" rot="0" flipX="false"/>
   </layer>
</tilemap>

I started out by learning javascipt and C# for Unity3D but I never found myself in a situation where XML would be useful.

Any good online resources I can use to improve my understanding of it?

It would also help me out greatly if anyone has the time to provide an example on how to read this but that is only if you have the time to do so. If not then I'll work with any resources I find :)

Use an existing library.

A popular one is TinyXML-2 , which is trivial to include as a dependency (single .cpp file + header), is fast, and easy to use.

You can find an example in the on-line documentation.

For parsing XML files, maybe boost library is a very nice choice. It is convenient to parse the XML files. For more details, click boost/property_tree/xml_parser.hpp . I hope this can help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM