home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / AACD / Programming / sofa / archive / exml.lha / exml / main / tree_parser / xml_element.e < prev    next >
Text File  |  1999-04-13  |  3KB  |  147 lines

  1. indexing
  2.     description: "objects representing a element";
  3.     status:            "See notice at end of class.";
  4.     author:            "Andreas Leitner";
  5.  
  6. class
  7.     XML_ELEMENT
  8. inherit
  9.     XML_NAMED_NODE
  10.             -- `name' means name of the tag
  11.         rename
  12.             make as make_named_node
  13.         redefine
  14.             out
  15.         end
  16. creation
  17.     make, make_root
  18. feature
  19.     make (a_parent: XML_ELEMENT; tag_name: STRING) is
  20.             -- creates a XML_ELEMENT object with
  21.             -- `a_parent' as parent and `tag_name' as
  22.             -- tag name
  23.         require
  24.             valid_tag_name: tag_name /= Void
  25.         do
  26.             make_named_node (a_parent)
  27.             name := clone (tag_name)        
  28.             !! attributes.make
  29.         end
  30.  
  31.     make_root (tag_name: STRING) is
  32.             -- creates a XML_ELEMENT root object with
  33.             -- `tag_name' as tag name
  34.         require
  35.             valid_tag_name: tag_name /= Void
  36.         do
  37.             make (Void, tag_name)
  38.         end
  39.  
  40.  
  41.     attributes: XML_ATTRIBUTE_TABLE
  42.             -- table of attributes the element contains
  43.     
  44.     children_allowed: BOOLEAN is
  45.             -- this type of node allows children
  46.         do
  47.             Result := True
  48.         end
  49. feature
  50.     out: STRING is
  51.         do
  52.             !! Result.make (0)
  53.             Result.append (start_tag)
  54.             Result.append (Precursor)
  55.             Result.append (end_tag)
  56.         end
  57.  
  58.     start_tag: STRING is
  59.         do
  60.             !! Result.make (0)
  61.             Result.append ("<")
  62.             Result.append (name)
  63.  
  64.  
  65.  
  66.             Result.append (">")
  67.         end
  68.     end_tag: STRING is
  69.         do
  70.             !! Result.make (0)
  71.             Result.append ("</")
  72.             Result.append (name)
  73.             Result.append (">")
  74.         end
  75. feature
  76.  
  77.     join_text_nodes is
  78.             -- joins sequences of text nodes
  79.         local
  80.             text_node: XML_TEXT
  81.             joint_text_node: XML_TEXT
  82.             cs: DS_BILINKED_LIST_CURSOR [XML_NODE]
  83.         do
  84.             from
  85.                 cs := new_cursor
  86.                 cs.start
  87.             until
  88.                 cs.off
  89.             loop
  90.                 text_node ?= cs.item
  91.                 if
  92.                     text_node /= Void
  93.                 then
  94.                         -- found a text node
  95.                         -- now join all text-nodes that are
  96.                         -- more forward until there
  97.                         -- is a node that is no text-node
  98.                     joint_text_node := clone (text_node)
  99.                     remove_at (cs)
  100.                     from
  101.                     until
  102.                         cs.off or text_node = Void
  103.                     loop
  104.                         text_node ?= cs.item
  105.                         if
  106.                             text_node /= Void
  107.                         then
  108.                                 -- found another text-node -> join
  109.                             joint_text_node.append_content (text_node)
  110.                             remove_at (cs)
  111.                         else
  112.                             cs.forth
  113.                         end
  114.                     end
  115.                     force_left (joint_text_node, cs)
  116.                 else                
  117.                     cs.forth
  118.                 end
  119.             end
  120.         end
  121.  
  122.     set_attributes (v: XML_ATTRIBUTE_TABLE) is
  123.         require
  124.             v_not_void: v /= Void
  125.         do
  126.             attributes := v
  127.         ensure
  128.             attributes_equals_v: attributes = v
  129.         end
  130.  
  131.  
  132. end -- XML_ELEMENT
  133.  
  134. --|-------------------------------------------------------------------------
  135. --| eXML, Eiffel XML Parser Toolkit
  136. --| Copyright (C) 1999  Andreas Leitner
  137. --| See the file forum.txt included in this package for licensing info.
  138. --|
  139. --| Comments, Questions, Additions to this library? please contact:
  140. --|
  141. --| Andreas Leitner
  142. --| Arndtgasse 1/3/5
  143. --| 8010 Graz
  144. --| Austria
  145. --| email: andreas.leitner@teleweb.at
  146. --| web: http://exml.dhs.org
  147. --|-------------------------------------------------------------------------