#include#include using namespace xercesc; int main() { // parse XML document XMLCh* xmlFile = XMLString::transcode("example.xml"); XercesDOMParser parser; parser.parse(xmlFile); // get a NodeList of all elements DOMDocument* doc = parser.getDocument(); DOMNodeList* booklist = doc->getElementsByTagName(XMLString::transcode("book")); // iterate through the NodeList and output the title of each book for (XMLSize_t i = 0; i < booklist->getLength(); ++i) { DOMNode* book = booklist->item(i); DOMElement* titleElement = dynamic_cast (book->getFirstChild()); std::cout << "Book " << i+1 << " title: " << XMLString::transcode(titleElement->getTextContent()) << std::endl; } XMLString::release(&xmlFile); return 0; }
#includeThis example shows how to remove nodes from a DOMNodeList item. The code uses the getElementsByTagName method to get a NodeList of allusing namespace xercesc; int main() { // parse XML document XMLCh* xmlFile = XMLString::transcode("example.xml"); XercesDOMParser parser; parser.parse(xmlFile); // get a NodeList of all elements DOMDocument* doc = parser.getDocument(); DOMNodeList* booklist = doc->getElementsByTagName(XMLString::transcode("book")); // remove the first book element from the NodeList DOMNode* firstBook = booklist->item(0); DOMNode* removedBook = booklist->removeChild(firstBook); XMLString::release(&xmlFile); return 0; }