blob: 21d97048dd60674ebac12005af13f76274f102d3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
#include "NameSpacingParser.h"
#include <glog/logging.h>
namespace uscxml {
NameSpacingParser* NameSpacingParser::fromXML(const std::string& xml) {
if (xml.length() == 0)
return NULL;
std::stringstream* ss = new std::stringstream();
(*ss) << xml;
// we need an auto_ptr for arabica to assume ownership
std::auto_ptr<std::istream> ssPtr(ss);
Arabica::SAX::InputSource<std::string> inputSource;
inputSource.setByteStream(ssPtr);
return fromInputSource(inputSource);
}
NameSpacingParser* NameSpacingParser::fromInputSource(Arabica::SAX::InputSource<std::string>& source) {
NameSpacingParser* parser = new NameSpacingParser();
if(!parser->parse(source) || !parser->getDocument().hasChildNodes()) {
if(parser->_errorHandler.errorsReported()) {
LOG(ERROR) << "could not parse input:";
LOG(ERROR) << parser->_errorHandler.errors() << std::endl;
} else {
Arabica::SAX::InputSourceResolver resolver(source, Arabica::default_string_adaptor<std::string>());
if (!resolver.resolve()) {
LOG(ERROR) << source.getSystemId() << ": no such file";
}
}
delete parser;
}
return parser;
}
NameSpacingParser::NameSpacingParser() {
Arabica::SAX::CatchErrorHandler<std::string> errorHandler;
setErrorHandler(errorHandler);
}
void NameSpacingParser::startPrefixMapping(const std::string& prefix, const std::string& uri) {
nameSpace.insert(std::make_pair(uri, prefix));
}
}
|