Generating an XML Document from a Resource Pools Configuration

XML is a convenient representation format for small quantities of data. There are many tools for manipulating XML documents and a lot of people are now familiar enough with the structure of XML to feel comfortable with this type of representation. Especially in preference to yet another problem domain specific data representation format (YAPDSDRF?).

libpool(3LIB) provides an API for manipulating Resource Pools configurations. In particular, the pool_conf_export(3POOL) function may be used to create a file containing the XML representation of a configuration.

pool_conf_export(3POOL) takes three arguments:

 conf - A valid pools configuration pointer
 location - The pathname you wish to write the configuration into
 format - This must be POX_NATIVE which is the native pools representation format 

It's not immediately obvious (and I say this with some shame since I defined this function) that POX_NATIVE == XML. Once you know that, it's fairly obvious how a program to dump a resource pools configuration in XML format can be written.

One further tip, you can pass "-" as the location and the output will be directed to stdout.

I'm sure that I don't need to say that the following program is completely unsupported and used at your peril, but I thought I would say it just to make it clear.


#include <pool.h>

/\* ARGSUSED \*/
int
main(int argc, char \*\*argv)
{
        pool_conf_t \*conf;

        if ((conf = pool_conf_alloc()) == NULL) {
                return (2);
        }
        if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY) !=
            PO_SUCCESS) {
                pool_conf_free(conf);
                return (2);
        }

        if (pool_conf_export(conf, "-", POX_NATIVE) != PO_SUCCESS) {
                (void) pool_conf_close(conf);
                pool_conf_free(conf);
                return (2);
        }
        (void) pool_conf_close(conf);
        pool_conf_free(conf);
        return (0);
}

Once you have your configuration as an XML document you can manipulate it easily using a wide range of tools. In a later post, I'll show how you can use an XSL stylesheet to transform the XML document into an HTML document using the xsltproc(1) utility.

Comments:

Interesting what programming style does to algorithms. Here's what I would have written: int main(int argc, char \*\*argv) { pool_conf_t \*conf; int rc = 2; if ((conf = pool_conf_alloc()) == NULL) { return rc; } if (pool_conf_open(conf, pool_dynamic_location(), PO_RDONLY) == PO_SUCCESS) { if (pool_conf_export(conf, "-", POX_NATIVE) == PO_SUCCESS) { rc = 0; } (void) pool_conf_close(conf); } pool_conf_free(conf); return rc; } (please reformat to a sane layout, the comment engine is seriously lacking...)

Posted by Volker A. Brandt on July 07, 2004 at 09:59 AM BST #

Post a Comment:
Comments are closed for this entry.
About

garypen

Search

Archives
« July 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   
       
Today