[xsde-users] Get the currently parsed element's name
Khuong Nguyen Thi Lien
ntlkhuong at tma.com.vn
Tue Oct 28 05:44:56 EDT 2008
Hi Boris,
I have another situation that I want to retrieve the current element's name
where the parser is working on. Is there any data member where we could
extract this name?
Thanks,
Khuong
-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Thursday, September 11, 2008 3:51 PM
To: Khuong Nguyen Thi Lien
Cc: xsde-users at codesynthesis.com
Subject: Re: [xsde-users] Get the element name
Hi Khuong,
Khuong Nguyen Thi Lien <ntlkhuong at tma.com.vn> writes:
> Sorry for the unclear question, I have the xml fragment below, when the
> parsing engine reaches the <greeting> element in the greeting() callback
> function, I would like to extract the name of the element right at this
> function. In this case I would like the returned name should be
"greeting".
My guess is that your schema is using substitution groups and element
names act as identifiers (i.e., different substituting elements use the
same type). If that's the case then I have already outlined the possible
ways to achieve this in the following post:
http://www.codesynthesis.com/pipermail/xsde-users/2008-July/000039.html
In your case the easiest way would be to override _start_element and
save the element name in a member variable. You can then access it
from the greeting function:
struct hello_pimpl: hello_pskel
{
virtual void
greeting (const string& greeting)
{
// element_name_ contains the element name.
}
virtual void
name (const string& name)
{
}
virtual void
_start_element (const xml_schema::ro_string& ns,
const xml_schema::ro_string& name
const char* type)
{
element_name_ = name;
// Always call the base _start_element().
//
hello_pskel::_start_element (ns, name, type);
}
private:
string element_name_;
};
Boris
More information about the xsde-users
mailing list