Re: [xml] libxml2 API crazy?

On 03May13 22:44, Nikita Churaev wrote:
}> What do you want to achieve ? I think I understand but it is better if
}> stated.
}Make so you can use libxml2 and be sure that you use it correctly rather
}than just blindly guess.
}The main problem here is casting quirks, libxml2 tree seems to cast
}xmlDoc*, xmlAttr* and even xmlNs* into xmlNode*, so not only the fields
}after the common node parts are unsafe to access without checking, even
}ones in the common part are, except xmlElementType type. The
}documentation provides no answer whatsoever on what structures
}correspond to each xmlElementType. Casting xmlNs* to xmlNode* is the
}worst one.

You seem to be talking about the internal implementation, rather than
use of the API? Can you provide specific examples in the code of how one
might be using the API in a valid fashion (ie. as documented and per the
examples) and yet be potentially using the wrong struct type?

If you are worried about "polymorphic" aspects of using certain structures
this is perfectly standard behaviour and, as I mentioned earlier, has been
well-known since K&R 2nd edition. It's also used extensively in the X11 API
and associated widget toolkits.

}I want to add:
}safe casting functions, for example:
}xmlNodePtr xmlDocToNode(xmlDocPtr node); 
}xmlDocPtr xmlNodeToDoc(xmlNodePtr node); // returns NULL if 
}                                         // node is not a doc

Why would an application being using docs as nodes and vice versa? Can you
give examples where this happens?



Callum Gibson @ home

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