[xsde-users] Get the element name

Boris Kolpackov boris at codesynthesis.com
Thu Sep 11 04:51:21 EDT 2008


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