64703

Reading an XML using libxml2

Question:

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>

Recommend

  • How to access different domain data using Java script
  • Disable specific items
  • Protecting API URL Data from being seen. cURL?
  • cypher how get relation between every two node and the distance from start node?
  • How can you retrieve a full nested document in Solr?
  • other option at place of tag
  • Can I create EventListener in AS3 from one Object and remove it from another Object?
  • Using extern @class in order to add a category?
  • Replace and retrieve placeholder value
  • Generating anchors with PyYAML.dump()?
  • Getting error java.io.FileNotFoundException (log4j log file) at the time of publish project on cloud
  • Portable JRE on Linux - possible?
  • Configure Spring's MappingJacksonHttpMessageConverter
  • Flash radiobutton: how do I get the selected radiobutton?
  • Setting the run time properties on SpringApplicationBuilder()
  • How to autopopulate a field in SugarCRM form
  • C++ pointer value changes with static_cast
  • Django simple Captcha “No module named fields” error
  • Marklogic : Query response time is very high
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • Using jQuery closest() method with class selector
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Array.prototype.includes - not transformed with babel
  • C# - Serializing and deserializing static member
  • Bug in WPF DataGrid
  • Incrementing object id automatically JS constructor (static method and variable)
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • python regex in pyparsing
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Suggestions to manage Login/Logout transitions
  • coudnt use logback because of log4j
  • Easiest way to encapsulate a HTML5 webpage into an android app?
  • Busy indicator not showing up in wpf window [duplicate]
  • costura.fody for a dll that references another dll
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal