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

Class DOMImplementation

Lib/xml/dom/minidom.py:1428–1505  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1426
1427
1428class DOMImplementation(DOMImplementationLS):
1429 _features = [("core", "1.0"),
1430 ("core", "2.0"),
1431 ("core", None),
1432 ("xml", "1.0"),
1433 ("xml", "2.0"),
1434 ("xml", None),
1435 ("ls-load", "3.0"),
1436 ("ls-load", None),
1437 ]
1438
1439 def hasFeature(self, feature, version):
1440 if version == "":
1441 version = None
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

Callers 1

DocumentClass · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…