如何将 xml 粘贴到 C++ (小XML)
我目前正在开发一个 C++ 项目,我需要从 xml 文件中读取一些内容,我发现tinyxml接缝是可行的方法,但我仍然不知道到底该怎么做。< br> 另外,我的 xml 文件有点棘手,因为对于每个需要使用它的用户来说,它看起来都有点不同。
我需要读取的 xml 文件如下所示
<?xml version="1.0" encoding="utf-8"?>
<cloud_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx xmlns:d="http://www.kuju.com/TnT/2003/Delta" d:version="1.0">
<cCareerModel d:id="154964152">
<ScenarioCareer>
<cScenarioCareer d:id="237116344">
<IsCompleted d:type="cDeltaString">CompletedSuccessfully</IsCompleted>
<BestScore d:type="sInt32">0</BestScore>
<LastScore d:type="sInt32">0</LastScore>
<ID>
<cGUID>
<UUID>
<e d:type="sUInt64">5034713268864262327</e>
<e d:type="sUInt64">2399721711294842250</e>
</UUID>
<DevString d:type="cDeltaString">0099a0b7-e50b-45de-8a85-85a12e864d21</DevString>
</cGUID>
</ID>
</cScenarioCareer>
</ScenarioCareer>
<MD5 d:type="cDeltaString"></MD5>
</cCareerModel>
</cloud_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
现在该程序的目标是能够插入一些字符串(通过变量)并搜索相应的“cScenarioCarrer d:id”并读取“IsComplete”和“最佳成绩”。
这些字符串稍后需要在我的程序中使用,但我可以处理。
我的问题是
A. 如何搜索特定的“cScenarioCareer”ID
B. 如何将“IsComplete”和“BestScore”粘贴到程序中的某些变量中。
注意:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 字符串对于每个用户都是唯一的,因此请记住它可以是任何内容。
如果有人愿意帮助我,我会非常感激,谢谢。
附言。我想对我在这里所做的事情有某种理解,尽管“将此代码粘贴到您的程序中”答案是可以接受的,但我认为如果您能告诉我它是如何以及为什么工作的,那就更好了。
I'm currently working on a project in C++ where I need to read some things from a xml file, I've figured out that tinyxml seams to be the way to go, but I still don't know exactly how to do.
Also my xml file is a little tricky, because it looks a little different for every user that needs to use this.
The xml file I need to read looks like this
<?xml version="1.0" encoding="utf-8"?>
<cloud_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx xmlns:d="http://www.kuju.com/TnT/2003/Delta" d:version="1.0">
<cCareerModel d:id="154964152">
<ScenarioCareer>
<cScenarioCareer d:id="237116344">
<IsCompleted d:type="cDeltaString">CompletedSuccessfully</IsCompleted>
<BestScore d:type="sInt32">0</BestScore>
<LastScore d:type="sInt32">0</LastScore>
<ID>
<cGUID>
<UUID>
<e d:type="sUInt64">5034713268864262327</e>
<e d:type="sUInt64">2399721711294842250</e>
</UUID>
<DevString d:type="cDeltaString">0099a0b7-e50b-45de-8a85-85a12e864d21</DevString>
</cGUID>
</ID>
</cScenarioCareer>
</ScenarioCareer>
<MD5 d:type="cDeltaString"></MD5>
</cCareerModel>
</cloud_xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx>
Now the goal of this program is to be able to insert some string (via. a variable) and serch for the corresponding "cScenarioCarrer d:id" and read the "IsComplete" and the "BestScore".
Those strings later need to be worked with in my program, but that I can handle.
My questions here are
A. How do I go by searching for a specific "cScenarioCareer" ID
B. How do I paste the "IsComplete" and "BestScore" into some variables in my program.
Note: The xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx string is unique for every user, so keep in mind it can be anything.
If anyone out there would like to help me, I'd be very graceful, thank you.
PS. I'd like to have some kind of understanding for what I'm doing here, all though "paste this code into your program" answers are acceptable, I think it would be much better if you can tell me how and why it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您是在 C++ 中执行此操作,因此我将使用 ticpp 接口来制作此示例
TinyXml 可从 ticpp.googlecode.com 获取。
假设:
标签和多个
标签。
包含一个
标记,该标记又包含一个
标记我还假设您有一个上下文变量某处包含一个指向
标签,如下所示:这是一个函数,它将定位 cScenarioCareer 的 ticpp::Element
给定的 ID。
然后,要获取您想要的信息,您需要执行以下操作:
当然,我还没有编译或测试任何这些,但它应该给您这个想法。
Since you're doing this in C++ I'll make this example using the ticpp interface to
TinyXml that available at ticpp.googlecode.com.
Assumptions:
<cloud>
tag and multiple<cCareerModel>
tags.<cCareerModel>
contains a single<ScenarioCareer>
tag which in turn contains a single<cScenarioCareer>
tagI'll also assume that you have a context variable somewhere containing a pointer to the
<cloud>
tag, like so:Here's a function that will locate the ticpp::Element for the cScenarioCareer with
the given ID.
Then to get at the information you want you'd do something like:
Naturally I haven't compiled or tested any of this, but it should give you the idea.