#include#include using namespace std; using namespace cppdom; int main(){ DocumentLoader docLoader; Document doc = docLoader.loadDocument("example.html"); Element rootNode = doc.getDocumentElement(); NodeList nodes = rootNode.getChildNodes(); for(unsigned int i=0; i
This example parses an HTML file called "example.html" and then iterates through the child nodes of its root element using a for loop. It then prints the name of each child node to the console.
Example 2:
The following code demonstrates how to use the getElementsByTagName() method of the DocumentLoader class to access all the elements of a particular tag name in the DOM.#include#include using namespace std; using namespace cppdom; int main(){ DocumentLoader docLoader; Document doc = docLoader.loadDocument("example.xml"); NodeList nodes = doc.getElementsByTagName("student"); for(unsigned int i=0; i This example parses an XML file called "example.xml" and then uses the getElementsByTagName() method to access all the "student" elements in the DOM. It then extracts the "name" and "age" attributes of each "student" element and prints them to the console. The DocumentLoader class is a part of the cppdom package library.