From W3C Document Object Model (Core) Level 1 specification (bold is mine):
Most of the APIs defined by this specification are interfaces rather than classes. That means that an actual implementation need only expose methods with the defined names and specified operation, not actually implement classes that correspond directly to the interfaces. This allows the DOM APIs to be implemented as a thin veneer on top of legacy applications with their own data structures, or on top of newer applications with different class hierarchies. This also means that ordinary constructors (in the Java or C++ sense) cannot be used to create DOM objects, since the underlying objects to be constructed may have little relationship to the DOM interfaces. The conventional solution to this in object-oriented design is to define factory methods that create instances of objects that implement the various interfaces. In the DOM Level 1, objects implementing some interface "X" are created by a "createX()" method on the Document interface; this is because all DOM objects live in the context of a specific Document.
AFAIK, you can not create any XmlNode
(XmlElement, XmlAttribute, XmlCDataSection
, etc) except XmlDocument
from a constructor.
Moreover, note that you can not use XmlDocument.AppendChild()
for nodes that are not created via the factory methods of the same document. In case you have a node from another document, you must use XmlDocument.ImportNode()
.