Hi libxml developers,

[BTW, is this list alive?]

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.

Patch attached.

Regards,
Alexey.
diff --git a/python/libxml.py b/python/libxml.py
index c861a70..193f97a 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":
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml@gnome.org
https://mail.gnome.org/mailman/listinfo/xml

Reply via email to