xml如何写入与保存listbox与listview的数据?
最好有代码
最好有代码
解决方案 »
- 字符串操作时,函数insert(s1,s2,3)和关键字insert重复了?????急急急
- 急寻下拉框选择图片的Combox控件,有人知道吗?
- 高分请教打印问题,如何打印panel里的所有内容?
- 接到个私活,大家看看应该价值多少?
- 关于进度条ProgressBar的使用
- 我用RICHEDIT编辑的文件,存成TXT格式,我用记事本打开以后发现是乱码,要如何解决?
- 实现统计表
- 请问如何在查询数据后,返回查询结果的数量?
- 请教DER(basic encoding rules)Delphi下实现问题。
- 和大家讨论万能报表该怎么做
- delphi videocapx
- delphi 这个#$C2#$18#$00计算出来整数是多少
{
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;
}