Example #1
0
	void XmlTree (std::ostream & out)
	{
		XML::Tree tree;
		XML::Node * root = tree.SetRoot ("UnitTest");
		std::auto_ptr<XML::Node> child1 (new XML::Node ("child"));
		child1->AddAttribute ("num", "1");
		child1->AddTransformAttribute ("level", "1");
		child1->AddTransformAttribute ("upperExamples", 
				"some upper chars: А, ▓, ├ or нт and finally Ш.");
		child1->AddTransformText ("This text contains all 5 special characters:\n"
			"ampersand: &, quotation mark: \", apostrophe: ', less than: < "
			"and greater than char: >.");
		root->AddChild (child1);

		root->AddText ("This is my next child");

		XML::Node * node = root->AddChild ("child");
		node->AddAttribute ("num", 2);
		node->AddAttribute ("level", 1);
		XML::Node * grandChild = node->AddEmptyChild ("Grandchild");
		grandChild->AddAttribute ("age", 2);
		tree.Write (out);

		XML::Node const * firstChild = *tree.GetRoot ()->FirstChild ();
		out << "\n\nTransform back upper-ascii characters: " 
			<< firstChild->GetTransformAttribValue ("upperExamples") << std::endl;
		out << "\nTransform back the text: " 
			<< (*firstChild->FirstChild ())->GetTransformAttribValue ("Text") << std::endl;
	}