1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-03-19 14:50:07 +03:00

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:

<?xml version="1.0"?>
<!DOCTYPE root [<!ELEMENT root EMPTY>]>
<root/>

the following script:

import libxml2
doc = libxml2.readFile("c.xml", None, libxml2.XML_PARSE_DTDLOAD)
print repr(doc.children)

prints:

<xmlNode (root) object at 0xb74963ec>

With properly cast nodes, it outputs the following:

<xmlDtd (root) object at 0xb746352c>

The latter object (xmlDtd) enables one to use DTD-specific methods such as
debugDumpDTD(), copyDTD(), and so on.
This commit is contained in:
Alexey Neyman 2013-02-20 18:28:25 -08:00 committed by Daniel Veillard
parent 23f05e0c33
commit e32ceb93f4

View File

@ -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":