简体   繁体   中英

Reading data from an XML file using C

This is follow-up to: using xslt to create an xml file in c

<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? I mean, not all nodes are mandatory. Do I need to go though all nodes via "libxml2" or something similar and read its values? OR I can use some sort of schema to define what my xml can look like? 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. All schema would do given you validate the xml against it is tell you it follows whatever rules are in there. For the rest of it, a quick search on here would have found this. How can libxml2 be used to parse data from XML?

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