/src/wrappers/xml/library/xml2_node.e
Specman e | 105 lines | 70 code | 18 blank | 17 comment | 3 complexity | 3f5ce95173435bdd0f165e047335376b MD5 | raw file
1note 2 description: "." 3 copyright: "[ 4 Copyright (C) 2008-2017: Paolo Redaelli 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public License 8 as published by the Free Software Foundation; either version 2.1 of 9 the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301 USA 20 ]" 21 22class XML2_NODE 23 -- Minimal wrapper for xmlNode of libxml2. No effort is made to mimick 24 -- SmartEiffel XML classes: their design does simply not conform. 25 26inherit 27 C_STRUCT redefine free end 28 MIXED_MEMORY_HANDLING redefine free end 29 30insert 31 SHARED_XML2_NODE_CACHE 32 LIBXML2_EXTERNALS 33 34create {ANY} from_external_pointer 35 36feature {ANY} -- Name and attributes 37 name: STRING 38 -- Name of the node. 39 do 40 create Result.from_external_copy(xml_node_get_name(handle)) 41 end 42 43 attribute_at (a_name: STRING): STRING 44 -- The content of the attribute named `a_name' encoded in UTF8. 45 -- Void if the attribute does not exist. 46 47 -- TODO: Result should be an heir of STRING like XML2_STRING because the 48 -- string pointer shall be free with xmlFree 49 require non_void_name: a_name/=Void 50 local p: POINTER 51 do 52 p:=xml_get_prop(handle,a_name.to_external) 53 if p.is_not_null then 54 create Result.from_external(p) 55 end 56 end 57 58 -- first_attribute: XML2_ATTRIBUTE 59 -- -- The first attribute/property 60 -- do 61 -- not_yet_implemented 62 -- end 63 64feature {ANY} -- Nodes relationships 65 parent: XML2_NODE 66 -- Curren't parent, if any. 67 do 68 Result:=cache.wrapper_or_void(xml_node_get_parent(handle)) 69 end 70 71 first: XML2_NODE 72 -- First child of Current node. Can be Void 73 do 74 Result:=cache.wrapper_or_void(xml_node_get_children(handle)) 75 end 76 77 next: XML2_NODE 78 -- Next "brother" node. Can be Void 79 do 80 Result:=cache.wrapper_or_void(xml_node_get_next(handle)) 81 end 82 83 prev: XML2_NODE 84 -- Previous "brother" node. Can be Void 85 do 86 Result:=cache.wrapper_or_void(xml_node_get_prev(handle)) 87 end 88 89 last: XML2_NODE 90 -- Last child node. Can be Void 91 do 92 Result:=cache.wrapper_or_void(xml_node_get_last(handle)) 93 end 94 95feature {} -- Implementation 96 free (p: POINTER) 97 do 98 xml_free (p) 99 end 100 101 struct_size: INTEGER 102 external "C use <libxml/tree.h>" 103 alias "size_of (xmlNode)" 104 end 105end -- class XML2_NODE