简体   繁体   English

C ++读取XML文件最有效的方法是什么?

[英]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. 我对尝试弄清楚如何读取XMLfile很有兴趣,因为这似乎是为视频游戏创建关卡的最佳方法。 I am using a program called pyxel edit to design the levels and I can export the sprite sheet as an XML. 我正在使用一个名为pyxel edit的程序来设计关卡,并且可以将精灵表导出为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. 这是一个2d的精灵图片,因此x值表示精灵在x轴上的位置,而y值表示精灵在x轴上的位置。
  • 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. 我从学习Unity3D的javascipt和C#开始,但是我从未发现自己会遇到XML有用的情况。

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. TinyXML-2是流行的一种,它很容易包含为依赖项(单个.cpp文件+头文件),并且快速且易于使用。

You can find an example in the on-line documentation. 您可以在在线文档中找到示例

For parsing XML files, maybe boost library is a very nice choice. 对于解析XML文件,也许boost library是一个很好的选择。 It is convenient to parse the XML files. 解析XML文件很方便。 For more details, click boost/property_tree/xml_parser.hpp . 有关更多详细信息,请单击boost / property_tree / xml_parser.hpp I hope this can help you. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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