[xsde-users] Get the currently parsed element's name
Boris Kolpackov
boris at codesynthesis.com
Fri Oct 31 03:06:58 EDT 2008
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