CDATASection.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // CDATASection.h
  3. //
  4. // Library: XML
  5. // Package: DOM
  6. // Module: DOM
  7. //
  8. // Definition of the DOM CDATASection class.
  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_CDATASection_INCLUDED
  16. #define DOM_CDATASection_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/DOM/Text.h"
  19. namespace Poco {
  20. namespace XML {
  21. class XML_API CDATASection: public Text
  22. /// CDATA sections are used to escape blocks of text containing characters that
  23. /// would otherwise be regarded as markup. The only delimiter that is recognized
  24. /// in a CDATA section is the "]]>" string that ends the CDATA section. CDATA
  25. /// sections cannot be nested. Their primary purpose is for including material
  26. /// such as XML fragments, without needing to escape all the delimiters.
  27. ///
  28. /// The DOMString attribute of the Text node holds the text that is contained
  29. /// by the CDATA section. Note that this may contain characters that need to
  30. /// be escaped outside of CDATA sections and that, depending on the character
  31. /// encoding ("charset") chosen for serialization, it may be impossible to write
  32. /// out some characters as part of a CDATA section.
  33. ///
  34. /// The CDATASection interface inherits from the CharacterData interface through
  35. /// the Text interface. Adjacent CDATASection nodes are not merged by use of
  36. /// the normalize method on the Element interface.
  37. ///
  38. /// Note: Because no markup is recognized within a CDATASection, character numeric
  39. /// references cannot be used as an escape mechanism when serializing. Therefore,
  40. /// action needs to be taken when serializing a CDATASection with a character
  41. /// encoding where some of the contained characters cannot be represented. Failure
  42. /// to do so would not produce well-formed XML.
  43. /// One potential solution in the serialization process is to end the CDATA
  44. /// section before the character, output the character using a character reference
  45. /// or entity reference, and open a new CDATA section for any further characters
  46. /// in the text node. Note, however, that some code conversion libraries at
  47. /// the time of writing do not return an error or exception when a character
  48. /// is missing from the encoding, making the task of ensuring that data is not
  49. /// corrupted on serialization more difficult.
  50. {
  51. public:
  52. // Text
  53. Text* splitText(unsigned long offset);
  54. // Node
  55. const XMLString& nodeName() const;
  56. unsigned short nodeType() const;
  57. protected:
  58. CDATASection(Document* pOwnerDocument, const XMLString& data);
  59. CDATASection(Document* pOwnerDocument, const CDATASection& sec);
  60. ~CDATASection();
  61. Node* copyNode(bool deep, Document* pOwnerDocument) const;
  62. private:
  63. static const XMLString NODE_NAME;
  64. friend class Document;
  65. };
  66. } } // namespace Poco::XML
  67. #endif // DOM_CDATASection_INCLUDED