// Assume xmlDoc is a loaded XML document DOMNode* root = xmlDoc->getDocumentElement(); DOMNodeList* children = root->getChildNodes(); for (XMLSize_t i = 0; i < children->getLength(); i++) { DOMNode* child = children->item(i); // do something with child node }
// Assume element is an XML element node DOMNamedNodeMap* attributes = element->getAttributes(); if (attributes->getLength() > 0) { DOMNode* attribute = attributes->item(0); const XMLCh* name = attribute->getNodeName(); const XMLCh* value = attribute->getNodeValue(); // do something with attribute name and value }
// Assume doc is an XML document DOMElement* newElement = doc->createElement(X("new_element")); DOMText* textNode = doc->createTextNode(X("some text")); newElement->appendChild(textNode);Overall, the cpp DOMNode class is a powerful tool for working with XML documents in C++. Its functionality is part of the Xerces-C++ library.