## Class writer

zeep::xml::writer — Use xml::writer to write XML documents to a stream.

## Synopsis

    // In header: </build/libzeep-8SPbhu/libzeep-3.0.5/zeep/xml/writer.hpp>

    class writer {
    public:
      // construct/copy/destruct
      writer(std::ostream &);
      writer(std::ostream &, bool, bool = false);
      ~writer();

      // public member functions
      void set_xml_decl(bool);
      void set_indent(int);
      void set_wrap(bool);
      void set_wrap_prolog(bool);
      void set_wrap_attributes(bool, int = 0);
      void set_trim(bool);
      void set_collapse_empty_elements(bool);
      void set_escape_whitespace(bool);
      void set_no_comment(bool);
      virtual void xml_decl(bool);
      virtual void empty_doctype(const std::string &, const std::string &);
      virtual void
      doctype(const std::string &, const std::string &, const std::string &);
      virtual void start_doctype(const std::string &, const std::string &);
      virtual void
      notation(const std::string &, const std::string &, const std::string &);
      virtual void end_doctype();
      virtual void start_element(const std::string &);
      virtual void end_element();
      virtual void attribute(const std::string &, const std::string &);
      virtual void content(const std::string &);
      void element(const std::string &, const std::string &);
      virtual void cdata(const std::string &);
      virtual void comment(const std::string &);
      virtual void
      processing_instruction(const std::string &, const std::string &);
    };

## Description

The zeep::xml::writer class is used to write XML documents. It has several options that influence the way the data is written. E.g. it is possible to specify whether to wrap the elements and what indentation to use. The writer keeps track of opened elements and therefore knows how to close an element.

The writer writes out XML 1.0 files.

### `writer` public construct/copy/destruct

1.     writer(std::ostream & os);

   The constructor takes a std::ostream as argument.

2.     writer(std::ostream & os, bool write_decl, bool standalone = false);

3.     ~writer();

### `writer` public member functions

1.     void set_xml_decl(bool flag);

   set_encoding is not yet implemented, we only support UTF-8 for now

   the xml declaration flag (<?xml version...) is not written by default

2.     void set_indent(int indentation);

   the indentation in number of spaces, default is two.

3.     void set_wrap(bool flag);

   default is to wrap XML files

4.     void set_wrap_prolog(bool flag);

   default is to wrap XML files

5.     void set_wrap_attributes(bool flag, int maxLevel = 0);

   default is to not wrap attributes

6.     void set_trim(bool flag);

   if the trim flag is set, all whitespace will be trimmed to one space exactly

7.     void set_collapse_empty_elements(bool collapse);

   collapsing empty elements (<empyt/>) is the default behaviour

8.     void set_escape_whitespace(bool escape);

   escape whitespace into character refences can be specified.

9.     void set_no_comment(bool no_comment);

   do not write out comments

10.     virtual void xml_decl(bool standalone);

    write a xml declaration, version will be 1.0, standalone can be specified.

11.     virtual void empty_doctype(const std::string & root, const std::string & dtd);

    To write an empty DOCTYPE specifying an external subset.

12.     virtual void
        doctype(const std::string & root, const std::string & pubid,
                const std::string & dtd);

    This opens a DOCTYPE declaration. The root parameter is the name of the base element.

13.     virtual void start_doctype(const std::string & root, const std::string & dtd);

14.     virtual void
        notation(const std::string & name, const std::string & sysid,
                 const std::string & pubid);

    To write a NOTATION declaration.

15.     virtual void end_doctype();

    End a DOCTYPE declaration.

16.     virtual void start_element(const std::string & name);

17.     virtual void end_element();

18.     virtual void attribute(const std::string & name, const std::string & value);

19.     virtual void content(const std::string & content);

20.     void element(const std::string & name, const std::string & s);

21.     virtual void cdata(const std::string & text);

22.     virtual void comment(const std::string & text);

23.     virtual void
        processing_instruction(const std::string & target, const std::string & text);