diff options
| author | Carl Hetherington <cth@carlh.net> | 2013-08-29 16:40:35 +0100 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2013-08-29 16:40:35 +0100 |
| commit | cd608545a795e2e939e2c7c485b0aeae9b6576a3 (patch) | |
| tree | 1e8450d4c9d8713a29c8b2575982c83e32fa4d45 /src/cxml.cc | |
| parent | 5c4e872c3a155c4af75d8ff963c16da28037ffe8 (diff) | |
File -> Document and allow use of streams.
Diffstat (limited to 'src/cxml.cc')
| -rw-r--r-- | src/cxml.cc | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/cxml.cc b/src/cxml.cc index 20d06ee..2fa6de3 100644 --- a/src/cxml.cc +++ b/src/cxml.cc @@ -196,25 +196,45 @@ cxml::Node::content () const return content; } -cxml::File::File (string file, string root_name) +cxml::Document::Document (string root_name) + : _root_name (root_name) +{ + _parser = new xmlpp::DomParser; +} + +cxml::Document::~Document () +{ + delete _parser; +} + +void +cxml::Document::read_file (filesystem::path file) { if (!filesystem::exists (file)) { throw cxml::Error ("XML file does not exist"); } - _parser = new xmlpp::DomParser; - _parser->parse_file (file); + _parser->parse_file (file.string ()); + take_root_node (); +} + +void +cxml::Document::read_stream (istream& stream) +{ + _parser->parse_stream (stream); + take_root_node (); +} + +void +cxml::Document::take_root_node () +{ if (!_parser) { throw cxml::Error ("could not parse XML"); } _node = _parser->get_document()->get_root_node (); - if (_node->get_name() != root_name) { + if (_node->get_name() != _root_name) { throw cxml::Error ("unrecognised root node"); } } -cxml::File::~File () -{ - delete _parser; -} |
