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