vc读写XML文件的源码
2005/6/28 13:15:33
阅读全文(8480) | 回复(0) | 编辑 | 精华
CString CCardSet::GetCardSetXml(){ MSXML::IXMLDOMDocumentPtr m_plDomDocument; MSXML::IXMLDOMElementPtr m_pDocRoot; MSXML::IXMLDOMNodePtr pNode; MSXML::IXMLDOMAttributePtr pAttribute; MSXML::IXMLDOMElementPtr pElement; MSXML::IXMLDOMNamedNodeMapPtr pNewAttrList; MSXML::IXMLDOMElement *element; MSXML::IXMLDOMNode *pRootNode; MSXML::IXMLDOMElementPtr root; MSXML::IXMLDOMAttributePtr pAttr; CString CardSetXml; CString strSetType; CString strSuit, strValue,strNumber; // CString temXml =_T("<CardSet SetType=\"0\">\ <CardList>\ </CardList>\ </CardSet>"); CString temXml =_T(""); m_plDomDocument->loadXML(_bstr_t(LPCSTR(temXml))); pRootNode = m_plDomDocument->GetfirstChild(); pNode = m_plDomDocument->createNode(_variant_t((short)MSXML::NODE_ELEMENT) , _bstr_t("CardSet"), ""); pNewAttrList = pNode->Getattributes(); ASSERT(NULL != pNewAttrList); strSetType.Format("%d", (int)m_SetType); pAttribute = m_plDomDocument->createAttribute(_bstr_t("SetType")); pAttribute->put_nodeValue((_variant_t)(LPCTSTR)_T(strSetType)); pNewAttrList->setNamedItem(pAttribute); // root = m_plDomDocument->documentElement; m_plDomDocument->appendChild(pNode); // AfxMessageBox(m_plDomDocument->xml); pNode = m_plDomDocument->createNode(_variant_t((short)MSXML::NODE_ELEMENT) , _bstr_t("CardList"), ""); root = m_plDomDocument->firstChild; root->appendChild(pNode); // AfxMessageBox(m_plDomDocument->xml); POSITION cardpos = m_CardList.GetHeadPosition(); while (cardpos != NULL) { CCard* tmpCard = (CCard*)m_CardList.GetNext(cardpos); strSuit.Format("%d", tmpCard->GetSuit()); strValue.Format("%d", tmpCard->GetCardinal()); strNumber.Format("%d", tmpCard->m_Number); pNode = m_plDomDocument->createNode(_variant_t((short)MSXML::NODE_ELEMENT) , _bstr_t("Card"), ""); pNewAttrList = pNode->Getattributes(); ASSERT(NULL != pNewAttrList); pAttribute = m_plDomDocument->createAttribute(_bstr_t("Suit")); pAttribute->put_nodeValue((_variant_t)(LPCTSTR)_T(strSuit)); pNewAttrList->setNamedItem(pAttribute); pAttribute = m_plDomDocument->createAttribute(_bstr_t("Value")); pAttribute->put_nodeValue((_variant_t)(LPCTSTR)_T(strValue)); pNewAttrList->setNamedItem(pAttribute); pAttribute = m_plDomDocument->createAttribute(_bstr_t("Number")); pAttribute->put_nodeValue((_variant_t)(LPCTSTR)_T(strNumber)); pNewAttrList->setNamedItem(pAttribute); root = m_plDomDocument->documentElement->firstChild; root->appendChild(pNode); }// AfxMessageBox(m_plDomDocument->xml); CardSetXml.Format("%s", LPCSTR(m_plDomDocument->xml)); return CardSetXml;} 出处 www.goodindeed.com
Posted by Qr on 2005/6/28 13:15:33
发表评论: |