|
I never thought of it ... I just code as
suggested: node->parent == node->doc or node->parent->type == XML_ELEMENT_NODE/XML_DOCUMENT_NODE and so on before you assume it really is a xmlNode In fact, I always test the type before doing anything EXCEPT that one node->parent == node->doc test which somehow I picked up someplace (old samples?) I just don't find it strange AT ALL in the C world to have pointers that point to different things and need conditional processing based on a type. Try coding with Oracle's C interface for example (not the SQL or higher language, they still have an actual C interface). It has all kinds of pointers to all kinds of things that require tests if they are non-NULL and what type they are. C is not a language that has objects and protections against everything ... it is a language great for performance when coded properly. As an example, I have a customer that hired a new IT manager who decided that using my old fashioned non-object oriented "hard to program" (if you don't know C :-) ), etc. server program was awful and needed to be replaced. It is a simple server fired up by inetd and reads in an XML document and returns one (generally after doing some database calls -- it servers Web pages and large XML file uploads for example 1,000 orders in a batch from Walmart. On a VERY modest AIX box I process in and out about 2.5 million documents in a day. So they paid a nice young man to replace my server with a JAVA server (why do people feel compelled to replace working programs I'll never know -- guess the new IT person had to feel important). JAVA has built-in XML and TCP/IP and it was so "easy" to program, yack yack ... it also fell to it's knees at volumes that would be about 10,000 documents per day if it did not crash and burn when the load got high. That is less than 1/2% of what my libxml2 server can process. This, of course, led to AIX trashing and the IT guy wanted a room full of Linux boxes with server load balancing and all kinds of things. Fortunately sanity prevailed and the new IT guys is gone. The cheap little AIX box purrs doing all that work (and running the order desk, inventory, warehouse, shipping, credit, accounting -- all in real time all on one little box) ... E On 5/3/2013 9:15 PM, Callum Gibson wrote:
-- Eric S. Eberhard VICS 2933 W Middle Verde Road Camp Verde, AZ 86322 928-567-3727 work 928-301-7537 cell http://www.vicsmba.com/index.html (our work) http://www.vicsmba.com/ourpics/index.html (fun pictures) |