blob: 619d62c93cfeaa787c455c8070fc68c6027d9b4c (
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
|
#include <uscxml/Common.h>
#include "NameSpacingParser.h"
#include <glog/logging.h>
#include <SAX/helpers/InputSourceResolver.hpp>
namespace uscxml {
NameSpacingParser NameSpacingParser::fromXML(const std::string& xml) {
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;
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";
}
}
}
return parser;
}
NameSpacingParser::NameSpacingParser() {
setErrorHandler(_errorHandler);
}
void NameSpacingParser::startPrefixMapping(const std::string& prefix, const std::string& uri) {
nameSpace.insert(std::make_pair(uri, prefix));
}
}
|