DocumentFragment.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // DocumentFragment.h
  3. //
  4. // Library: XML
  5. // Package: DOM
  6. // Module: DOM
  7. //
  8. // Definition of the DOM DocumentFragment 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_DocumentFragment_INCLUDED
  16. #define DOM_DocumentFragment_INCLUDED
  17. #include "Poco/XML/XML.h"
  18. #include "Poco/DOM/AbstractContainerNode.h"
  19. #include "Poco/XML/XMLString.h"
  20. namespace Poco {
  21. namespace XML {
  22. class XML_API DocumentFragment: public AbstractContainerNode
  23. /// DocumentFragment is a "lightweight" or "minimal" Document object. It is
  24. /// very common to want to be able to extract a portion of a document's tree
  25. /// or to create a new fragment of a document. Imagine implementing a user command
  26. /// like cut or rearranging a document by moving fragments around. It is desirable
  27. /// to have an object which can hold such fragments and it is quite natural
  28. /// to use a Node for this purpose. While it is true that a Document object
  29. /// could fulfill this role, a Document object can potentially be a heavyweight
  30. /// object, depending on the underlying implementation. What is really needed
  31. /// for this is a very lightweight object. DocumentFragment is such an object.
  32. ///
  33. /// Furthermore, various operations -- such as inserting nodes as children of
  34. /// another Node -- may take DocumentFragment objects as arguments; this results
  35. /// in all the child nodes of the DocumentFragment being moved to the child
  36. /// list of this node.
  37. ///
  38. /// The children of a DocumentFragment node are zero or more nodes representing
  39. /// the tops of any sub-trees defining the structure of the document. DocumentFragment
  40. /// nodes do not need to be well-formed XML documents (although they do need
  41. /// to follow the rules imposed upon well-formed XML parsed entities, which
  42. /// can have multiple top nodes). For example, a DocumentFragment might have
  43. /// only one child and that child node could be a Text node. Such a structure
  44. /// model represents neither an HTML document nor a well-formed XML document.
  45. ///
  46. /// When a DocumentFragment is inserted into a Document (or indeed any other
  47. /// Node that may take children) the children of the DocumentFragment and not
  48. /// the DocumentFragment itself are inserted into the Node. This makes the DocumentFragment
  49. /// very useful when the user wishes to create nodes that are siblings; the
  50. /// DocumentFragment acts as the parent of these nodes so that the user can
  51. /// use the standard methods from the Node interface, such as insertBefore and
  52. /// appendChild.
  53. {
  54. public:
  55. // Node
  56. const XMLString& nodeName() const;
  57. unsigned short nodeType() const;
  58. protected:
  59. DocumentFragment(Document* pOwnerDocument);
  60. DocumentFragment(Document* pOwnerDocument, const DocumentFragment& fragment);
  61. ~DocumentFragment();
  62. Node* copyNode(bool deep, Document* pOwnerDocument) const;
  63. private:
  64. static const XMLString NODE_NAME;
  65. friend class Document;
  66. };
  67. } } // namespace Poco::XML
  68. #endif // DOM_DocumentFragment_INCLUDED