[xsde-users] Get the currently parsed element's name

Ninh Tran Dang tdninh at tma.com.vn
Fri Oct 31 04:15:56 EDT 2008


Hi Boris,

We still got segmentation fault with your instruction. In the worst case, we
will use the "const char* name = _context ().element_name_" in the pre()
method and then create the object with the stored name variable in the
post(), we tried and found that it works. But we are not sure if there is
any further risk because the name variable also points to the element_name
member of context class which is somehow freed previously.

Thanks,
Ninh

-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Sent: Friday, October 31, 2008 2:07 PM
To: Ninh Tran Dang
Cc: xsde-users at codesynthesis.com
Subject: Re: [xsde-users] Get the currently parsed element's name

Hi Ninh,

Ninh Tran Dang <tdninh at tma.com.vn> writes:

> We tried with your new suggestion, it's ok when retrieving the element's
> name from the pre() with the "const char* name = _context
().element_name_"
> statement. But it got the segmentation fault when getting this from the
> post() method. Even we tried in the post() of element that doesn't contain
> the nested elements.
> 
> Do you know the reason why we got this error?

I think I do: post() is called after the end_element SAX even arrives
while the element name was saved in start_element. Expat (the underlying
parser) probably frees or reuses the name buffer after start_element
which makes it unusable. Sorry, I was too optimistic about types
without nested elements. 

After thinking some more about this, I believe this can be fixed by
adding a similar line of code to end_element_() in 
libxsde/xsde/cxx/parser/expat/document.cxx, after line 879, as we've 
added to start_element_():

context_.element_name_ = name_p;

This way the element name in the context will be restored for the
post() call. The really nice thing about it is that you can now
use _context ().element_name_ from post() even for types that have 
nested elements!

Boris



More information about the xsde-users mailing list