diff --git a/src/xml-cxx/xml.hxx b/src/xml-cxx/xml.hxx index 30c9f4b..32d5a71 100644 --- a/src/xml-cxx/xml.hxx +++ b/src/xml-cxx/xml.hxx @@ -458,6 +458,10 @@ namespace xml { public: Factory(const Node& t) throw(); const Node& operator*() const throw(); + friend std::ostream& operator<<(std::ostream& os, + const Factory& factory) throw(); + static std::ostream& print(std::ostream& os, const Node& node, + unsigned int level=0) throw(); std::auto_ptr read(std::istream& is) throw(wrong_end_tag, wrong_start_tag, tag_expected, type_mismatch, second_slash_in_tag, character_after_slash, diff --git a/src/xml.cxx b/src/xml.cxx index f38a72f..96c65d4 100644 --- a/src/xml.cxx +++ b/src/xml.cxx @@ -525,6 +525,63 @@ namespace xml { const Node& Factory::operator*() const throw() { return _template[0]; } + std::ostream& operator<<(std::ostream& os, const Factory& factory) throw() { + return factory.print(os, *factory); + } + std::ostream& Factory::print(std::ostream& os, const Node& node, + unsigned int level) throw() { + if (node.children()) { + os<first<<"=\""<second<<'"'; + os<<'>'; + if (dynamic_cast(&node)) + os<<" (Unsigned Integer"; + else if (dynamic_cast(&node)) + os<<" (String"; + else + os<<" (Node"; + if (node.min()==1 && node.max()==1) + os<<", required exactly once)"; + else if (node.min()==1 && node.max()==0) + os<<", required at least once)"; + else if (node.min()==0 && node.max()==0) + os<<", 0..n)"; + else if (node.min()==0 && node.max()==1) + os<<", optional)"; + else + os<<", "<'; + } else { + os<first<<"=\""<second<<'"'; + os<<"/>"; + if (dynamic_cast(&node)) + os<<" (Unsigned Integer"; + else if (dynamic_cast(&node)) + os<<" (String"; + else + os<<" (Node"; + if (node.min()==1 && node.max()==1) + os<<", required exactly once)"; + else if (node.min()==1 && node.max()==0) + os<<", required at least once)"; + else if (node.min()==0 && node.max()==0) + os<<", 0..n)"; + else if (node.min()==0 && node.max()==1) + os<<", optional)"; + else + os<<", "< Factory::read(std::istream& is) throw(wrong_end_tag, wrong_start_tag, tag_expected, type_mismatch, second_slash_in_tag,