void XMLNode::Copy(XMLNode **new_node) { XMLNode *newroot = new XMLNode(); newroot->name = name; newroot->depth = depth; // pridame rovnake polia list<XMLField*>::iterator itf; for (itf=fields.begin(); itf!=fields.end(); itf++) { XMLField *f = *itf; newroot->AddField(f->key, f->value); } // a este aj kopie nodov list<XMLNode*>::iterator itn; for (itn=nodes.begin(); itn!=nodes.end(); itn++) { XMLNode *n = *itn; XMLNode *newnode = NULL; // novu kopiu n->Copy(&newnode); newroot->AddNode(newnode); } }
int XMLFile::LoadFromXmlReader(IXmlReader *reader) { XmlNodeType type; int depth = 0; LPCWSTR text, value; HRESULT hr; list<XMLNode*> stack; stack.push_back(root); while (reader->Read(&type) == NOERROR) { switch (type) { case XmlNodeType_Element: { BOOL is_empty = reader->IsEmptyElement(); XMLNode *parent = stack.back(); XMLNode *current = new XMLNode(); stack.push_back(current); // add a new node parent->AddNode(current); hr = reader->GetLocalName(&text, NULL); if (FAILED(hr)) return hr; current->name = CString(text); // load attributes while (true) { hr = reader->MoveToNextAttribute(); if (hr != NOERROR) break; // read attribute name and value name hr = reader->GetLocalName(&text, NULL); if (FAILED(hr)) return hr; hr = reader->GetValue(&value, NULL); if (FAILED(hr)) return hr; CString attr_name(text); CString attr_value(value); current->AddField(attr_name, attr_value); } if (is_empty) { stack.pop_back(); } } break; case XmlNodeType_EndElement: { stack.pop_back(); } break; } } return 0; }