From cd608545a795e2e939e2c7c485b0aeae9b6576a3 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Thu, 29 Aug 2013 16:40:35 +0100 Subject: File -> Document and allow use of streams. --- src/cxml.cc | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'src/cxml.cc') 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; -} -- cgit v1.2.3