0

I want to modify an XML file which has a very complicated structure something like

<root>
<a></a>
<b></b>
<c></c>
<d>
   <e>text</e>
   <f>text</f>
<d>
<d>
....
</root>

I tried to use tinyxml and it is good but there are some comments in the source xml file that I want to keep so I thought may be dealing with the file as mere text can be a good idea, however the string functions in c++ are crippling me because I'll have to search and replace, any ideas?

Note:There are no attributes in the XML, just values between the tags.

Poka Yoke
  • 373
  • 3
  • 8
  • 27

1 Answers1

0

I don't know if using a third party library is off the table for parsing but I've been using this XSD parser which allows you to serialize XML files to memory. You are then free to edit and/or read the values at their node locations and then write the file back out.

This, to me, at least, is significantly simpler than generating a custom parser for each type of XML input.

Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47
  • I would like to keep it as simple as possible;since all what I need to do is modify some values only. Moreover, I wonder if XSD will allow me to preserve the comments in the file too – Poka Yoke Jun 17 '13 at 15:43
  • @PokaYoke I *think* it will preserve the comments, I've never tried, but it's a nice little science project for you to try. XSD is very easy to use and you can be up serializing data in less than 10 minutes. – Tyler Jandreau Jun 17 '13 at 15:45
  • Which is better in my case do you think, the parser mapping or the tree mapping? – Poka Yoke Jun 17 '13 at 16:31
  • Honestly it depends on the XML file. The tree parser holds the whole XML in memory. The stream parser is used for larger XML files. I prefer the tree parser. – Tyler Jandreau Jun 17 '13 at 17:18
  • 1
    @TylerJandreau You might want to mention that Codesynthesis XSD needs an XML Schema as input. – Erik Sjölund Sep 06 '13 at 14:24