## Class writer

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

## Synopsis

    // In header: </home/maarten/projects/libzeep/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_trim(bool);
      void set_collapse_empty_elements(bool);
      void set_escape_whitespace(bool);
      void set_no_comment(bool);
      void xml_decl(bool);
      void empty_doctype(const std::string &, const std::string &);
      void doctype(const std::string &, const std::string &, const std::string &);
      void start_doctype(const std::string &, const std::string &);
      void notation(const std::string &, const std::string &, const std::string &);
      void end_doctype();
      void start_element(const std::string &);
      void end_element();
      void attribute(const std::string &, const std::string &);
      void content(const std::string &);
      void element(const std::string &, const std::string &);
      void cdata(const std::string &);
      void comment(const std::string &);
      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_trim(bool flag);

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

6.     void set_collapse_empty_elements(bool collapse);

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

7.     void set_escape_whitespace(bool escape);

   escape whitespace into character refences can be specified.

8.     void set_no_comment(bool no_comment);

   do not write out comments

9.     void xml_decl(bool standalone);

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

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

    To write an empty DOCTYPE specifying an external subset.

11.     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.

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

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

    To write a NOTATION declaration.

14.     void end_doctype();

    End a DOCTYPE declaration.

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

16.     void end_element();

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

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

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

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

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

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