From e32ceb93f425ee852021ccda157fca923a1046b0 Mon Sep 17 00:00:00 2001 From: Alexey Neyman Date: Wed, 20 Feb 2013 18:28:25 -0800 Subject: Python bindings: DOM casts everything to xmlNode I noticed another issue with Python bindings of libxml: the access methods do not cast the pointers to specific classes such as xmlDtd, xmlEntityDecl, etc. For example, with the following document: ]> the following script: import libxml2 doc = libxml2.readFile("c.xml", None, libxml2.XML_PARSE_DTDLOAD) print repr(doc.children) prints: With properly cast nodes, it outputs the following: The latter object (xmlDtd) enables one to use DTD-specific methods such as debugDumpDTD(), copyDTD(), and so on. --- python/libxml.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'python') diff --git a/python/libxml.py b/python/libxml.py index c861a70c..013d65c8 100644 --- a/python/libxml.py +++ b/python/libxml.py @@ -265,22 +265,22 @@ class xmlCore: ret = libxml2mod.parent(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) def get_children(self): ret = libxml2mod.children(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) def get_last(self): ret = libxml2mod.last(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) def get_next(self): ret = libxml2mod.next(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) def get_properties(self): ret = libxml2mod.properties(self._o) if ret == None: @@ -290,7 +290,7 @@ class xmlCore: ret = libxml2mod.prev(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) def get_content(self): return libxml2mod.xmlNodeGetContent(self._o) getContent = get_content # why is this duplicate naming needed ? @@ -317,7 +317,7 @@ class xmlCore: ret = libxml2mod.parent(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) elif attr == "properties": ret = libxml2mod.properties(self._o) if ret == None: @@ -327,22 +327,22 @@ class xmlCore: ret = libxml2mod.children(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) elif attr == "last": ret = libxml2mod.last(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) elif attr == "next": ret = libxml2mod.next(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) elif attr == "prev": ret = libxml2mod.prev(self._o) if ret == None: return None - return xmlNode(_obj=ret) + return nodeWrap(ret) elif attr == "content": return libxml2mod.xmlNodeGetContent(self._o) elif attr == "name": -- cgit v1.2.1