Re: [xml] libxml2 API crazy?
- From: Nikita Churaev <lamefun x0r gmail com>
- To: Nikolay Sivov <bunglehead gmail com>
- Cc: xml gnome org
- Subject: Re: [xml] libxml2 API crazy?
- Date: Mon, 29 Apr 2013 08:18:44 +0400
Is this allowed by the C standard? And where is this documented?
On Mon, 2013-04-29 at 08:14 +0400, Nikolay Sivov wrote:
On 4/29/2013 07:59, Nikita Churaev wrote:
No it's not.
http://xmlsoft.org/html/libxml-tree.html#xmlDoc
http://xmlsoft.org/html/libxml-tree.html#xmlNode
xmlDoc has int compression instead of xmlNode's xmlNs
I see what you mean. All node types are using same layout containing basic
stuff to link node in a tree - up to 'doc' field. That's what a comment
in tree.h means:
---
struct _xmlNode {
void *_private; /* application data */
xmlElementType type; /* type number, must be second ! */
const xmlChar *name; /* the name of the node, or the entity */
struct _xmlNode *children; /* parent->childs link */
struct _xmlNode *last; /* last child link */
struct _xmlNode *parent; /* child->parent link */
struct _xmlNode *next; /* next sibling link */
struct _xmlNode *prev; /* previous sibling link */
struct _xmlDoc *doc; /* the containing document */
/* End of common part */
---
So to be clean with casting it should have some sort of header struct
containing these fields only,
and have every node type start with this header, it's just not done this
way. To be safe you always
need to check type and cast appropriately.
On Mon, 2013-04-29 at 07:48 +0400, Nikolay Sivov wrote:
On 4/29/2013 07:30, Nikita Churaev wrote:
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <stdio.h>
int
main (int argc, char** argv)
{
xmlDocPtr doc = xmlReadMemory("<doc/>", 6, "egg.xml", NULL, 0);
/* XmlNode */ /* XmlDoc */
printf("%s\n", (doc->children->parent == doc) ? "true" : "false");
return 0;
}
This gives out "true"... Why? xmlNode.parent is xmlNodePtr... So I can't
just rely on xmlNode pointers to actually point to xmlNode?
Just take a look what xmlDocPtr actually is - document is also a node.
I looked all
around the API reference and tutorials and found nothing on this topic.
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
https://mail.gnome.org/mailman/listinfo/xml
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
https://mail.gnome.org/mailman/listinfo/xml
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
https://mail.gnome.org/mailman/listinfo/xml
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
https://mail.gnome.org/mailman/listinfo/xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]