summaryrefslogtreecommitdiffstats
path: root/src/3rdparty/libcroco/cr-libxml-node-iface.c
blob: bc860f974bbc41e147bc07b7e96d3692c3d97aeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <libxml/tree.h>
#include <string.h>
#include "cr-libxml-node-iface.h"

static CRXMLNodePtr
libxml_getParentNode(CRXMLNodePtr cnode)
{
	xmlNode const *xnode = (xmlNode const *) cnode;
	return xnode->parent;
}

static CRXMLNodePtr
libxml_getFirstChild(CRXMLNodePtr cnode)
{
	xmlNode const *xnode = (xmlNode const *) cnode;
	return xnode->children;
}

static CRXMLNodePtr
libxml_getNextSibling(CRXMLNodePtr cnode)
{
	xmlNode const *xnode = (xmlNode const *) cnode;
	return xnode->next;
}

static CRXMLNodePtr
libxml_getPrevSibling(CRXMLNodePtr cnode)
{
	xmlNode const *xnode = (xmlNode const *) cnode;
	return xnode->prev;
}

static char const *
local_part(char const *const qname)
{
	char const *ret = strrchr(qname, ':');
	if (ret)
		return ++ret;
	else
		return qname;
}

static char const *
libxml_getLocalName(CRXMLNodePtr cnode)
{
	xmlNode const *xnode = (xmlNode const *) cnode;
	return local_part((char *)xnode->name);
}

static char *
libxml_getProp(CRXMLNodePtr cnode, char const *cprop)
{
	xmlNodePtr xnode = (xmlNodePtr) cnode;
	xmlChar const *xprop = (xmlChar const *) cprop;
	return (char *)xmlGetProp(xnode, xprop);
}

static gboolean
libxml_isElementNode(CRXMLNodePtr cnode)
{
	xmlNode const *xnode = (xmlNode const *) cnode;
	return xnode->type == XML_ELEMENT_NODE;
}

static void
libxml_freePropVal(void *const cval)
{
	xmlFree(cval);
}

CRNodeIface const cr_libxml_node_iface = {
	libxml_getParentNode,
	libxml_getFirstChild,
	libxml_getNextSibling,
	libxml_getPrevSibling,
	libxml_getLocalName,
	libxml_getProp,  /* fixme: Check whether we want xmlGetNoNsProp instead. */

	libxml_freePropVal,
	libxml_isElementNode
};