开发者

C++ XML library for use under Windows

Under Windows to parse XML one can use the COM based XML API but I wondered if there is any C++ XML libraries out there I can us开发者_开发技巧e for this purpose, without needing to get into the intricacies of COM?


I suggest pugixml. Pugixml is Light-weight, simple and fast XML parser for C++ with XPath support

Here is the quick start guide, and here is a benchmark, notice how only AsmXML is faster than pugixml.


AFAIK, the most efficient open-source parser library for C, C#, C++, and Java nowadays is VTD-XML. In terms of performance, it beats DOM, SAX, and XPath. I has converted the library to Delphi for my private project, and I found that VTD-XML is just like what it claims. See VTD-XML Benchmark.


Yes of course.

If you don't need validation, I'd suggest TinyXML++ which is also very simple to use :

    ticpp::Document doc(pcFilename);
    doc.LoadFile();

    // parse through all elements
    std::string strName;
    std::string strValue;
    ticpp::Iterator<ticpp::Element> child;
    for(child = child.begin(doc.FirstChildElement()); child != child.end(); child++)
    {
            // parse through all the attributes of this fruit
            ticpp::Iterator< ticpp::Attribute > attribute;
            for(attribute = attribute.begin(child.Get()); attribute != attribute.end(); attribute++)
            {
                    attribute->GetName(&strName);
                    attribute->GetValue(&strValue);
                    std::cout << strName << ": " << strValue << std::endl;
            }
            std::cout << std::endl;
    }

If you need validation, consider using XercesC++.


I've used XercesC++ in the past to good effect. I recently used MSXML which was all pain in comparison.


I've used xerces and expat (both C libraries) from within C++. Both do their job well, but if I was to rewrite my code again I'd probably use libxml2. Xerces IMO is too large and overwhelming for my needs, while expat is too low-level. My understanding is that libxml2 is a good higher level library. (I've used the lxml python bindings for libxml2 extensively - and they work beautifully.).

Oh and I've used tinyxml a bit too (several years ago), but found its DOM model too slow for my needs.


The Expat XML Parser is also a good one. I think you will find a C++ wapper for it somewhere. http://expat.sourceforge.net/


A simple google search found me quite a few XML parsers for C++ other than Xerces (the most commonly used one).

I don't know how good they are. Here are two:

libXML

TinyXML


The boost.property_tree has the XML parser (based on RapidXml).

It's header-only and has no dependencies other than Boost.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜