开发者

std::string xml string to object

What woul开发者_如何转开发d be the most effective way to take an XML string of type std::string and convert it to an in-memory XML object, the object structure is of no importance, what I'm after is whether I'd need to go through the string char by char and pick out all the pieces or if there is some easier way?


The easiest way is probably to use a library to do that.

If you want to do that yourself, you'll need to parse the string containing XML code. There are many ways to do that; easiest is probably a recursive-descent parser.


Take a look at Arabica: http://www.jezuk.co.uk/cgi-bin/view/arabica Of all XML libraries/wrappers I am aware of it is most std friendly.


Try Expat, compact, user-friendly and free: http://expat.sourceforge.net/


You could use MSXML for this, it will take the string and produce a DOM (Document Object Model) representation. Documentation is OK but this is not the easiest library to use. WIndows only of course.

Pros - reliable, widely used. Cons - you have to learn COM programming model to a degree. Not the most intuitive to use.

A simpler option would be xerces. Sample file parse code here, there are other samples as well. I've used both this and MSXML in different jobs.


Use libxml2. Not a highly complicated library and easy to use. Portable, written in C but bindings to other languages available, and loads of examples to use and learn from.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜