Skip to content
This repository was archived by the owner on Feb 12, 2025. It is now read-only.

filipenf/libxml-cpp-wrapper

Repository files navigation

libxml-cpp-wrapper

A simple C++ wrapper to the libxml

I created this small library to simplify the libxml's API for C++ developers.

Example

For a xml like this:

<CustomerList>
    <Customer>
        <Name>John Smith</Name>
        <ContactInfo>
            <Address>22 Acacia Avenue</Address>
            <OfficePhone>123456</OfficePhone>
        </ContactInfo>
    </Customer>
</CustomerList>

The code to write such file is:

    XMLMemoryWriter writer;
    XMLBuilder<XMLMemoryWriter> builder(writer);
    XMLNode &root = builder.addNode("CustomerList");
    root.attributes["version"] = "1.0";
    root["Customer"]["Name"].text = "John Smith";
    root["Customer"]["ContactInfo"]["Address"].text = "22 Acacia Avenue";
    root["Customer"]["ContactInfo"]["OfficePhone"].text = "+11 222 333 444";
    builder.write();
    cout << writer.getContent() << endl;

And the code to parse and get the value of OfficePhone tag is:

list<XMLNode> nodes;
XMLReader<XMLMemoryParser> reader(xml_string);
reader.parse(nodes);
XMLNode &node = *nodes.begin();
string office_phone = node["Customer"]["ContactInfo"]["OfficePhone"].text;

Pre-requisites:

* libxml2
* cmake

Installation

  1. Clone git repository
    git clone git://github.com/filipenf/libxml-cpp-wrapper.git

** Easiest way: ** 2) Just copy the .cpp and .h files to your project and build it.

** 2nd easiest way :-): **

  1. Build the project
    mkdir build && cd build
    cmake ../libxml-cpp-wrapper
    make && sudo make install

If may find some errors about the inclusion of libxml headers. Make sure your libxml2 include directory is /usr/local/include/libxml2 or you can adjust it in the CMakeFiles.txt

After the instalation a library named xmlcppwrapper will be installed in your system. You should link your project to it.

About

A simple wrapper to the libxml

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages