22 #ifndef _XercesDomReadingContext_hxx_
23 #define _XercesDomReadingContext_hxx_
27 #include <xercesc/dom/DOMElement.hpp>
28 #include <xercesc/dom/DOMNamedNodeMap.hpp>
29 #include <xercesc/dom/DOMNodeList.hpp>
36 class XercesDomDocumentHandler;
44 xercesc::DOMElement * _context;
45 xercesc::DOMNodeList * _children;
46 xercesc::DOMNamedNodeMap * _attributes;
47 std::stringstream _plainContentToParse;
48 unsigned int _currentChild;
50 std::list<std::string> _errors;
64 _parentContext=oldContext;
67 void setAt(xercesc::DOMElement * element)
70 _children = _context->getChildNodes();
71 _attributes = _context->getAttributes();
87 if (_currentChild==_children->getLength())
return false;
89 xercesc::DOMNode * child = _children->item(_currentChild);
90 CLAM_ASSERT(child->getNodeType() == xercesc::DOMNode::ELEMENT_NODE,
91 "Can't change the context to a non element node");
92 if (!xercesc::XMLString::equals(child->getNodeName(),
U(name)))
return false;
107 CLAM_ASSERT(!hasContentLeft,
"Fetching element with content left");
109 "Accessing beyond DOM nodes");
110 xercesc::DOMNode * child = _children->item(_currentChild);
111 CLAM_ASSERT(child->getNodeType() == xercesc::DOMNode::ELEMENT_NODE,
112 "Can't change the context to a non element node");
113 CLAM_ASSERT(xercesc::XMLString::equals(child->getNodeName(),
U(name)),
114 "XML element name should be the one expected");
117 return dynamic_cast<xercesc::DOMElement *
>(child);
124 return _parentContext;
130 std::ostringstream os;
131 os <<
"Unexpected content: '";
132 for (
int c=_plainContentToParse.get(); not _plainContentToParse.eof(); c=_plainContentToParse.get())
134 os <<
"' at position ";
136 _errors.push_back(os.str());
141 if (_currentChild>=_children->getLength())
return;
142 xercesc::DOMNode * child = _children->item(_currentChild);
150 std::ostringstream os;
151 os <<
"Unexpected Element: '";
152 os <<
L(child->getNodeName());
153 os <<
"' at position ";
156 _errors.push_back(os.str());
161 xercesc::DOMNode * attribute =
162 _attributes->getNamedItem(
U(attributeName));
163 if (!attribute)
return false;
164 os <<
L(attribute->getNodeValue()) << std::flush;
170 return _plainContentToParse;
181 for (; _currentChild<_children->getLength(); _currentChild++)
183 xercesc::DOMNode * child= _children->item(_currentChild);
184 if (child->getNodeType() == xercesc::DOMNode::COMMENT_NODE)
continue;
185 if (child->getNodeType() != xercesc::DOMNode::TEXT_NODE)
break;
186 _plainContentToParse <<
L(child->getNodeValue());
188 _plainContentToParse << std::flush;
198 int c = _plainContentToParse.peek();
199 while (not _plainContentToParse.eof())
201 if (!isspace(c))
return true;
202 _plainContentToParse.ignore();
203 c = _plainContentToParse.peek();
205 _plainContentToParse.clear();
216 if (_parentContext) path=_parentContext->
getPath();
218 path +=
L(_context->getNodeName());
226 #endif//_XercesDomReadingContext_hxx_