Ejemplo n.º 1
0
void CopyXMLNode(csRef<iDocumentNode> source, csRef<iDocumentNode> target, int mode)
{
    if (mode == 0)
    {
        target->RemoveNodes();
        target->RemoveAttributes();
    }
    
    // copy nodes
    csRef<iDocumentNodeIterator> nodeIter = source->GetNodes();
    while (nodeIter->HasNext())
    {
        csRef<iDocumentNode> child = nodeIter->Next();
        csRef<iDocumentNode> targetChild = target->GetNode(child->GetValue());
        if (targetChild==NULL || mode==3)  // Mode 3 means don't merge tags but just insert multiples, so we create a new one here every time
        {
            targetChild = target->CreateNodeBefore(child->GetType());
            if (targetChild == NULL)
                assert(!"failed to create XML node, you are probably using wrong XML parser (xmlread instead of xmltiny)");
            targetChild->SetValue(child->GetValue());
        }
        CopyXMLNode(child, targetChild, mode);
    }
    
    // copy attributes
    csRef <iDocumentAttributeIterator> attrIter = source->GetAttributes();
    while (attrIter->HasNext())
    {
        csRef<iDocumentAttribute> attr = attrIter->Next();
        const char* attrName = attr->GetName();
        if (mode==1  ||  !target->GetAttribute(attrName))
            target->SetAttribute(attrName, attr->GetValue());
    }
}