{
    "mode": "perldoc",
    "parameter": "XML::DOM::Document",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/XML%3A%3ADOM%3A%3ADocument/json",
    "generated": "2026-06-16T03:29:16Z",
    "sections": {
        "NAME": {
            "content": "XML::DOM::Document - An XML document node in XML::DOM\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "XML::DOM::Document extends XML::DOM::Node.\n\nIt is the main root of the XML document structure as returned by XML::DOM::Parser::parse and\nXML::DOM::Parser::parsefile.\n\nSince elements, text nodes, comments, processing instructions, etc. cannot exist outside the\ncontext of a Document, the Document interface also contains the factory methods needed to create\nthese objects. The Node objects created have a getOwnerDocument method which associates them\nwith the Document within whose context they were created.\n\nMETHODS\ngetDocumentElement\nThis is a convenience method that allows direct access to the child node that is the root\nElement of the document.\n\ngetDoctype\nThe Document Type Declaration (see DocumentType) associated with this document. For HTML\ndocuments as well as XML documents without a document type declaration this returns undef.\nThe DOM Level 1 does not support editing the Document Type Declaration.\n\nNot In DOM Spec: This implementation allows editing the doctype. See\n*XML::DOM::ignoreReadOnly* for details.\n\ngetImplementation\nThe DOMImplementation object that handles this document. A DOM application may use objects\nfrom multiple implementations.\n\ncreateElement (tagName)\nCreates an element of the type specified. Note that the instance returned implements the\nElement interface, so attributes can be specified directly on the returned object.\n\nDOMExceptions:\n\n*   INVALIDCHARACTERERR\n\nRaised if the tagName does not conform to the XML spec.\n\ncreateTextNode (data)\nCreates a Text node given the specified string.\n\ncreateComment (data)\nCreates a Comment node given the specified string.\n\ncreateCDATASection (data)\nCreates a CDATASection node given the specified string.\n\ncreateAttribute (name [, value [, specified ]])\nCreates an Attr of the given name. Note that the Attr instance can then be set on an Element\nusing the setAttribute method.\n\nNot In DOM Spec: The DOM Spec does not allow passing the value or the specified property in\nthis method. In this implementation they are optional.\n\nParameters: *value* The attribute's value. See Attr::setValue for details. If the value is\nnot supplied, the specified property is set to 0. *specified* Whether the attribute value\nwas specified or whether the default value was used. If not supplied, it's assumed to be 1.\n\nDOMExceptions:\n\n*   INVALIDCHARACTERERR\n\nRaised if the name does not conform to the XML spec.\n\ncreateProcessingInstruction (target, data)\nCreates a ProcessingInstruction node given the specified name and data strings.\n\nParameters: *target* The target part of the processing instruction. *data* The data for the\nnode.\n\nDOMExceptions:\n\n*   INVALIDCHARACTERERR\n\nRaised if the target does not conform to the XML spec.\n\ncreateDocumentFragment\nCreates an empty DocumentFragment object.\n\ncreateEntityReference (name)\nCreates an EntityReference object.\n",
            "subsections": [
                {
                    "name": "Additional methods not in the DOM Spec",
                    "content": "getXMLDecl and setXMLDecl (xmlDecl)\nReturns the XMLDecl for this Document or undef if none was specified. Note that XMLDecl is\nnot part of the list of child nodes.\n\nsetDoctype (doctype)\nSets or replaces the DocumentType. NOTE: Don't use appendChild or insertBefore to set the\nDocumentType. Even though doctype will be part of the list of child nodes, it is handled\nspecially.\n\ngetDefaultAttrValue (elem, attr)\nReturns the default attribute value as a string or undef, if none is available.\n\nParameters: *elem* The element tagName. *attr* The attribute name.\n\ngetEntity (name)\nReturns the Entity with the specified name.\n\ncreateXMLDecl (version, encoding, standalone)\nCreates an XMLDecl object. All parameters may be undefined.\n\ncreateDocumentType (name, sysId, pubId)\nCreates a DocumentType object. SysId and pubId may be undefined.\n\ncreateNotation (name, base, sysId, pubId)\nCreates a new Notation object. Consider using XML::DOM::DocumentType::addNotation!\n\ncreateEntity (parameter, notationName, value, sysId, pubId, ndata)\nCreates an Entity object. Consider using XML::DOM::DocumentType::addEntity!\n\ncreateElementDecl (name, model)\nCreates an ElementDecl object.\n\nDOMExceptions:\n\n*   INVALIDCHARACTERERR\n\nRaised if the element name (tagName) does not conform to the XML spec.\n\ncreateAttlistDecl (name)\nCreates an AttlistDecl object.\n\nDOMExceptions:\n\n*   INVALIDCHARACTERERR\n\nRaised if the element name (tagName) does not conform to the XML spec.\n\nexpandEntity (entity [, parameter])\nExpands the specified entity or parameter entity (if parameter=1) and returns its value as a\nstring, or undef if the entity does not exist. (The entity name should not contain the '%',\n'&' or ';' delimiters.)\n\ncheck ( [$checker] )\nUses the specified XML::Checker to validate the document. If no XML::Checker is supplied, a\nnew XML::Checker is created. See XML::Checker for details.\n\nchecksax ( [$checker] )\nSimilar to check() except it uses the SAX interface to XML::Checker instead of the expat\ninterface. This method may disappear or replace check() at some time.\n\ncreateChecker ()\nCreates an XML::Checker based on the document's DTD. The $checker can be reused to check any\nelements within the document. Create a new XML::Checker whenever the DOCTYPE section of the\ndocument is altered!\n"
                }
            ]
        }
    },
    "summary": "XML::DOM::Document - An XML document node in XML::DOM",
    "flags": [],
    "examples": [],
    "see_also": []
}