30#include "NCMLParser.h"
31#include "OtherXMLParser.h"
32#include "XMLHelpers.h"
36OtherXMLParser::OtherXMLParser(NCMLParser& p) :
37 _rParser(p), _depth(0), _otherXML(
"")
41OtherXMLParser::~OtherXMLParser()
46int OtherXMLParser::getParseDepth()
const
52OtherXMLParser::getString()
const
57void OtherXMLParser::reset()
63void OtherXMLParser::onStartDocument()
65 THROW_NCML_INTERNAL_ERROR(
"OtherXMLParser::onStartDocument called! This is a logic bug.");
68void OtherXMLParser::onEndDocument()
70 THROW_NCML_INTERNAL_ERROR(
"OtherXMLParser::onEndDocument called! This is a logic bug.");
73void OtherXMLParser::onStartElement(
const std::string& name,
const XMLAttributeMap& attrs)
75 appendOpenStartElementTag(name,
"");
76 appendAttributes(attrs);
78 appendCloseStartElementTag();
83void OtherXMLParser::onEndElement(
const std::string& name)
85 appendEndElementTag(name);
89void OtherXMLParser::onStartElementWithNamespace(
const std::string& localname,
const std::string& prefix,
92 appendOpenStartElementTag(localname, prefix);
93 appendAttributes(attributes);
99 "Got depth 0 OtherXML element while parsing OtherXML attribute..." <<
" Pulling all un-shadowed ancestral namespaces into the element with localname=" << localname << std::endl);
105 _rParser.getXMLNamespaceStack().getFlattenedNamespacesUsingLexicalScoping(ancestralNamespaces);
106 appendNamespaces(ancestralNamespaces);
110 appendNamespaces(namespaces);
113 appendCloseStartElementTag();
118void OtherXMLParser::onEndElementWithNamespace(
const std::string& localname,
const std::string& prefix,
121 appendEndElementTag(XMLAttribute::getQName(prefix, localname));
125void OtherXMLParser::onCharacters(
const std::string& content)
128 _otherXML.append(content);
131void OtherXMLParser::onParseWarning(std::string msg)
133 THROW_NCML_PARSE_ERROR(-1,
134 "OtherXMLParser: got SAX parse warning while parsing OtherXML. Msg was: " + msg);
137void OtherXMLParser::onParseError(std::string msg)
139 THROW_NCML_PARSE_ERROR(-1,
"OtherXMLParser: got SAX parse error while parsing OtherXML. Msg was: " + msg);
142void OtherXMLParser::appendOpenStartElementTag(
const std::string& localname,
const std::string& prefix)
145 _otherXML += string(
"<");
146 _otherXML += XMLAttribute::getQName(prefix, localname);
149void OtherXMLParser::appendAttributes(
const XMLAttributeMap& attributes)
151 for (XMLAttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); ++it) {
152 _otherXML += (string(
" ") + it->getQName() +
"=\"" + it->value +
"\"");
156void OtherXMLParser::appendNamespaces(
const XMLNamespaceMap& namespaces)
158 _otherXML += namespaces.getAllNamespacesAsAttributeString();
161void OtherXMLParser::appendCloseStartElementTag()
166void OtherXMLParser::appendEndElementTag(
const string& qname)
168 _otherXML += (string(
"</") + qname +
">");
171void OtherXMLParser::pushDepth()
176void OtherXMLParser::popDepth()
183 THROW_NCML_INTERNAL_ERROR(
"OtherXMLElement::onEndElement: _depth < 0! Logic error in parsing OtherXML.");
NcML Parser for adding/modifying/removing metadata (attributes) to existing local datasets using NcML...