Reading Configuration xml files in C++

11,925

Solution 1

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?

Solution 2

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.

Share:
11,925
softwarematter
Author by

softwarematter

C++, Java, C#, ASP.NET

Updated on June 08, 2022

Comments

  • softwarematter
    softwarematter almost 2 years

    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
    softwarematter over 13 years
    Well, it is an academic project and using third party libraries is prohibited :-(
  • darioo
    darioo over 13 years
    Boost is a 3rd party library, so your answer won't be of much help to OP.
  • Nawaz
    Nawaz over 13 years
    @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
  • DumbCoder
    DumbCoder over 13 years
    @iJeeves - Then write your own parser. See the library and start copying code with utmost care.
  • Joe Doliner
    Joe Doliner over 13 years
    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
    Joe Doliner over 13 years
    @DumbCoder that's pretty troll advice considering it's an academic project clearly governed by strict plagiarism rules.
  • user562374
    user562374 over 13 years
    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.
  • DumbCoder
    DumbCoder over 13 years
    @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.
  • Searock
    Searock almost 13 years
    Thanks a lot for suggesting TinyXml. I have used it in one of my assignment project.