driver.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2005 Carl Barron. Distributed under the Boost
  2. // Software License, Version 1.0. (See accompanying file
  3. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #include "xml_g.hpp"
  5. #include <boost/spirit/include/classic_utility.hpp>
  6. #include <iostream>
  7. namespace std
  8. {
  9. std::ostream & operator << (std::ostream &os,std::pair<std::string,std::string> const &p)
  10. {
  11. return os << p.first << '=' << p.second;
  12. }
  13. std::ostream & operator << (std::ostream &os,const tag &t)
  14. {
  15. return os << t.id;
  16. }
  17. }
  18. int main()
  19. {
  20. const char *test =
  21. // "<A x=\"1\" y=\"2\"> test 1 </A>"
  22. // "<B x=\"3\" y= \"4\" z = \"10\"> test 3 </B>"
  23. // "<C><A></A><V><W></W></V></C>"
  24. // "<D x=\"4\"/>"
  25. "<E>xxx<F>yyy</F>zzz</E>"
  26. ;
  27. std::list<tag> tags;
  28. xml_g g(tags);
  29. if(SP::parse(test,g,SP::comment_p("<---","--->")).full)
  30. {
  31. std::for_each(tags.begin(),tags.end(),walk_data());
  32. }
  33. else
  34. {
  35. std::cout << "parse failed\n";
  36. }
  37. }