C++ class for reading and writing XML structures. No need for a C++ code parser or special pre compiler. Specify a schema entirly in native C++. The schema is verified when XML is read and exceptions are thrown when the XML to be parse is invalid.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
Marc Wäckerlin 6b2d5abec6 fix for cosmic and C++17 5 yıl önce
debian fix debian build 5 yıl önce
doc fixed C++11 dependency 6 yıl önce
examples fixed rpm build 7 yıl önce
src fix for cosmic and C++17 5 yıl önce
test update buildsystem 8 yıl önce
AUTHORS new author url 9 yıl önce
COPYING LGPL 3 15 yıl önce
ChangeLog fix rpm build 5 yıl önce
INSTALL build system updated 5 yıl önce
NEWS fix for C++17, requires at least C+17 6 yıl önce
README.md build system updated 5 yıl önce
autogen.sh update buildsystem 8 yıl önce
ax_check_qt.m4 fixed dependency-bug in ubuntu cosmic and stretch 6 yıl önce
ax_cxx_compile_stdcxx.m4 fix for C++17, requires at least C+17 6 yıl önce
ax_cxx_compile_stdcxx_11.m4 update buildsystem 8 yıl önce
ax_init_standard_project.m4 build system updated 5 yıl önce
bootstrap.sh build system updated 5 yıl önce
build-in-docker.conf fixed for build with opensuse tumbleweed and leap 6 yıl önce
build-in-docker.sh fix build on eoan 5 yıl önce
build-resource-file.sh new author url 9 yıl önce
configure.ac fixed C++11 dependency 6 yıl önce
dependency-graph.sh fixed build on mac 6 yıl önce
install-32-bit-lin-win.sh 32bit-build added, refs #5 14 yıl önce
install-64-and-32-bit-linux.sh extendions and corrections 15 yıl önce
libxml-cxx.desktop.in development packages are named devel in rpms, not dev 9 yıl önce
libxml-cxx.spec.in fix rpm build 5 yıl önce
mac-create-app-bundle.sh update buildsystem 6 yıl önce
makefile.am fix rpm build 5 yıl önce
makefile_test.inc.am update buildsystem 8 yıl önce
resolve-debbuilddeps.sh fixed build for mageia 6 yıl önce
resolve-rpmbuilddeps.sh update buildsystem 6 yıl önce
rpmsign.exp build updated 7 yıl önce
sql-to-dot.sed update buildsystem 8 yıl önce
template.sh fix build on eoan 5 yıl önce

README.md

C++ XML Class Library

This is a C++ class for reading and writing XML structures.

  • Specify your XML schema in C++ using common C++ syntax, such as shift, dereference, etc.
  • Verify the schema of XML files while they are read from a stream.
  • Map and store your own C++ classes to XML and restore them back.

Rationale

The initial idea was to map C++ data structures to XML files for configuration files that can easily be edited by hand.

This library does not need any kind of C++ code parser or special pre compiler. You can specify a schema entirly in native C++. The schema is verified when XML is read and exceptions are thrown when the XML to be parse is invalid. Exceptions specify exactly the location and reason of the problem, so that the editor of the XML file can easily find and correct the problem.

C++ classes can inherit xml::Serialize and become serializable this way. All you need to do is to overwrite one single method, where you declare XML tag names for the class name and for all members.

Note: All links below require the generated Doxygen documentation.

More rationale: See also Related Pages in the doxygen project documentation.

Basics

Include file:

#include <xml-cxx/xml.hxx>

Link option:

-lxml-cxx

Factory with Schema Declaration

Small example on how to declare an XML schema, you may then use template.read(is) to read XML from a stream:

// start with root element: <root id="">
xml::Factory template(xml::Node("root").attr("id", xml::optional)
                      // <root> contains any number of <child>
                      <<xml::String("child")
                      // must contain exactly one <other>
                      <<(xml::Node("other").limits(1, 1)
                         // <other> contains min 2 max 4 <text>
                         <<xml::String("text").limits(2, 4)));

Using Macros Instead of Literal Text

If you prefere using constants instead of literal texts, you can declare the node names before you use them:

XML_NODE(root);
XML_STRING(child);
[...]
xml::Factory template(xml::node::root.clone()->attr("id", xml::optional)
                      <<*xml::string::child.clone()
                      [...]

Serialize Classes, Join Classes with XML

When inheriting from xml::Serialize, your class inherits the methods xml::Serialize::loadXml and xml::Serialize::saveXml. Simply overwrite xml::Serialize::initXmlMembers to make your class serializable:

class MyClass: public xml::Serialize {
  [...]
  protected:
    void initXmlMembers() {
      className("MyClass");
      persist(i, "i");
      persist(s, "s");
      persist(l, "l");
    }
  private:
    int i;
    std::string s;
    xml::List<std::string> l; // same behaviour as std::list
};

Known Limitations

  • XML-Comments are only ignored, not read, not stored.
  • Mixed tags and text is not supported. Tags may either contain other tags only (type xml::Node) or text only (type xml::String). -> This is intended behaviour!
  • Unlimited recursion is not possible (e.g. <p><p><p></p></p></p>;)
  • Exceptions should be optional, best effort otherwise (option "strict")

Limitations of Serialization

  • Only the following types are intended to be serialized:
    (It is possible to use other techniques, but that's not recommended)
    • basic C++ types (except pointer)
    • std::string
    • classes derieved from xml::Serialize
    • most standard containers, but in their xml-form, e.g. xml::List instead of std::list (xml::List inherits std::list)
    • Optional values are supported through xml::Optional
    • std::bitset, std::priority_queue, std::queue and std::stack are not implemented
    • Polymorfic serialisation is not yet implemented

In the Web

Missing a Feature, Found a Bug

You are missing a feature, or an implementation is too incomplete for the purpose you need it? Or you even found a bug? Just register and open an issue on the project management page.