- XML* a = new XML("f.xml"); // load from file
- XML* a = new XML("<blah f="\\">",1); // load from memory from ASCIIZ string
- XML* a = new XML("<a href="http://www.some.com/files.xml">http://www.some.com/files.xml",2); // load from URL(Win32)
- ASSERT(a->IntegrityCheck() == true && a->ParseStatus() == 0);
- a->CompressMemory();
- //Get 3rd element's name, and its variable "v" value.
- //Also set new variable "tz" with normal and with 'on the fly' mode
- char y[100] = {0};
- a->GetRootElement()->GetChildren()[0]->GetElementName(y);
- // now y == "Cfg"
- a->GetRootElement()->GetChildren()[0]->FindVariableZ("v")->GetValue(y);
- // now y == "Cfg"
- // Create "tz" in the 'normal' mode
- XMLElement* e = a->GetRootElement()->GetChildren()[0];
- XMLVariable* v = new XMLVariable("tz","some value");
- e->AddVariable(v);
- // now do not delete v, it is owned by e
- // Create "tz" on the fly
- a->GetRootElement()->GetChildren()[0]->FindVariableZ( "tz",true)->
- SetValue("some value");
- // FindVariableZ(x,true) creates the var if doesn't exist!
- // Create Comments and Contents in the same way.
- // Use 0 instead of y to get the # of bytes required </blah>
- // <blah f="\\">for the returned string.
- // Let's save/export:
- if (a->IntegrityTest())
- {
- a->Save(); // Saves back to file
- a->Save("new.xml");
- a->Export(fp,1,0,0); // Save to a fp. You can also export to memory
- // or save only one element by calling XMLElement :: Export.
- delete a;
- // bye bye; </blah>
- // <blah f="\\">Note that the destructor doesn't save the file by default,
- //unless you call XML :: SaveOnClose(). }</blah>
- //该片段来自于http://www.codesnippet.cn/detail/130320132407.html
来源: http://www.codesnippet.cn/detail/130320132407.html