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>Answer1:
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>