4

How can the following configuration file be read in C++. Is there any support in STL. I can't afford to use other 3rd party libraries.

<?xml version="1.0" encoding="utf-8"?> 
<appSettings>
    <add key="FileType" value="doc"/>  
    <add key="FileLength" value="102234"/>   
</appSettings>

I am not using managed C++.

softwarematter
  • 28,015
  • 64
  • 169
  • 263
  • "I can't afford to use other 3rd party libraries" <-- WRONG. Why can't you? – Arafangion Jan 26 '11 at 08:44
  • 6
    You don't need to afford any library. All of them are free. – DumbCoder Jan 26 '11 at 08:46
  • 6
    It's the opposite for those of us who code for a living: We can't afford to _not_ to use 3rd-party libraries. – sbi Jan 26 '11 at 08:49
  • I've worked at plenty of places that don't allow any third party code in their products. Sometimes, they just want you to brew your own, or be clever in where you steal it from. – StarPilot Jul 12 '16 at 21:52

3 Answers3

8

I suggest to use TinyXML in this case. It's a very very small XML reader, sufficiently sophisticated to parse your quoted XML document correctly. It's just two or three C++ source files which you can directly compile into your application. It has no external dependencies except the standard library and the STL.

Frerich Raabe
  • 90,689
  • 19
  • 115
  • 207
6

STL has no support for parsing xml. If you're determined not to use a third party library then your only other option is to write a parser by hand, this seems like a pretty bad idea. Why exactly can't you afford to use third party libraries?

Joe Doliner
  • 2,058
  • 2
  • 15
  • 19
  • Well, it is an academic project and using third party libraries is prohibited :-( – softwarematter Jan 26 '11 at 08:45
  • @iJeeves - Then write your own parser. See the library and start copying code with utmost care. – DumbCoder Jan 26 '11 at 08:52
  • I see, well I would appeal that if I were you on the grounds that this is the sort of thing that it's a good practice to use third party plugins for. On the other hand. How complicated is this configuration file? If the example you gave is the actual config file then xml is kind of overkill. You could pretty easily whip something up to do that. – Joe Doliner Jan 26 '11 at 08:55
  • 3
    @DumbCoder that's pretty troll advice considering it's an academic project clearly governed by strict plagiarism rules. – Joe Doliner Jan 26 '11 at 08:57
  • 2
    That sounds more like group homework/project than a real academic project with subsequent publication, because people really have better things to do than rewrite XML parsers. – user562374 Jan 26 '11 at 09:20
  • @Joe Doliner - Care clarifying what is troll in there ? The OP doesn't want any 3rd libraries. And the only option is he writes his own parser. He can get inspiration from the already existing libraries and start copying/modifying according to his requirements. Copying also is quite difficult if you don't understand what is happening in the code, so take utmost care. – DumbCoder Jan 26 '11 at 09:46
0

This is a link from a similar topic on StackOverflow
Using Boost to read and write XML files Which also recommends Tiny like Frerich Raabe recommended.

Community
  • 1
  • 1
seanb511
  • 3
  • 2
  • Boost is a 3rd party library, so your answer won't be of much help to OP. – darioo Jan 26 '11 at 08:48
  • 1
    @darioo: I think Boost is a 2nd party library, as it's very very very close to C++.. in fact so so close that many of it's techniques is included in C++0x. :D – Nawaz Jan 26 '11 at 08:51