/tutorial/xml/dom/example2.e

http://github.com/tybor/Liberty · Specman e · 40 lines · 29 code · 5 blank · 6 comment · 3 complexity · cac24958c6438107ed56e04198cad15f MD5 · raw file

  1. class EXAMPLE2
  2. --
  3. -- This example is a bit more complex since it uses a subclass of XML_TREE to provide some validation.
  4. --
  5. inherit
  6. EXAMPLE1
  7. redefine make
  8. end
  9. create {}
  10. make
  11. feature {}
  12. make
  13. local
  14. in: TEXT_FILE_READ; tree: MY_VALIDATING_TREE; version: UNICODE_STRING
  15. do
  16. if argument_count = 0 then
  17. std_error.put_line(once "Usage: #(1) <file.xml>" # command_name)
  18. die_with_code(1)
  19. end
  20. -- first create the stream
  21. create in.connect_to(argument(1))
  22. if in.is_connected then
  23. -- then create the tree
  24. create tree.with_error_handler(in.url, agent error(?, ?))
  25. -- now display the results
  26. version := tree.attribute_at(once U"version")
  27. if version /= Void then
  28. io.put_string(once "XML version: ")
  29. io.put_string(version.as_utf8)
  30. io.put_new_line
  31. end
  32. tree.root.accept(Current)
  33. end
  34. end
  35. end -- class EXAMPLE2