1.1 --- a/libxml2dom/__init__.py Sat Aug 30 00:51:04 2008 +0200
1.2 +++ b/libxml2dom/__init__.py Sun Aug 31 01:31:31 2008 +0200
1.3 @@ -29,6 +29,7 @@
1.4 toString as Node_toString, toStream as Node_toStream, \
1.5 toFile as Node_toFile
1.6 import urllib # for parseURI in HTML mode
1.7 +import libxml2dom.errors
1.8
1.9 # Standard namespaces.
1.10
1.11 @@ -392,9 +393,9 @@
1.12
1.13 def insertBefore(self, tmp, oldNode):
1.14 if tmp.ownerDocument != self.ownerDocument:
1.15 - raise xml.dom.DOMException(xml.dom.WRONG_DOCUMENT_ERR)
1.16 + raise xml.dom.WrongDocumentErr()
1.17 if oldNode.parentNode != self:
1.18 - raise xml.dom.DOMException(xml.dom.NOT_FOUND_ERR)
1.19 + raise xml.dom.NotFoundErr()
1.20 if hasattr(tmp, "as_native_node"):
1.21 return self.impl.get_node(Node_insertBefore(self._node, tmp.as_native_node(), oldNode.as_native_node()), self)
1.22 else:
1.23 @@ -402,9 +403,9 @@
1.24
1.25 def replaceChild(self, tmp, oldNode):
1.26 if tmp.ownerDocument != self.ownerDocument:
1.27 - raise xml.dom.DOMException(xml.dom.WRONG_DOCUMENT_ERR)
1.28 + raise xml.dom.WrongDocumentErr()
1.29 if oldNode.parentNode != self:
1.30 - raise xml.dom.DOMException(xml.dom.NOT_FOUND_ERR)
1.31 + raise xml.dom.NotFoundErr()
1.32 if hasattr(tmp, "as_native_node"):
1.33 return self.impl.get_node(Node_replaceChild(self._node, tmp.as_native_node(), oldNode.as_native_node()), self)
1.34 else:
1.35 @@ -412,7 +413,7 @@
1.36
1.37 def appendChild(self, tmp):
1.38 if tmp.ownerDocument != self.ownerDocument:
1.39 - raise xml.dom.DOMException(xml.dom.WRONG_DOCUMENT_ERR)
1.40 + raise xml.dom.WrongDocumentErr()
1.41 if hasattr(tmp, "as_native_node"):
1.42 return self.impl.get_node(Node_appendChild(self._node, tmp.as_native_node()), self)
1.43 else:
1.44 @@ -558,12 +559,23 @@
1.45
1.46 """
1.47 An abstract class providing document-level housekeeping and distinct
1.48 - functionality.
1.49 + functionality. Configuration of the document is also supported.
1.50 + See: http://www.w3.org/TR/DOM-Level-3-Core/core.html#DOMConfiguration
1.51 """
1.52
1.53 + # Constants from
1.54 + # See: http://www.w3.org/TR/DOM-Level-3-Val/validation.html#VAL-Interfaces-NodeEditVAL
1.55 +
1.56 + VAL_TRUE = 5
1.57 + VAL_FALSE = 6
1.58 + VAL_UNKNOWN = 7
1.59 +
1.60 def __init__(self, node, impl):
1.61 self._node = node
1.62 self.implementation = self.impl = impl
1.63 + self.error_handler = libxml2dom.errors.DOMErrorHandler()
1.64 +
1.65 + # Standard DOM properties and their implementations.
1.66
1.67 def _documentElement(self):
1.68 return self.xpath("*")[0]
1.69 @@ -578,6 +590,53 @@
1.70 documentElement = property(_documentElement)
1.71 ownerDocument = property(_ownerDocument)
1.72
1.73 + # DOM Level 3 Core DOMConfiguration methods.
1.74 +
1.75 + def setParameter(self, name, value):
1.76 + if name == "error-handler":
1.77 + raise xml.dom.NotSupportedErr()
1.78 + raise xml.dom.NotFoundErr()
1.79 +
1.80 + def getParameter(self, name):
1.81 + if name == "error-handler":
1.82 + return self.error_handler
1.83 + raise xml.dom.NotFoundErr()
1.84 +
1.85 + def canSetParameter(self, name, value):
1.86 + return 0
1.87 +
1.88 + def _parameterNames(self):
1.89 + return []
1.90 +
1.91 + # Extensions to the usual PyXML API.
1.92 +
1.93 + def validate(self, doc):
1.94 +
1.95 + """
1.96 + Validate the document against the given schema document, 'doc'.
1.97 + """
1.98 +
1.99 + if hasattr(doc, "as_native_node"):
1.100 + _schema = Document_schema(doc.as_native_node())
1.101 + else:
1.102 + _schema = Document_schemaFromString(doc.toString())
1.103 + try:
1.104 + self.error_handler.reset()
1.105 + return Document_validate(_schema, self._node, self.error_handler)
1.106 + finally:
1.107 + Schema_free(_schema)
1.108 +
1.109 + # DOM Level 3 Validation methods.
1.110 +
1.111 + def validateDocument(self, doc):
1.112 +
1.113 + """
1.114 + Validate the document against the given schema document, 'doc'.
1.115 + See: http://www.w3.org/TR/DOM-Level-3-Val/validation.html#VAL-Interfaces-DocumentEditVAL-validateDocument
1.116 + """
1.117 +
1.118 + return self.validate(doc) and self.VAL_TRUE or self.VAL_FALSE
1.119 +
1.120 class Document(_Document, Node):
1.121
1.122 """