Re: [xml] xmlHashScan and *data argument



On Sunday 19 October 2003 21:49, Daniel Veillard wrote:
On Sun, Oct 19, 2003 at 09:07:31PM +0200, Melvyn Sopacua wrote:
Content-Description: signed data

Hi,

I'm trying to build a tree-like output from a given DTD. For that I need
to know the 'indent level' I'm printing at, so I thought I'd pass an int
pointer as data. That gives all kinds of weird results and it looks like
the passed element is never initialized. If I set the level within the
callback and set data to NULL, everything works correctly.

The code in valid.c uses an xmlBuffer to pass to the callback and looking
into hash.c there are a number or argument mangles, that don't make sense
to me.

What is assumed about this 'data' argument and can it be only an
xmlBuffer?

  I have no idea what you're trying to do, nor what you problem is.
xmlHashScan is used to traverse a hash table. The xmlHashScanner
argment is called for each element in the table with the content
in the hash, the data you passed and the name of the data in the hash
as the third argument. There is nothing assumed about data.

This works:
========================================================================
void printElementStructured(xmlElementPtr el)
{
        int level = 0;
        switch( el->etype )
        /* pass level along to content printer, but if called from
         * content, the indent level is 0 again */
}

/* in main() */
table = dtd->elements; /* dtd is an xmlDtdPtr */
if( table != NULL )
{
        xmlHashScan(table, (xmlHashScanner) printElementStructured, NULL);
}
========================================================================

This doesn't:
========================================================================
void printElementStructured(int *level, xmlElementPtr el)
{
        int i;

        for(i=0; i < *level ; i++ )
                print("\t");

        switch( el->etype )
...
}

/* in main() */
int level = 0;
table = dtd->elements;
if( table != NULL )
{
        xmlHashScan(table, (xmlHashScanner) printElementStructured, &level);
}
========================================================================

I basically took this from xmlDumpElementDesc in valid.c and *thought* that 
the data argument, would be passed in as first arg to the xmlHashScanner - in 
fact - that part works, but the xmlElementPtr is invalid:
(gdb) print *el
$1 = {_private = 0x0, type = 134541632, name = 0x804e140 "", children = 
0xbfbff584,
  last = 0x8048611, parent = 0x2, next = 0xbfbff58c, prev = 0xbfbff598,
  doc = 0xbfbff584, etype = 134514153, content = 0x804a13c,
  attributes = 0xbfbff584, prefix = 0x80484ba "Ã", contModel = 0x80485f1}


-- 
Melvyn

Attachment: pgpxL5F10yWbE.pgp
Description: signature



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