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