阅读使用的libxml2的XML [英] Reading an XML using libxml2

查看:215
本文介绍了阅读使用的libxml2的XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用libxml2.so解析Linux平台上用C XML文件中。我有我的XML格式如下所述。我可以有任意数量的文件帐户。我使用的libxml在第一次之后有人建议我在论坛上。我能够分析我只有一个帐户的文件。我明白DONOT我如何实施,如果我有一个以上的账户。任何人都实施这样的事情之前,C,libxml的Linux上。

 <账户>
  <&account_no上GT; 123 LT; / account_no上>
  <名称> XYZ< / XYZ>
  <州与GT; GA< / STATE>
< /账户><账户>
  <&account_no上GT; 223 LT; / account_no上>
  <名称> ABC< / XYZ>
  <州与GT; FL< / STATE>
< /账户>


解决方案

每XML的定义,如果你有以上<帐户>就是你需要周围的标签F.E. <帐户>周围的所有的<帐户>标签都有效。

如果你有,你可以去到孩子,你可以在()在 - >下一个节点

EDITH:我想你使用DOM-潜行。但是,如果你有很多的&LT(!);帐户> S,你应该向型开关SAX对内存的原因。 DOM构建(D)ocument完整的(M)apping在内存(O)bjects。

在SAX,你建立一个状态机,而文件/内存的读取完成后,每一个开始标记和结束标记和数据被触发。

EDITH 2:如果你必须找到一个特殊的价值,你应该考虑把键值(account_no上?)到像℃的属性;开户无=123>< NAME>< XYZ>< STATE> FL< / STATE>< /帐户>

I'm using libxml2.so to parse XML file in C on LINUX platform. I have my XML in the format as mentioned below. I can have any number of accounts in the files. I'm using libxml for the first time after someone suggested me on forum. I'm able to parse the file I had only one account. I donot understand how do I implement if I have more than one account. Anyone implemented such thing before in C,libxml on Linux.

<ACCOUNT>
  <ACCOUNT_NO> 123 </ACCOUNT_NO>
  <NAME> XYZ </XYZ>
  <STATE> GA </STATE>
</ACCOUNT>

<ACCOUNT>
  <ACCOUNT_NO> 223 </ACCOUNT_NO>
  <NAME> ABC </XYZ>
  <STATE> FL </STATE>
</ACCOUNT>

解决方案

per XML-Definition, if you have more < ACCOUNT>s you need a surrounding tag f.e. < ACCOUNTS> around all the < ACCOUNT>-tags.

if you have that, you can go "into" the child, and you can while() over the ->next nodes.

EDITH: i suppose you use the DOM-modell. But if you have many (!) < ACCOUNT>s, you should swith to SAX for memory reasons. DOM builds a complete (M)apping of the (D)ocument to (O)bjects in memory.

In SAX, you build a state machine, which is triggered while the reading of the file/memory is done, for every starting tag and ending tag and data.

EDITH 2: if you have to find a special value you should consider to put the key-value (account_no?) into an attribute like < ACCOUNT no="123"> < NAME>< XYZ> < STATE>FL< /STATE> < /ACCOUNT>

这篇关于阅读使用的libxml2的XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆