Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ XML WindowsForms
Hello, I have been struggling with this for a while so I request a little help.
I am working on an application, with which I'm almost finished.
I just need to parse some things into XML file and from it.
I have tried using tinyxml and tinyxml2, rapidxml and so, but I have failed to use them inside my project.
I have tried to use various other options, but I also failed.
I don't have precompiled headers so that can't be problem, I also have required linkers linked.
 
I am trying to save a simple string from textBox1 to line 1 in XML file with button1_Click, replace if exists,
and also to load line 1 string from XML file with button2_Click and show it in textBox1.
 
I have no idea where to head now...
my head is already exploding, and it seems that every XML library and solution isn't related to Windows Forms Applications, or I am doing something wrong with it.
Posted 19-Feb-13 13:32pm
Comments
Sergey Alexandrovich Kryukov at 19-Feb-13 18:35pm
   
How about just reading documentation? Search in MSDN?!
 
Now, how is XML parsing is related to Forms, or any other UI? Ever heard of separation of concerns?!
—SA
Sergey Alexandrovich Kryukov at 20-Feb-13 11:49am
   
Is it .NET forms application and C++/CLI, or something else?
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Don't use those 3rd party codes! Everything is done for you in .NET FCL:
 
  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2.  
  3. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  4.  
  5. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].
 
—SA
  Permalink  
Comments
Quirkafleeg at 20-Feb-13 6:24am
   
My vote of 3.
This is fine if you are using the abominable (in my opinion) Managed C++, but they have no use if you using "proper" C++. Remember that the "Windows Forms application" could be relating to MFC and the asker could still be using VC++6!
Sergey Alexandrovich Kryukov at 20-Feb-13 11:47am
   
I am using?! Sorry, did you think well before saying so?
 
To me "Windows Forms application" can only be legitimately related to .NET and hence C++/CLI. This is how I understood.
Anyway, your vote is not valid until we have clarification from the user (as well as my answer, may be).
 
Abominate or not: I'm not using it, OP does (you question it, all right). I respect your opinion, but there are others. I personally think that C++ ("classical", and mind you, I know it well) is the biggest harm to industry, so what, not answering C++ questions.
 
I don't care how you vote, but your logic is questionable... :-)
Of course, if this is MFC and C++, I'll remove this answer.
 
Anyway,
—SA
Quirkafleeg at 21-Feb-13 3:22am
   
Fair points
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The solution by Sergey Alexandrovich Kryukov should be fine for linking with Managed C++.
 
There are 3 that I know of which seem to support the use of xsds (does anyone still think CDATA sections are the best solution?). If you don't need schema validation, then you can ignore the next bit:
 
xerces
This is big and fairly awkward to learn without samples (thankfully, there are many in googleland), but is probably the most feature-rich and free parser you can get.
 
libxml2
This is a nightmare if you look at the rather appalling on-line help and lack of samples beyond the most basic. As expected from this little rant - it is a Linux library. I haven't looked, but there may be a port.
 
msxml
This was a more common way to parse xml in MFC applications. It was COM based and does have 64-bit support. I have never actually used it, but as a "mature" Microsoft library, there should be a fair amount of help on-line.
 
--
 
Alternatively, there are a few less "bloated" xml parsers right here on codeproject:
CXMLFile - A Simple C++ XML Parser[^]
Simple C++ XML Parser[^]
If you search codeproject, there will be plenty more.
 
From your description, it sounds like you are trying to find something that is a 1-click solution that does everything for you. Maybe I am wrong about this, but with xml parsers, you have to do some coding yourself. The most simple parsers usually demand the following at a minimum when parsing:
a) load an xml file/string data into the parser
b) run the parser
c) read the output
Some parsers will build a nice set of objects for you that you can read, while others are more involved, i.e. you have to move the parsed data into objects you have written yourself.
 
I have used tinyxml myself and found it to be ok - it worked fine. Perhaps you could explain why your used xml parsers actually failed?
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 295
1 OriginalGriff 285
2 Sergey Alexandrovich Kryukov 157
3 Afzaal Ahmad Zeeshan 154
4 Peter Leow 115
0 OriginalGriff 7,510
1 DamithSL 5,494
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 20 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100