xml如何写入与保存listbox与listview的数据?
最好有代码

解决方案 »

  1.   

    这玩意要什么鸟代码,会操作xml,你先怎么保存就怎么保存,xmldocument,你把这个弄会了就行了
      

  2.   

    用nativexml吧,   具体的操作可以在 万一博客里找到 很简单
      

  3.   

    void CMyMSXML::SetNodeText(XMLNode node, LPCTSTR nodeText)
    {
    if (node == NULL)
    return;
     
    CComBSTR str = nodeText;
    node->put_text(str);
    str.Empty();
    }
     
    BOOL CMyMSXML::CreateNode(LPCTSTR path, LPCTSTR nodeText)
    {
    CString dupStr = path;
    while (1) {
    int nPre = dupStr.Find(_T('['));
    if (nPre == -1)
    break;
     
    int nPost = dupStr.Find(_T(']'), nPre);
    ASSERT (nPost != -1);
    if (nPost == -1)
    nPost = dupStr.GetLength()-1;
     
    for (int i = nPre; i <= nPost; i++)
    dupStr.SetAt(i, _T(' '));
    }
     
    CString elementName = path;
    CString treePath = path;
    if (dupStr.ReverseFind(_T('/')) != -1) {
    elementName = elementName.Right(dupStr.GetLength()-dupStr.ReverseFind(_T('/'))-1);
    treePath = treePath.Left(dupStr.ReverseFind(_T('/')));
    }
    else
    treePath = _T("");
     
    // make sure the full path is created already
    XMLNode node = NULL;
    if (treePath != _T("")){
    CComBSTR str = treePath;
    node = m_DomDoc->selectSingleNode(str.m_str);
    if (node == NULL){
    CreateNode(treePath);
    node = m_DomDoc->selectSingleNode(str.m_str);
    }
    str.Empty();
    }
     
    // Get Attributes
    vector<CString> attrName, attrValue;
    if (elementName.ReverseFind(_T('[')) != -1){
    CString strAttrs = elementName.Right(elementName.GetLength()-elementName.Find(_T('['))-1);
    elementName = elementName.Left(elementName.Find(_T('[')));
    strAttrs.Delete(strAttrs.ReverseFind(_T(']')), 1);
     
    int iStrAttrStart = strAttrs.Find(_T('@'));
    if (iStrAttrStart == -1)
    return ERROR_INVALID_ARG;
     
    while (TRUE){
    int iNextAttrStart = strAttrs.Find(_T('@'), iStrAttrStart+2);
    bool bFinish = (iNextAttrStart == -1);
     
    CString strOneAttr = strAttrs.Mid(iStrAttrStart, strAttrs.GetLength());
    if (!bFinish)
    strOneAttr = strAttrs.Mid(iStrAttrStart, iNextAttrStart-iStrAttrStart);
    CString strAttrName = strOneAttr.Mid(1, strOneAttr.Find(_T('='))-1);
    CString strAttrValue = strOneAttr.Mid(strOneAttr.Find(_T('"'))+1, strOneAttr.ReverseFind(_T('"'))-strOneAttr.Find(_T('"'))-1);
     
    attrName.push_back(strAttrName);
    attrValue.push_back(strAttrValue);
    if (bFinish)
    break;
     
    iStrAttrStart = iNextAttrStart;
    }
    }
     
    CComBSTR bstrName = elementName;
    XMLElement newElem = m_DomDoc->createElement(bstrName.m_str);
    bstrName.Empty();
     
    if (newElem == NULL)
    return FALSE;
     
    // set node value
    if (nodeText != NULL){
    CComBSTR str = nodeText;
    newElem->put_text(str);
    str.Empty();
    }
     
    node->appendChild(newElem);
    if (attrName.size() == 0)
    return TRUE;
     
    // create attributes
    MSXML::IXMLDOMNamedNodeMapPtr pAttrList = newElem->Getattributes();
    if (NULL == pAttrList)
    return FALSE;
     
    for (UINT i = 0; i < attrName.size(); i++){
    CComBSTR bstrAttrName = attrName.at(i);
    CComBSTR bstrAttrValue = attrValue.at(i);
    MSXML::IXMLDOMAttributePtr pNewAttr = m_DomDoc->createAttribute(bstrAttrName.m_str);
    pNewAttr->PutnodeValue((_variant_t)bstrAttrValue);
    pAttrList->setNamedItem(pNewAttr);
     
    bstrAttrName.Empty();
    bstrAttrValue.Empty();
    }
     
    return TRUE;
    }
      

  4.   

    自己定义的一个对XML操作的类,还有很多接口没有一一列出!~