MCPcopy Index your code
hub / github.com/python/cpython / createDocument

Method createDocument

Lib/xml/dom/minidom.py:1444–1487  ·  view source on GitHub ↗
(self, namespaceURI, qualifiedName, doctype)

Source from the content-addressed store, hash-verified

1442 return (feature.lower(), version) in self._features
1443
1444 def createDocument(self, namespaceURI, qualifiedName, doctype):
1445 if doctype and doctype.parentNode is not None:
1446 raise xml.dom.WrongDocumentErr(
1447 "doctype object owned by another DOM tree")
1448 doc = self._create_document()
1449
1450 add_root_element = not (namespaceURI is None
1451 and qualifiedName is None
1452 and doctype is None)
1453
1454 if not qualifiedName and add_root_element:
1455 # The spec is unclear what to raise here; SyntaxErr
1456 # would be the other obvious candidate. Since Xerces raises
1457 # InvalidCharacterErr, and since SyntaxErr is not listed
1458 # for createDocument, that seems to be the better choice.
1459 # XXX: need to check for illegal characters here and in
1460 # createElement.
1461
1462 # DOM Level III clears this up when talking about the return value
1463 # of this function. If namespaceURI, qName and DocType are
1464 # Null the document is returned without a document element
1465 # Otherwise if doctype or namespaceURI are not None
1466 # Then we go back to the above problem
1467 raise xml.dom.InvalidCharacterErr("Element with no name")
1468
1469 if add_root_element:
1470 prefix, localname = _nssplit(qualifiedName)
1471 if prefix == "xml" \
1472 and namespaceURI != "http://www.w3.org/XML/1998/namespace":
1473 raise xml.dom.NamespaceErr("illegal use of 'xml' prefix")
1474 if prefix and not namespaceURI:
1475 raise xml.dom.NamespaceErr(
1476 "illegal use of prefix without namespaces")
1477 element = doc.createElementNS(namespaceURI, qualifiedName)
1478 if doctype:
1479 doc.appendChild(doctype)
1480 doc.appendChild(element)
1481
1482 if doctype:
1483 doctype.parentNode = doctype.ownerDocument = doc
1484
1485 doc.doctype = doctype
1486 doc.implementation = self
1487 return doc
1488
1489 def createDocumentType(self, qualifiedName, publicId, systemId):
1490 doctype = DocumentType(qualifiedName)

Callers 6

workMethod · 0.80
testRenameOtherMethod · 0.80
cloneNodeMethod · 0.80
buildDocumentMethod · 0.80
resetMethod · 0.80

Calls 4

_create_documentMethod · 0.95
_nssplitFunction · 0.85
createElementNSMethod · 0.80
appendChildMethod · 0.45

Tested by 3

workMethod · 0.64
testRenameOtherMethod · 0.64