[xsde-users] Get the element name
    Khuong Nguyen Thi Lien 
    ntlkhuong at tma.com.vn
       
    Wed Sep 17 04:26:07 EDT 2008
    
    
  
Hi Boris,
 
Thanks for your response, instead of using a string member variable to store
the name, I would like to use the const char* to point to the name array as
the way to save space for my classes and we only use in the callback and
then no use anymore. So is there is there any risk by using this way?
 
Thanks,
Khuong
 
  class clearArpCacheEthernet_pimpl: public clearArpCacheEthernet_pskel
  {
    public:
    clearArpCacheEthernet_pimpl ();
 
    virtual void
    pre ();
 
    // Elements.
    //
  void clearArpCacheEthernet_pimpl::
  slot (ucg::AttributePtr& slot)
  {
    slot->setName(currentElementName);
    data->addAttribute(slot);
  }
 
  void clearArpCacheEthernet_pimpl::
  port (ucg::AttributePtr& port)
  {
    port->setName(currentElementName);
    data->addAttribute(port);
  }
 
    virtual ::ucg::NodePtr&
    post_clearArpCacheEthernet ();
 
    protected:
        bool _start_element_impl(const xsde::cxx::ro_string& ns, const
xsde::cxx::ro_string& n, const char* s)
        {
            currentElementName =  n.data();
            return clearArpCacheEthernet_pskel::_start_element_impl(ns, n,
s);
        }
        ::ucg::NodePtr data;
        const char* currentElementName;
  };
 
 
-----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