/src/wrappers/xml/library/xml2_node.e

http://github.com/tybor/Liberty · Specman e · 105 lines · 70 code · 18 blank · 17 comment · 3 complexity · 3f5ce95173435bdd0f165e047335376b MD5 · raw file

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