Commit 2bd4773c authored by Kjell Ahlstedt's avatar Kjell Ahlstedt

Parser: Add input operator>>()

* libxml++/parsers/parser.h: Add operator>>(std::istream& in, Parser& parser).
* examples/dom_parse_entities/main.cc: Use operator>>(). Bug #329281.
parent 0070e1bb
// -*- C++ -*-
/* main.cc /* main.cc
* *
* Copyright (C) 2002 The libxml++ development team * Copyright (C) 2002 The libxml++ development team
...@@ -26,6 +24,7 @@ ...@@ -26,6 +24,7 @@
#include "../testutilities.h" #include "../testutilities.h"
#include <libxml++/libxml++.h> #include <libxml++/libxml++.h>
#include <iostream> #include <iostream>
#include <fstream>
#include <cstdlib> #include <cstdlib>
void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int indentation = 0) void print_node(const xmlpp::Node* node, bool substitute_entities, unsigned int indentation = 0)
...@@ -93,7 +92,17 @@ int main(int argc, char* argv[]) ...@@ -93,7 +92,17 @@ int main(int argc, char* argv[])
xmlpp::DomParser parser; xmlpp::DomParser parser;
parser.set_validate(); parser.set_validate();
parser.set_substitute_entities(substitute_entities); parser.set_substitute_entities(substitute_entities);
parser.parse_file(filepath);
// Two ways of reading the XML file.
if (substitute_entities)
parser.parse_file(filepath);
else
{
std::ifstream instream(filepath.c_str());
if (!instream)
throw xmlpp::internal_error("Could not open file " + filepath);
instream >> parser;
}
if(parser) if(parser)
{ {
//Walk the tree: //Walk the tree:
...@@ -114,4 +123,3 @@ int main(int argc, char* argv[]) ...@@ -114,4 +123,3 @@ int main(int argc, char* argv[])
return return_code; return return_code;
} }
...@@ -199,6 +199,16 @@ protected: ...@@ -199,6 +199,16 @@ protected:
//int clear_options_; //int clear_options_;
}; };
/** Equivalent to Parser::parse_stream().
*
* @newin{2,38}
*/
inline std::istream& operator>>(std::istream& in, Parser& parser)
{
parser.parse_stream(in);
return in;
}
} // namespace xmlpp } // namespace xmlpp
#endif //__LIBXMLPP_PARSER_H #endif //__LIBXMLPP_PARSER_H
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment