Re: [xml] greetings & a question

On Sat, 18 Aug 2001 tlewis mindspring com wrote:

Greetings.  I am using libxml2 for a new, free network intrusion detection
system called hank.  I hope to announce it publically next month.
So far, I have been very pleased by my experiences using it.

My rule file is xml, and reports are specified like this:


This approach was very simple and easy to code; copy the text and replace
the <field> nodes with my field data structure in C.

Now, I would like to allow people to have their reports as more than
plain text documents; I would like to generate xml for such purposes
as supporting idmef or other NIDS xml report formats.  Under such a scheme,
users would instead state rules like this:


The naive way to code this is: make a copy and walk the tree, looking
for all "field" nodes and replacing them.  This, however, seems rather a
lot of work, and repetitive at that.  I also thought about caching their
location, but the representation of nodes as linked lists makes this
cumbersome to do for a humble C journeyman as myself, and potentially
even more work than walking the entire tree, since large portions of the
tree could be traversed repeatedly unless I get even more adventurous
with my coding, etc.

My question is, is there a way to identify these nodes before-hand, copy
the tree and replace the corresponding nodes in the new tree?  I don't
know if I could xlink them or use some other xml magic to make this easy
or if there's a more obvious approach that I'm just too dumb to realize.
I had ruled out replacing them in the original before copying because of
memory leak fears, but maybe there's a way to adopt this approach.

Any and all advice is welcome and appreciated.

Todd Lewis
tlewis mindspring com

Have you looked at XSLT? You're basically translating one type of XML document
into another, even if it's as simple as replacing elements with text. XSLT
excels at manipulating XML.

You could even change your original C code to output an XSLT stylesheet
instead of doing search-and-replace on an xmlDoc, then use libxslt to apply
the stylesheet to any report you choose, copying any elements it doesn't know
about, and replacing ones it does know about with the appropriate value.

Ignacio Vazquez-Abrams  <ignacio openservices net>

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]