XmlDocument::CreateDocumentType Method
Returns a new XmlDocumentType object.
Assembly: System.Xml (in System.Xml.dll)
[PermissionSetAttribute(SecurityAction::InheritanceDemand, Name = L"FullTrust")] public: virtual XmlDocumentType^ CreateDocumentType( String^ name, String^ publicId, String^ systemId, String^ internalSubset )
Parameters
- name
- Type: System::String
Name of the document type.
- publicId
- Type: System::String
The public identifier of the document type or nullptr. You can specify a public URI and also a system identifier to identify the location of the external DTD subset.
- systemId
- Type: System::String
The system identifier of the document type or nullptr. Specifies the URL of the file location for the external DTD subset.
- internalSubset
- Type: System::String
The DTD internal subset of the document type or nullptr.
The returned node will have parsed Entities and Notations collections.
Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. To add the new object, you must explicitly call one of the node insert methods.
According to the W3C Extensible Markup Language (XML) 1.0 recommendation (www.w3.org/TR/1998/REC-xml-19980210), DocumentType nodes are only allowed within Document nodes. Each XmlDocument can have only one DocumentType node. The DocumentType node must also be inserted before the root element of the XmlDocument (if the document already has a root element, you cannot add a DocumentType node).
If the passed parameters do not combine to build a valid XmlDocumentType, an exception is thrown.
Notes to InheritorsThis method has an inheritance demand. Full trust is required to override the CreateDocumentType method. See Inheritance Demands for more information.
This method is a Microsoft extension to the Document Object Model (DOM).
The following example creates a DocumentType node and adds it to an XML document.
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { //Create the XmlDocument. XmlDocument^ doc = gcnew XmlDocument; //Create a document type node and //add it to the document. XmlDocumentType^ doctype; doctype = doc->CreateDocumentType( "book", nullptr, nullptr, "<!ELEMENT book ANY>" ); doc->AppendChild( doctype ); //Create the root element and //add it to the document. doc->AppendChild( doc->CreateElement( "book" ) ); Console::WriteLine( "Display the modified XML..." ); doc->Save( Console::Out ); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.