1.1 --- a/libxml2dom/__init__.py Thu Dec 01 01:58:25 2005 +0000
1.2 +++ b/libxml2dom/__init__.py Thu Dec 01 01:59:06 2005 +0000
1.3 @@ -4,9 +4,8 @@
1.4 DOM wrapper around libxml2, specifically the libxml2mod Python extension module.
1.5 """
1.6
1.7 -__version__ = "0.2.4"
1.8 +__version__ = "0.2.5"
1.9
1.10 -import libxml2
1.11 from libxml2dom.macrolib import *
1.12 from libxml2dom.macrolib import \
1.13 createDocument as Node_createDocument, \
1.14 @@ -174,6 +173,42 @@
1.15 def _nextSibling(self):
1.16 return Node(Node_nextSibling(self._node), self.ownerDocument)
1.17
1.18 + def _doctype(self):
1.19 + return Node(Node_doctype(self._node), self.ownerDocument)
1.20 +
1.21 + def _publicId(self):
1.22 + # NOTE: To be fixed when the libxml2mod API has been figured out.
1.23 + if self.nodeType != self.DOCUMENT_TYPE_NODE:
1.24 + return None
1.25 + declaration = self.toString()
1.26 + return self._findId(declaration, "PUBLIC")
1.27 +
1.28 + def _systemId(self):
1.29 + # NOTE: To be fixed when the libxml2mod API has been figured out.
1.30 + if self.nodeType != self.DOCUMENT_TYPE_NODE:
1.31 + return None
1.32 + declaration = self.toString()
1.33 + if self._findId(declaration, "PUBLIC"):
1.34 + return self._findIdValue(declaration, 0)
1.35 + return self._findId(declaration, "SYSTEM")
1.36 +
1.37 + # NOTE: To be removed when the libxml2mod API has been figured out.
1.38 +
1.39 + def _findId(self, declaration, identifier):
1.40 + i = declaration.find(identifier)
1.41 + if i == -1:
1.42 + return None
1.43 + return self._findIdValue(declaration, i)
1.44 +
1.45 + def _findIdValue(self, declaration, i):
1.46 + q = declaration.find('"', i)
1.47 + if q == -1:
1.48 + return None
1.49 + q2 = declaration.find('"', q + 1)
1.50 + if q2 == -1:
1.51 + return None
1.52 + return declaration[q+1:q2]
1.53 +
1.54 def hasAttributeNS(self, ns, localName):
1.55 return Node_hasAttributeNS(self._node, ns, localName)
1.56
1.57 @@ -285,8 +320,6 @@
1.58 texts.append(text_nodes[-1].nodeValue)
1.59 self.replaceChild(self.ownerDocument.createTextNode("".join(texts)), text_nodes[-1])
1.60
1.61 - # NOTE: normalize must be implemented specially for libxml2dom.
1.62 -
1.63 childNodes = property(_childNodes)
1.64 value = data = nodeValue = property(_nodeValue, _setNodeValue)
1.65 name = nodeName = property(_nodeName)
1.66 @@ -299,6 +332,14 @@
1.67 attributes = property(_attributes)
1.68 previousSibling = property(_previousSibling)
1.69 nextSibling = property(_nextSibling)
1.70 + doctype = property(_doctype)
1.71 + publicId = property(_publicId)
1.72 + systemId = property(_systemId)
1.73 +
1.74 + # NOTE: To be fixed - these being doctype-specific values.
1.75 +
1.76 + entities = {}
1.77 + notations = {}
1.78
1.79 #def isSameNode(self, other):
1.80 # return self._node.nodePath() == other._node.nodePath()
1.81 @@ -355,11 +396,30 @@
1.82 def _ownerDocument(self):
1.83 return self.weakref_ownerDocument()
1.84
1.85 + def _parentNode(self):
1.86 + return None
1.87 +
1.88 def __del__(self):
1.89 #print "Freeing document", self._node
1.90 libxml2mod.xmlFreeDoc(self._node)
1.91
1.92 ownerDocument = property(_ownerDocument)
1.93 + parentNode = property(_parentNode)
1.94 +
1.95 +class DocumentType(object):
1.96 +
1.97 + "A class providing a container for document type information."
1.98 +
1.99 + def __init__(self, localName, publicId, systemId):
1.100 + self.name = self.localName = localName
1.101 + self.publicId = publicId
1.102 + self.systemId = systemId
1.103 +
1.104 + # NOTE: Nothing is currently provided to support the following
1.105 + # NOTE: attributes.
1.106 +
1.107 + self.entities = {}
1.108 + self.notations = {}
1.109
1.110 # Factory functions.
1.111
1.112 @@ -374,7 +434,7 @@
1.113 # Utility functions.
1.114
1.115 def createDocumentType(localName, publicId, systemId):
1.116 - return None
1.117 + return DocumentType(localName, publicId, systemId)
1.118
1.119 def createDocument(namespaceURI, localName, doctype):
1.120 return Document(Node_createDocument(namespaceURI, localName, doctype))