Page 1 of 1

XMLDocument

Posted: Wed Nov 27, 2019 2:48 pm
by AckiB
:windows: :linux:

The XMLDocument class (XMLDoc and irrXMLDoc libraries) I created to load and save XML files...
It is very powerful and easy to use...

Create and save a XML file:

Code: Select all

	xml::XMLDocument doc;

	xml::XMLNode* root = doc.getRootNode();

	//! set values
	root->setValue("show", true);
	root->setValue("value", 88);

	doc.save("defaults.dat");
Load and read a XML file:

Code: Select all

	xml::XMLDocument doc;
	doc.load("defaults.dat");
	
	xml::XMLNode* root = doc.getRootNode();

	//! load values
	bool vB = root->getValue_Boolean("show");
	int vI = 10; // default
	root->getValue("value", &vI);
Iterate XML child nodes:

Code: Select all

	xml::XMLNode* root = doc.getRootNode();
	
	// iterate all child nodes
	for(xml::XMLNode* node = root->FirstChildNode(); node; node = node->NextSiblingNode()){
		int v = node->getValue_Integer("Value");
	}

	// iterate specific child nodes
	for(xml::XMLNode* node = root->FirstChildNode("node_name"); node; node = node->NextSiblingNode("node_name")){
		int v = node->getValue_Integer("Value");
	}