29 #include "NCMLDebug.h"
30 #include "NCMLParser.h"
31 #include "OtherXMLParser.h"
32 #include "XMLHelpers.h"
36 OtherXMLParser::OtherXMLParser(NCMLParser& p) :
37 _rParser(p), _depth(0), _otherXML(
"")
41 OtherXMLParser::~OtherXMLParser()
46 int OtherXMLParser::getParseDepth()
const
52 OtherXMLParser::getString()
const
57 void OtherXMLParser::reset()
63 void OtherXMLParser::onStartDocument()
65 THROW_NCML_INTERNAL_ERROR(
"OtherXMLParser::onStartDocument called! This is a logic bug.");
68 void OtherXMLParser::onEndDocument()
70 THROW_NCML_INTERNAL_ERROR(
"OtherXMLParser::onEndDocument called! This is a logic bug.");
73 void OtherXMLParser::onStartElement(
const std::string& name,
const XMLAttributeMap& attrs)
75 appendOpenStartElementTag(name,
"");
76 appendAttributes(attrs);
78 appendCloseStartElementTag();
83 void OtherXMLParser::onEndElement(
const std::string& name)
85 appendEndElementTag(name);
89 void 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();
118 void OtherXMLParser::onEndElementWithNamespace(
const std::string& localname,
const std::string& prefix,
121 appendEndElementTag(XMLAttribute::getQName(prefix, localname));
125 void OtherXMLParser::onCharacters(
const std::string& content)
128 _otherXML.append(content);
131 void OtherXMLParser::onParseWarning(std::string msg)
133 THROW_NCML_PARSE_ERROR(-1,
134 "OtherXMLParser: got SAX parse warning while parsing OtherXML. Msg was: " + msg);
137 void OtherXMLParser::onParseError(std::string msg)
139 THROW_NCML_PARSE_ERROR(-1,
"OtherXMLParser: got SAX parse error while parsing OtherXML. Msg was: " + msg);
142 void OtherXMLParser::appendOpenStartElementTag(
const std::string& localname,
const std::string& prefix)
145 _otherXML += string(
"<");
146 _otherXML += XMLAttribute::getQName(prefix, localname);
149 void OtherXMLParser::appendAttributes(
const XMLAttributeMap& attributes)
151 for (XMLAttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); ++it) {
152 _otherXML += (string(
" ") + it->getQName() +
"=\"" + it->value +
"\"");
156 void OtherXMLParser::appendNamespaces(
const XMLNamespaceMap& namespaces)
158 _otherXML += namespaces.getAllNamespacesAsAttributeString();
161 void OtherXMLParser::appendCloseStartElementTag()
166 void OtherXMLParser::appendEndElementTag(
const string& qname)
168 _otherXML += (string(
"</") + qname +
">");
171 void OtherXMLParser::pushDepth()
176 void OtherXMLParser::popDepth()
183 THROW_NCML_INTERNAL_ERROR(
"OtherXMLElement::onEndElement: _depth < 0! Logic error in parsing OtherXML.");