blob: da736bef5b695bd8bdc1e01f750bf44732b37cb6 [file] [log] [blame]
Daniel Veillard5e5c2d02002-02-09 18:03:01 +00001import libxml2mod
Daniel Veillardd2897fd2002-01-30 16:37:32 +00002
Daniel Veillard1971ee22002-01-31 20:29:19 +00003#
4# This class is the ancestor of all the Node classes. It provides
5# the basic functionalities shared by all nodes (and handle
6# gracefylly the exception), like name, navigation in the tree,
7# doc reference and content access
8#
Daniel Veillard36ed5292002-01-30 23:49:06 +00009class xmlCore:
Daniel Veillardd2897fd2002-01-30 16:37:32 +000010 def __init__(self, _obj=None):
11 if _obj != None:
Daniel Veillard01a6d412002-02-11 18:42:20 +000012 self._o = _obj;
13 return
14 self._o = None
Daniel Veillardd2897fd2002-01-30 16:37:32 +000015
Daniel Veillardd2897fd2002-01-30 16:37:32 +000016 def __getattr__(self, attr):
17 if attr == "parent":
Daniel Veillard01a6d412002-02-11 18:42:20 +000018 ret = libxml2mod.parent(self._o)
19 if ret == None:
20 return None
21 return xmlNode(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +000022 elif attr == "properties":
Daniel Veillard01a6d412002-02-11 18:42:20 +000023 ret = libxml2mod.properties(self._o)
24 if ret == None:
25 return None
26 return xmlAttr(_obj=ret)
27 elif attr == "children":
28 ret = libxml2mod.children(self._o)
29 if ret == None:
30 return None
31 return xmlNode(_obj=ret)
32 elif attr == "last":
33 ret = libxml2mod.last(self._o)
34 if ret == None:
35 return None
36 return xmlNode(_obj=ret)
37 elif attr == "next":
38 ret = libxml2mod.next(self._o)
39 if ret == None:
40 return None
41 return xmlNode(_obj=ret)
42 elif attr == "prev":
43 ret = libxml2mod.prev(self._o)
44 if ret == None:
45 return None
46 return xmlNode(_obj=ret)
47 elif attr == "content":
48 return libxml2mod.xmlNodeGetContent(self._o)
49 elif attr == "name":
50 return libxml2mod.name(self._o)
51 elif attr == "type":
52 return libxml2mod.type(self._o)
53 elif attr == "doc":
54 ret = libxml2mod.doc(self._o)
55 if ret == None:
56 return None
57 return xmlDoc(_doc=ret)
58 raise AttributeError,attr
Daniel Veillardd2897fd2002-01-30 16:37:32 +000059
Daniel Veillard01a6d412002-02-11 18:42:20 +000060 #
61 # Those are common attributes to nearly all type of nodes
62 #
Daniel Veillardd2897fd2002-01-30 16:37:32 +000063 def get_parent(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +000064 ret = libxml2mod.parent(self._o)
65 if ret == None:
66 return None
67 return xmlNode(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +000068 def get_children(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +000069 ret = libxml2mod.children(self._o)
70 if ret == None:
71 return None
72 return xmlNode(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +000073 def get_last(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +000074 ret = libxml2mod.last(self._o)
75 if ret == None:
76 return None
77 return xmlNode(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +000078 def get_next(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +000079 ret = libxml2mod.next(self._o)
80 if ret == None:
81 return None
82 return xmlNode(_obj=ret)
Daniel Veillard1971ee22002-01-31 20:29:19 +000083 def get_properties(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +000084 ret = libxml2mod.properties(self._o)
85 if ret == None:
86 return None
87 return xmlAttr(_obj=ret)
Daniel Veillard1971ee22002-01-31 20:29:19 +000088 def get_doc(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +000089 ret = libxml2mod.doc(self._o)
90 if ret == None:
91 return None
92 return xmlDoc(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +000093 def get_prev(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +000094 ret = libxml2mod.prev(self._o)
95 if ret == None:
96 return None
97 return xmlNode(_obj=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +000098 def get_content(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +000099 return libxml2mod.xmlNodeGetContent(self._o)
Daniel Veillard1971ee22002-01-31 20:29:19 +0000100 def getContent(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000101 return libxml2mod.xmlNodeGetContent(self._o)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000102 def get_name(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000103 return libxml2mod.name(self._o)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000104 def get_type(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000105 return libxml2mod.type(self._o)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000106 def get_doc(self):
Daniel Veillard01a6d412002-02-11 18:42:20 +0000107 ret = libxml2mod.doc(self._o)
108 if ret == None:
109 return None
110 return xmlDoc(_doc=ret)
Daniel Veillardd2897fd2002-01-30 16:37:32 +0000111 def free(self):
Daniel Veillard5e5c2d02002-02-09 18:03:01 +0000112 libxml2mod.freeDoc(self._o)
Daniel Veillard01a6d412002-02-11 18:42:20 +0000113
Daniel Veillard36ed5292002-01-30 23:49:06 +0000114#
Daniel Veillard1971ee22002-01-31 20:29:19 +0000115# converters to present a nicer view of the XPath returns
116#
117def nodeWrap(o):
118 # TODO try to cast to the most appropriate node class
Daniel Veillard5e5c2d02002-02-09 18:03:01 +0000119 name = libxml2mod.name(o)
Daniel Veillard1971ee22002-01-31 20:29:19 +0000120 if name == "element" or name == "text":
121 return xmlNode(_obj=o)
122 if name == "attribute":
123 return xmlAttr(_obj=o)
124 if name[0:8] == "document":
125 return xmlDoc(_obj=o)
126 if name[0:8] == "namespace":
127 return xmlNs(_obj=o)
128 if name == "elem_decl":
129 return xmlElement(_obj=o)
130 if name == "attribute_decl":
131 return xmlAtribute(_obj=o)
132 if name == "entity_decl":
133 return xmlEntity(_obj=o)
134 if name == "dtd":
135 return xmlAttr(_obj=o)
136 return xmlNode(_obj=o)
137
138def xpathObjectRet(o):
139 if type(o) == type([]) or type(o) == type(()):
140 ret = map(lambda x: nodeWrap(x), o)
Daniel Veillard01a6d412002-02-11 18:42:20 +0000141 return ret
Daniel Veillard1971ee22002-01-31 20:29:19 +0000142 return o
143
144#
Daniel Veillarda7340c82002-02-01 17:56:45 +0000145# register an XPath function
146#
147def registerXPathFunction(ctxt, name, ns_uri, f):
Daniel Veillard5e5c2d02002-02-09 18:03:01 +0000148 ret = libxml2mod.xmlRegisterXPathFunction(ctxt, name, ns_uri, f)
Daniel Veillarda7340c82002-02-01 17:56:45 +0000149
Daniel Veillard797a5652002-02-12 13:46:21 +0000150
Daniel Veillarda7340c82002-02-01 17:56:45 +0000151#
Daniel Veillard36ed5292002-01-30 23:49:06 +0000152# Everything below this point is automatically generated
153#
Daniel Veillard1971ee22002-01-31 20:29:19 +0000154