Need to write some C++ code that reads XML string and if i do
something like:
get valueofElement("ACTION_ON_CARD") it returns 3
get valueofElement("ACTION_ON_ENVELOPE") it returns YES
XML String:
<ACTION_ON_CARD>3</ACTION_ON_CARD>
<ACTION_ON_ENVELOPE>YES</ACTION_ON_ENVELOPE>
Any code example would be helpfull
Thanks
writing an xml parser is not necessarily an easy thing to do, so unless it is a requirement you do it yourself I suggest you get a library to do that for you.
There are many available like xerces (pretty complete but not exactly simple), tinyxml (mostly the opposite of xerces, it probably suits best your needs) or libxml (never tried this one)
If you have the schema, you could use codesynthesis xsd compiler.
I recommend the XML parser from the Poco C++ library. It's well documented and easy to use.
Related
I have an xml file to be parsed for the information contained to be further used. Can anyone help me with the xerces C++ code for parsing it? I have the xml creation code using xerces library as well in C++.
Maybe this doesn't help you much if you're already committed to xerces, but I'd recommend using pugixml instead. It's very easy to integrate, is very performant and has excellent documentation. I built a rather large project using it and had nothing but good experiences with it. It's of the nicest libraries I've ever used. (I'm not affiliated with them; just very happy).
Here is the documentation on parsing files: http://pugixml.googlecode.com/svn/tags/latest/docs/manual/access.html
I'm looking for an XML library that writes out the XML stream as it goes. I've looked at TinyXML, pugixml, etc. and it seems these only write the stream when the entire DOM is built in memory. I want a library that will write each object as soon as all children and attributes are available. Is there such a thing?
The word you're looking for is SAX.
Xerces is one such C++ SAX library. If you're in the MS world then MSXML supports SAX2 too.
I wrote my own library in the end. I'm willing to share the source if it's of interest to anyone - it's a little clunky and minimal though.
I'm writing a native C++ project and I need a simple XML parser/writer. I already know XmlDocument in C#, so something similar could be quite good, but if there isn't, does anyone know a quick-to-use XML parser/writer?
I'm trying to shorten my "learning of the library" time to minimum.
Thanks!
There are quite a few you can consider:
Xerces
TinyXML
libxml++
Expat Xml
XmlLite
I've used TinyXML, and it's worked reasonably well for what I've needed. My needs weren't terribly demanding though. At least when I used it, it didn't deal with DTD/XSD at all, so if you need to handle those it's probably not an option.
I ended up using RapidXML (http://rapidxml.sourceforge.net/).
For me, its intuitive, and was really easy to learn.
No body recommended it so I added my own answer :-\ ...
Any recommendations for XML generators in C++?
There are quite a few XML generators for C++. Some of them work with DOM, others can serialize your classes, and yet others work in even more different ways, like Boost.PropertyTree. Whichever you should choose, depends entirely on your requirements.
If you need to write a small set of data to an XML file (and may also want to write this data to other formats in the end), consider using Boost.PropertyTree. If you want to serialize C++ classes to XML, or make C++ class representation of XSD Schemas, consider using a binding generator such as CodeSynthesis XSD. And if you just want to manipulate the XML directly, you can use a DOM parser/writer like the cross-platform Xerces C++.
MSXML is a sensible option if you're limiting your application to Windows.
Xerces could prove useful if you're wanting to write code that can be ported to other platforms.
I'm sure there are a few that exist already, but if one were inclined to implement their own it would be an easy task using Boost.Spirit.Karma.
I have requirement where we have to read a small XML file on Linux. Our application is in C++ and I like to use any light weight XML library. Please suggest me the library.
Thanks
You can Try pugixml Light-weight, simple and fast XML parser for C++
As a 2nd option look at TinyXML
Have a look also at TinyXml (http://sourceforge.net/projects/tinyxml). It is extremely lightweight and for this reason it is used also in mobile and game programming. The API is minimal though so you have to evaluate if it fully satisfy your needs.
This xml parser is good
There is xerces-c for that. It's complete, but I don't know if you will find it small enough. Your question is relative to what?