DOMWriter.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // DOMWriter.h
  3. //
  4. // Library: XML
  5. // Package: DOM
  6. // Module: DOMWriter
  7. //
  8. // Definition of class DOMWriter.
  9. //
  10. // Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
  11. // and Contributors.
  12. //
  13. // SPDX-License-Identifier: BSL-1.0
  14. //
  15. #ifndef DOM_DOMWriter_INCLUDED
  16. #define DOM_DOMWriter_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/XML/XMLString.h"
  19. #include "Poco/XML/XMLStream.h"
  20. #include "Poco/TextEncoding.h"
  21. namespace Poco {
  22. namespace XML {
  23. class Node;
  24. class Document;
  25. class XML_API DOMWriter
  26. /// The DOMWriter uses a DOMSerializer with an
  27. /// XMLWriter to serialize a DOM document into
  28. /// textual XML.
  29. {
  30. public:
  31. DOMWriter();
  32. /// Creates a DOMWriter.
  33. ~DOMWriter();
  34. /// Destroys a DOMWriter.
  35. void setEncoding(const std::string& encodingName, Poco::TextEncoding& textEncoding);
  36. /// Sets the encoding, which will be reflected in the written XML declaration.
  37. const std::string& getEncoding() const;
  38. /// Returns the encoding name set with setEncoding.
  39. void setOptions(int options);
  40. /// Sets options for the internal XMLWriter.
  41. ///
  42. /// See class XMLWriter for available options.
  43. int getOptions() const;
  44. /// Returns the options for the internal XMLWriter.
  45. void setNewLine(const std::string& newLine);
  46. /// Sets the line ending characters for the internal
  47. /// XMLWriter. See XMLWriter::setNewLine() for a list
  48. /// of supported values.
  49. const std::string& getNewLine() const;
  50. /// Returns the line ending characters used by the
  51. /// internal XMLWriter.
  52. void setIndent(const std::string& indent);
  53. /// Sets the string used for one indentation step.
  54. ///
  55. /// The default is a single TAB character.
  56. /// The given string should only contain TAB or SPACE
  57. /// characters (e.g., a single TAB character, or
  58. /// two to four SPACE characters).
  59. const std::string& getIndent() const;
  60. /// Returns the string used for one indentation step.
  61. void writeNode(XMLByteOutputStream& ostr, const Node* pNode);
  62. /// Writes the XML for the given node to the specified stream.
  63. void writeNode(const std::string& systemId, const Node* pNode);
  64. /// Writes the XML for the given node to the file specified in systemId,
  65. /// using a standard file output stream (Poco::FileOutputStream).
  66. private:
  67. std::string _encodingName;
  68. Poco::TextEncoding* _pTextEncoding;
  69. int _options;
  70. std::string _newLine;
  71. std::string _indent;
  72. };
  73. //
  74. // inlines
  75. //
  76. inline const std::string& DOMWriter::getEncoding() const
  77. {
  78. return _encodingName;
  79. }
  80. inline int DOMWriter::getOptions() const
  81. {
  82. return _options;
  83. }
  84. inline const std::string& DOMWriter::getNewLine() const
  85. {
  86. return _newLine;
  87. }
  88. inline const std::string& DOMWriter::getIndent() const
  89. {
  90. return _indent;
  91. }
  92. } } // namespace Poco::XML
  93. #endif // DOM_DOMWriter_INCLUDED