22 #ifndef _LibXmlDomReadingContext_hxx_
23 #define _LibXmlDomReadingContext_hxx_
27 #include <libxml++/libxml++.h>
34 class LibXmlDomDocumentHandler;
43 xmlpp::Element * _context;
44 xmlpp::Node::NodeList _children;
45 xmlpp::Node::NodeList::iterator _currentChild;
46 xmlpp::Element::AttributeList _attributes;
47 std::stringstream _plainContentToParse;
48 std::list<std::string> _errors;
62 _parentContext=oldContext;
65 void setAt(xmlpp::Element * element)
68 _children = _context->get_children();
69 _attributes = _context->get_attributes();
70 _currentChild=_children.begin();
84 if (_currentChild==_children.end())
return false;
85 xmlpp::Element * child =
dynamic_cast<xmlpp::Element*
>(*_currentChild);
87 "Can't change the context to a non element node");
88 if (child->get_name()!=
U(name))
return false;
101 CLAM_ASSERT(!hasContentLeft,
"Fetching element with content left");
103 "Accessing beyond DOM nodes");
104 xmlpp::Element * child =
dynamic_cast<xmlpp::Element *
>(*_currentChild);
106 "Can't change the context to a non element node");
108 "XML element name should be the one expected");
118 return _parentContext;
124 std::ostringstream os;
125 os <<
"Unexpected content: '";
126 for (
int c=_plainContentToParse.get(); not _plainContentToParse.eof(); c=_plainContentToParse.get())
128 os <<
"' at position ";
130 _errors.push_back(os.str());
134 if (_currentChild==_children.end())
return;
135 xmlpp::Element * child =
dynamic_cast<xmlpp::Element*
>(*_currentChild);
141 std::ostringstream os;
142 os <<
"Unexpected Element: '";
143 os <<
L(child->get_name());
144 os <<
"' at position ";
147 _errors.push_back(os.str());
152 xmlpp::Attribute * attribute =
153 _context->get_attribute(
U(attributeName));
154 if (!attribute)
return false;
155 os <<
L(attribute->get_value()) << std::flush;
161 return _plainContentToParse;
171 for (; _currentChild!=_children.end(); _currentChild++)
173 xmlpp::Node * child= *_currentChild;
174 if (dynamic_cast<xmlpp::CommentNode*>(child))
continue;
175 xmlpp::TextNode * textNode =
dynamic_cast<xmlpp::TextNode*
>(child);
176 if (!textNode)
break;
177 _plainContentToParse <<
L(textNode->get_content());
179 _plainContentToParse << std::flush;
189 int c = _plainContentToParse.peek();
190 while (not _plainContentToParse.eof())
192 if (!isspace(c))
return true;
193 _plainContentToParse.ignore();
194 c = _plainContentToParse.peek();
196 _plainContentToParse.clear();
206 return L(_context->get_path());
209 if (_parentContext) path=_parentContext->
getPath();
211 path +=
L(_context->get_name());
218 #endif//_LibXmlDomReadingContext_hxx_