[OPEN-ILS-DEV] PATCH: osrf_system.c
Mike Rylander
mrylander at gmail.com
Tue May 22 00:15:02 EDT 2007
On 5/21/07, Scott McKellar <mck9 at swbell.net> wrote:
>
> --- Mike Rylander <mrylander at gmail.com> wrote:
>
> > >
> > > When I get home I'll try out your fix and subject it to some more
> > > torture tests.
> > >
> >
> > Thanks.
> >
> > --miker
>
> I tried your fix and it seemed to work, but I'm darned if I know
> why it works. This whole function continues to baffle me. I think
> I need to study libxml2 more -- I don't quite understand what is
> a child or sibling of what.
>
> Scott McKellar
> http://home.swbell.net/mck9/aargh/
>
(For explanation to all interested parties...)
The function in question ( jsonObject* _xmlToJSON(xmlNodePtr,
jsonObject*) ) is a tree walker that constructs a parallel JSON object
while descending through a DOM tree. It recursively fills in a
hash-like structure of Object nodes, and constructs Array nodes at the
edges where named elements are duplicated, as is possible in the case
of the <domain/> element. For singular elements, like <logfile/>, it
simply sets the value of the key to the value of TEXT node. In JSON,
the finished structure would look something like:
{ srfsh :
{ router_name : "router",
domains : { domain : [ '127.0.0.1', '10.1.0.1' ] },
username : 'myusername',
passwd : 'mypasswd',
port : 5222,
logfile : '/path/to/log/file/srfsh.log',
loglevel : 4
}
}
The gist of the fix is that we don't want TEXT nodes except at the
leaves of the DOM tree (in _any_ of the XML config files we supply,
which is why I felt comfortable making this change in the xml_utils
method directly), meaning that there will be only one child node where
we want to see text.
To test the length of the 'children' linked list of a DOM node in
libxml2, we can compare the first child node (pointed at by the
'children' member of the xmlNode object) to the last (you guessed it,
the 'last' member of the xmlNode object), and if they are the same
then then we know we're looking at a leaf node. In that case we allow
the handling of the TEXT type nodes, otherwise we skip them in the
linked list. We're completely ignoring those non-leaf TEXT nodes, but
(while I haven't tested the xsd yet) we should be able to warn on
those using Dan's shiny new validation schema. I'm unsure as to
whether we should integrate that in a programmatic fashion or have a
script to do the validation.
That algorithm was based on info from
http://www.xmlsoft.org/html/libxml-tree.html#xmlNode as well as having
worked with libxml2 in the past (obviously).
--miker
More information about the Open-ils-dev
mailing list