Boost logo

Boost :

From: zaufi_at_[hidden]
Date: 2004-07-21 02:49:41


On Tuesday 20 July 2004 15:40, Jeff Garland wrote:
> On Tue, 20 Jul 2004 01:19:33 -0500 (CDT), Aleksander Demko wrote
> > and, just out of curiosity:
> > xml/html parsing
>
> There have been various discussions of this, but I'm not aware of a
> coherent effort.
>
> All the libraries you mention would be valuable in boost in my view --
> contributions appreciated. See
> http://www.boost.org/more/submission_process.htm if you haven't already.

Recently I implement some XML related code with the following features:

- currently lightweight general XML classes like xml_node and xml_document.
they are both uses STL (to hold parent/child releations, content and
attributres) and (when needs to produce/parse real XML strings) libxml2.
Sample code:
        xml_document doc(xml_node("root));
        xml_node& root = doc.get_root();
        xml_node::child_iterator c = root.insert_child(xml_node("node", "content"));
        c->insert_attribute("name", "value");
        c->append_content("... more content.");
        // XML document is convertable to std::string
        std::string raw_xml = doc;
        cout << doc;
        // parse XML to new document uses another constructor
        xml_document rebuilded(raw_xml);

- XML serialization subsystem -- a set of helpers to convert ANY (almost ;)
type to XML and back to C/C++ type... sample code may look like this:
        int a = 10;
        xml_node n = xml_cast<xml_node>(a, "size");
        // "size" is a node name (which is become XML 'tag' if XML output requierd

        int b = xml_cast<int>(n, "size"); // convert from xml_node back to int...

        // you may produce serializable types from 'usual' types at easy
        xml_serializable_data<map<int, float> > src("my_map");
        src.value()[1] = 3.14;
        src.value()[2] = 2.73;
        xml_node my_map = src.to_xml();

        // or using already known xml_cast :)
        // no need to pass a name... it is already known
        xml_node mm = xml_cast<xml_node>(src);

- and finally I have implement a XML RPC like protocol to do remote calls:

        int foo(std::list<int>, std::string, const float*) { /* ... */}

        // to create XML RPC server you just need:
        // 1) connection maker object -- usual listener for servers
        xml_rpc_listener listener(port_number);
        // 2) RPC server object itself which will use sockets maden by listener
        xml_rpc_server server(&listener);
        // 3) add/register XML method(s) on server
        server.add_method(
            xml_rpc_server_method<
                int(std::list<int>, std::string, const float*)
>("xml_foo", &foo)
          );
        // ...

        // to call remote method you need:
        // 1) connection maker object -- usual active connector for clients
        xml_rpc_connector connector("localhost", port_number);
        // 2) client object which will use socket produce by connector
        xml_rpc_client_p2p client(&connector);
        // 3) XML method/functor -- this is a real functor, so you may pass it
        // everywhere a functor maybe passed... even for std algorithms ;)
        xml_rpc_client_method<int(std::list<int>, std::string, const float*)>
                remote_foo("xml_foo", &client);

        // now call it! ;)
        std::list<int> my_list; my_list.push_back(123);
        const float* pi_ptr = new float(3.14);
        remote_foo(my_list, "super string", pi_ptr);

You even may catch __remote__ exception if server's foo throw it :)

All of above used in project I worked on currently, but if it can be
interested for someone else I can start to boostify this... :)

have fun!


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk