0

I am being tasked to essentially write a potentially enormous function in C++ that deals with searching and writing to an XML file.

Is there a way in C++ to search through an XML file, either as an xml file or just raw text, take in a path and write a record at the end of that path. For example:

<File>
    <Record>
        <Name>Joe</Name>
        <Age>52</Age>
    </Record>
</File>

The function would search for the end of the latest record, then insert a line for a new Record, then next go through the loop, it finds the new record tag, inserts the name, then next time it inserts the age, then it closes the Record tag.

Any ideas or sources that could be helpful for this level of manipulation? Tips on how it should go?

To those calling this a duplicate, allow me to add that I cannot use a 3rd party DLL. I have to code everything on my own.

user3215251
  • 239
  • 1
  • 16
  • Duplicates: http://stackoverflow.com/questions/9387610/what-xml-parser-should-i-use-in-c, http://stackoverflow.com/questions/170686/best-open-xml-parser-for-c, – JBentley May 23 '14 at 12:15
  • Not a duplicate. All of those link to using 3rd Party DLLs. I am not allowed to use those. – user3215251 May 23 '14 at 12:24
  • 2
    You do not have to link to third party libraries dynamically (DLLs). However, if you must write your own code, then what exactly is it you're asking? "is there a way in C++" is a pointless question - of course there is a way, otherwise there would be no third party libraries to do it. If you want a detailed understanding of it, then read the XML specification and/or look at the source of the various C++ XML libraries. If you want help here, you need to ask an actual specific question. – JBentley May 23 '14 at 12:26

1 Answers1

3

Use boost::property_tree it can handle XML and is quite nice in my opinion.

http://www.boost.org/doc/libs/1_41_0/doc/html/boost_propertytree/tutorial.html should give you a hint. I've written a small project using it and it was useful. There are other parsers like tinyXML which is also quite good.

clambake
  • 772
  • 4
  • 15