## Class element

zeep::xml::element

## Synopsis

    // In header: </home/maarten/projects/libzeep/zeep/xml/node.hpp>

    class element : public zeep::xml::container {
    public:
      // member classes/structs/unions

      // as a service to the user, we define an attribute iterator here

      class attribute_iterator {
      public:
        // construct/copy/destruct
        attribute_iterator();
        attribute_iterator(attribute *);
        attribute_iterator(const attribute_iterator &);
        attribute_iterator& operator=(const attribute_iterator &);

        // public member functions
        reference operator*() const;
        pointer operator->() const;
        attribute_iterator & operator++();
        attribute_iterator operator++(int);
        attribute_iterator & operator--();
        attribute_iterator operator--(int);
        bool operator==(const attribute_iterator &) const;
        bool operator!=(const attribute_iterator &) const;
        pointer base() const;
      };

      class const_attribute_iterator {
      public:
        // construct/copy/destruct
        const_attribute_iterator();
        const_attribute_iterator(attribute *);
        const_attribute_iterator(const attribute_iterator &);
        const_attribute_iterator(const const_attribute_iterator &);
        const_attribute_iterator& operator=(const const_attribute_iterator &);

        // public member functions
        reference operator*() const;
        pointer operator->() const;
        const_attribute_iterator & operator++();
        const_attribute_iterator operator++(int);
        const_attribute_iterator & operator--();
        const_attribute_iterator operator--(int);
        bool operator==(const const_attribute_iterator &) const;
        bool operator!=(const const_attribute_iterator &) const;
        pointer base() const;
      };
      // construct/copy/destruct
      element(const std::string &);
      ~element();

      // public member functions
      void write(writer &) const;
      bool equals(const node *) const;
      node * clone() const;
      std::string str() const;
      void write_content(std::ostream &, const char * = kWhiteSpaceChar) const;
      std::string qname() const;
      std::string namespace_for_prefix(const std::string &) const;
      std::string prefix_for_namespace(const std::string &) const;
      std::string content() const;
      void content(const std::string &);
      std::string get_attribute(const std::string &) const;
      attribute * get_attribute_node(const std::string &) const;
      void set_attribute(const std::string &, const std::string &, bool = false);
      void remove_attribute(const std::string &);
      void set_name_space(const std::string &, const std::string &);
      void add_text(const std::string &);
      attribute_set attributes() const;
      name_space_list name_spaces() const;
      std::string lang() const;
      std::string id() const;
      attribute_iterator attr_begin();
      attribute_iterator attr_end();
      const_attribute_iterator attr_begin() const;
      const_attribute_iterator attr_end() const;
    };

## Description

element is the most important zeep::xml::node object. It encapsulates a XML element as found in the XML document. It has a qname, can have children, attributes and a namespace.

### `element` public construct/copy/destruct

1.     element(const std::string & qname);

2.     ~element();

### `element` public member functions

1.     void write(writer & w) const;

   writing out

2.     bool equals(const node * n) const;

   Compare the node with n.

3.     node * clone() const;

   Deep clone the node.

4.     std::string str() const;

   return all content concatenated, including that of children.

5.     void write_content(std::ostream & os, const char * sep = kWhiteSpaceChar) const;

   write out the concatenated content to a stream, separated by sep.

6.     std::string qname() const;

   Nodes can have a name, and the XPath specification requires that a node can have a so-called expanded-name. This name consists of a local-name and a namespace which is a URI. And we can have a QName which is a concatenation of a prefix (that points to a namespace URI) and a local-name separated by a colon.

   To reduce storage requirements, names are stored in nodes as qnames, if at all.

7.     std::string namespace_for_prefix(const std::string & prefix) const;

   Return the namespace URI for a prefix.

8.     std::string prefix_for_namespace(const std::string & uri) const;

   Return the prefix for a namespace URI.

9.     std::string content() const;

10.     void content(const std::string & content);

11.     std::string get_attribute(const std::string & qname) const;

12.     attribute * get_attribute_node(const std::string & qname) const;

13.     void set_attribute(const std::string & qname, const std::string & value,
                           bool id = false);

    the DOCTYPE can specify some attributes as ID

14.     void remove_attribute(const std::string & qname);

15.     void set_name_space(const std::string & prefix, const std::string & uri);

    to set the default namespace, pass an empty string as prefix

16.     void add_text(const std::string & s);

    The add_text method checks if the last added child is a text node, and if so, it appends the string to this node's value. Otherwise, it adds a new text node child with the new text.

17.     attribute_set attributes() const;

    to iterate over the attribute nodes

18.     name_space_list name_spaces() const;

    to iterate over the namespace nodes

19.     std::string lang() const;

    content of a xml:lang attribute of this element, or its nearest ancestor

20.     std::string id() const;

    content of the xml:id attribute, or the attribute that was defined to be of type ID by the DOCTYPE.

21.     attribute_iterator attr_begin();

22.     attribute_iterator attr_end();

23.     const_attribute_iterator attr_begin() const;

24.     const_attribute_iterator attr_end() const;