Click here to Skip to main content
15,893,904 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Comments
Sergey Alexandrovich Kryukov 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 20-Feb-13 11:49am    
Is it .NET forms application and C++/CLI, or something else?
—SA

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?
 
Share this answer
 
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. 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[^].
  3. 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
 
Share this answer
 
Comments
Quirkafleeg 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 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 21-Feb-13 3:22am    
Fair points

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900