void Writer::writeContainer(const NodeContainer& container) { XML::NodeContainer::const_iterator it = container.beginChild(); XML::NodeContainer::const_iterator end = container.endChild(); for (; it != end; ++it) { if ((*it)->type() == ELEMENT_NODE) { XML::ElementNodePtr child = Core::dynamic_ptr_cast<XML::ElementNode>(*it); writeElement(child); } else if ((*it)->type() == TEXT_NODE) { XML::TextNodePtr child = Core::dynamic_ptr_cast<XML::TextNode>(*it); m_buffer += child->text(); } else { ASSERT_FALSE(); } } }
void XPathIterator::parse(QueryIterator begin, QueryIterator end, const NodePtr& context) { // Finished parsing? if (begin == end) { // Add to results, if valid node. if (context.get() != nullptr) m_results.push_back(context); return; } // Skip path separator. tstring::const_iterator it = begin; if (*it == TXT('/')) ++it; // Extract the node name. tstring::const_iterator nameFirst = it; while ( (it != end) && (*it != TXT('/')) ) ++it; tstring name(nameFirst, it); NodeType type = context->type(); NodeContainer* nodes = nullptr; // Has children? if (type == DOCUMENT_NODE) nodes = Core::static_ptr_cast<Document>(context).get(); else if (type == ELEMENT_NODE) nodes = Core::static_ptr_cast<ElementNode>(context).get(); // Find all children that match the name. for (NodeContainer::const_iterator nodeIter = nodes->beginChild(); nodeIter != nodes->endChild(); ++nodeIter) { const NodePtr& node = *nodeIter; // If a match, recurse... if ( (node->type() == ELEMENT_NODE) && (Core::static_ptr_cast<ElementNode>(node)->name() == name) ) { parse(it, end, *nodeIter); } } }