简体   繁体   English

使用C从XML文件读取数据

[英]Reading data from an XML file using C

This is follow-up to: using xslt to create an xml file in c 这是后续: 使用xslt在c中创建xml文件

<element1 type="type1" name="value1">
  <start play="no"/>
  <element2 aaa="AAA"/>
  <element2 bbb="BBB"/>
  <element3 ccc="CCC">
     <element4/><!-- play="no"/>-->
  </element3>
</element1>

Lets say I get this xml file, how do I read individual nodes? 让我说我得到这个xml文件,我如何读取单个节点? I mean, not all nodes are mandatory. 我的意思是,并非所有节点都是必需的。 Do I need to go though all nodes via "libxml2" or something similar and read its values? 我是否需要通过“libxml2”或类似的东西浏览所有节点并读取其值? OR I can use some sort of schema to define what my xml can look like? 或者我可以使用某种模式来定义我的xml可能是什么样子? What is a better way of dealing with this problem? 处理这个问题的更好方法是什么?

A schema is never a bad idea, however it won't help you read the xml as such. 架构从来都不是一个坏主意,但它不会帮助您读取xml。 All schema would do given you validate the xml against it is tell you it follows whatever rules are in there. 所有模式都会在你对xml进行验证时告诉你它遵循那里的任何规则。 For the rest of it, a quick search on here would have found this. 对于其余部分,在这里快速搜索会发现这一点。 How can libxml2 be used to parse data from XML? libxml2如何用于解析XML中的数据?

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

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