3 Replies - 580 Views - Last Post: 09 July 2012 - 07:36 AM Rate Topic: -----

#1 Eowyn27  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 150
  • Joined: 17-October 11

How to implement a class that reads xml files and sorts it using C++

Posted 08 July 2012 - 06:01 AM

Basically, I have to write a header file and an implementation file that will take an xml file (in my case a file that includes the titles, dates, authors of several books), extra the useful information I listed previously and sorts them into a data structure (into a private data member). I was told using Vectors would be a good idea but I've never used any vectors before. I was wondering 1) Why vectors over linked lists? 2) If there's a sample source code I can look over to make sure I'm writing the code correctly. That is, how do I even include an .xml file for c++ to read and then extract useful data?

Thanks

edit: Oh I might have to use a parser like TinyXML but I'm not sure yet how to use it. Any good resources for it?

This post has been edited by Eowyn27: 08 July 2012 - 06:07 AM


Is This A Good Question/Topic? 0
  • +

Replies To: How to implement a class that reads xml files and sorts it using C++

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2517
  • View blog
  • Posts: 4,001
  • Joined: 21-June 11

Re: How to implement a class that reads xml files and sorts it using C++

Posted 08 July 2012 - 06:09 AM

1) Unless you specifically need to insert nodes at a specific position in the list (not at the end) to which you already have an iterator, using a vector will be much faster than using a linked list in the vast majority of cases.

2) That depends on which XML library you're planning on using. Most XML libraries will include sample codes of how to use them in their documentation.

This post has been edited by sepp2k: 08 July 2012 - 06:10 AM

Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: How to implement a class that reads xml files and sorts it using C++

Posted 08 July 2012 - 07:16 AM

I use libxml2 to parse the DIC RSS feed in C++ in this blog post. Perhaps it might be helpful. As to TinyXML, have you tried reading the documentation and tutorial?
Was This Post Helpful? 0
  • +
  • -

#4 Eowyn27  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 150
  • Joined: 17-October 11

Re: How to implement a class that reads xml files and sorts it using C++

Posted 09 July 2012 - 07:36 AM

View PostJackOfAllTrades, on 08 July 2012 - 07:16 AM, said:

I use libxml2 to parse the DIC RSS feed in C++ in this blog post. Perhaps it might be helpful. As to TinyXML, have you tried reading the documentation and tutorial?


I was wondering, how do I search through the XML Catalog/file I have and insure that for each element, there is something. If the element is empty, I want to proceed to the next item. Kind of like While (TiXMLelement !=NULL) { //code with getText() }. Is that alright or do I have to be specific for each element that it accesses?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1