[xml-bindings]libxml2.nodeWrap



Good day!
I did point out a while ago that there was a problem with CDATA elements in the nodeWrap function. As it turns out, there is a problem with the whole nodeWrap function, which uses the node's name instead of type, not to mention a few other crippling typos. (diffs below) Also of interest, if I parse a document, I find that a few nodes (the DTD declarations) are given to me as the wrong Python class to start with. In other words, if I walk over a document with the following code:

def show(node):
    newNode = libxml2.nodeWrap(node._o)
    if newNode.__class__ != node.__class__:
        print node.type,node.__class__,newNode.__class__

I find the following mistyped node types:
entity_decl libxml2.xmlNode libxml2.xmlEntity
elem_decl libxml2.xmlNode libxml2.xmlElement
attribute_decl libxml2.xmlNode libxml2.xmlAttribute

I do not know what part of the python binding code creates the original xmlNodes, but clearly there is a problem elsewhere in the code.

I do get the correct subclass for
attribute (libxml2.xmlAttr)
document_xml (libxml2.xmlDoc)
namespace (libxml2.xmlNs)

All of the other types (cdata ,comment, element, entity_ref, pi, text) also end up as libxml2.xmlNode, as intended.
(Why are there not python subclasses for those types, by the way?)

Thank you for your attention,
Marc-Antoine Parent

diff -c libxml2.py libxml2.py~
*** libxml2.py  Thu Feb 26 12:07:44 2004
--- libxml2.py~ Tue Feb 24 12:13:10 2004
***************
*** 446,464 ****
  #
  def nodeWrap(o):
      # TODO try to cast to the most appropriate node class
!     name = libxml2mod.type(o)
      if name == "element" or name == "text":
          return xmlNode(_obj=o)
      if name == "attribute":
          return xmlAttr(_obj=o)
      if name[0:8] == "document":
          return xmlDoc(_obj=o)
!     if name == "namespace":
          return xmlNs(_obj=o)
      if name == "elem_decl":
          return xmlElement(_obj=o)
      if name == "attribute_decl":
!         return xmlAttribute(_obj=o)
      if name == "entity_decl":
          return xmlEntity(_obj=o)
      if name == "dtd":
--- 446,464 ----
  #
  def nodeWrap(o):
      # TODO try to cast to the most appropriate node class
!     name = libxml2mod.name(o)
      if name == "element" or name == "text":
          return xmlNode(_obj=o)
      if name == "attribute":
          return xmlAttr(_obj=o)
      if name[0:8] == "document":
          return xmlDoc(_obj=o)
!     if name[0:8] == "namespace":
          return xmlNs(_obj=o)
      if name == "elem_decl":
          return xmlElement(_obj=o)
      if name == "attribute_decl":
!         return xmlAtribute(_obj=o)
      if name == "entity_decl":
          return xmlEntity(_obj=o)
      if name == "dtd":




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]