📄 xml.cpp
字号:
{ QDomNode child_second = child_first.GetChildNode(nSecond); if (! child_second.IsValidNode()) { return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE); } int nMatchCount = 0; for (int nAttri=0; nAttri<child_second.GetAttributeCount(); nAttri++) { IEXMLAttribute attri = child_second.GetAttribute(nAttri); if (! attri.IsValidAttribute()) { return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE); } string strName = attri.GetName(); string strValue= attri.GetValue(); for (unsigned int uVector = 0 ; uVector<aryAttri.size(); uVector++) { ATTRI_PART& attri_part = aryAttri[uVector]; if ( 0 == strcmp_lower(attri_part.strName, strName) && 0 == strcmp_lower(attri_part.strValue, strValue)) { nMatchCount++; break; } } } if (nMatchCount == (int)aryAttri.size()) return child_second; } } } return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE);}QDomNode CXMLReader::GetDomNodex(const QString& qstrParentName, const char* pszChildName, ...){ //= 兼容定义 const char* pszParentName = qstrParentName.data(); //= vector<ATTRI_PART> aryAttri; va_list args; va_start(args, pszChildName); string strChildName = pszChildName; char* pszAttriValue = NULL; char* pszAttriName = va_arg(args,char*); if (pszAttriName != NULL) pszAttriValue = va_arg(args,char*); while (pszAttriName &&pszAttriValue) { struct ATTRI_PART attri; attri.strName = pszAttriName; attri.strValue= pszAttriValue; aryAttri.push_back(attri); pszAttriName = va_arg(args,char*); pszAttriValue = va_arg(args,char*); } va_end(args); //查找接点 QDomNode root = m_DocXML.GetRootNode(); if (! root.IsValidNode()) { return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE); } //cout << "根节点的子接点数目:" << root.GetChildCount() <<endl; for (int nFirst=0; nFirst<root.GetChildCount(); nFirst++) { QDomNode child_first = root.GetChildNode(nFirst); if (! child_first.IsValidNode()) { return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE); } // 匹配父节点名称 string strName = child_first.GetName(); if (0 != strcmp_lower(pszParentName, strName)) continue; //cout << "子节点)"<<child_first.GetName()<<") 的子接点数目:" << child_first.GetChildCount() <<endl; for (int nSecond=0; nSecond<child_first.GetChildCount(); nSecond++) { QDomNode child_second = child_first.GetChildNode(nSecond); if (! child_second.IsValidNode()) { // cout << "--------------first-------------------"<<endl; return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE); } // 匹配子节点名称 string strName = child_second.GetName(); //cout <<"===============================" <<endl; //cout << "子节点名称:" << strName.c_str() <<endl; //cout <<"===============================" <<endl; int n = strcmp_lower(pszChildName, strName);n=n;// printf("n==%d\n", n);// cout <<"比较大小:" << strcmp_lower(pszChildName, strName) <<endl; if (0 != strcmp_lower(pszChildName, strName)) { // cout << "--------------second-------------------"<<endl; continue; } //cout << "--------------third-------------------"<<endl; // 匹配属性名称及属性值 int nMatchCount = 0; //cout << "属性数目:" << child_second.GetAttributeCount() <<endl; for (int nAttri=0; nAttri<child_second.GetAttributeCount(); nAttri++) { IEXMLAttribute attri = child_second.GetAttribute(nAttri); //cout << "属性名称:" << attri.GetName() << "\t属性值:" <<attri.GetValue()<< endl; if (! attri.IsValidAttribute()) { return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE); } string strName = attri.GetName(); string strValue= attri.GetValue(); //cout << "属性名称:" << strName << "\t属性值:" <<strValue<< endl; for (unsigned int uVector=0; uVector<aryAttri.size(); uVector++) { ATTRI_PART& attri_part = aryAttri[uVector]; if ( 0 == strcmp_lower(attri_part.strName, strName) && 0 == strcmp_lower(attri_part.strValue, strValue)) { nMatchCount++; break; } } } if (nMatchCount == (int)aryAttri.size()) return child_second; } } return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE);}QDomNode CXMLReader::GetChildNode(QDomNode& node, const char* pszChildName, ...){ vector<ATTRI_PART> aryAttri; va_list args; va_start(args, pszChildName); string strChildName = pszChildName; char* pszAttriName = va_arg(args,char*); char* pszAttriValue = va_arg(args,char*); while (pszAttriName &&pszAttriValue) { struct ATTRI_PART attri; attri.strName = pszAttriName; attri.strValue= pszAttriValue; aryAttri.push_back(attri); pszAttriName = va_arg(args,char*); pszAttriValue = va_arg(args,char*); } va_end(args); //查找接点 if (! node.IsValidNode()) { cout<<"QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE)----------1\n"; return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE); }// cout << "子节点数目为:"<< node.GetChildCount() <<endl; for (int nChild=0; nChild<node.GetChildCount(); nChild++) { QDomNode child = node.GetChildNode(nChild); if (! child.IsValidNode()) { cout<<"QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE)----------2\n"; return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE); } // 匹配父节点名称 string strName = child.GetName();// cout<<strChildName<<"\tcompare\t"<<strName<<endl; if (0 != strcmp_lower(strName, strChildName)) {// cout << "两者不等=================\n"; continue; } //HYK added if(0==aryAttri.size()) return child; // 匹配属性名称及属性值 int nMatchCount = 0;// cout<<"属性数目为:attr count="<<child.GetAttributeCount()<<endl; for (int nAttri=0; nAttri<child.GetAttributeCount(); nAttri++) { IEXMLAttribute attri = child.GetAttribute(nAttri); if (! attri.IsValidAttribute()) { return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE); } string strName = attri.GetName(); string strValue= attri.GetValue(); for (unsigned int uVector=0; uVector<aryAttri.size(); uVector++) { ATTRI_PART& attri_part = aryAttri[uVector]; if ( 0 == strcmp_lower(attri_part.strName, strName) && 0 == strcmp_lower(attri_part.strValue, strValue)) { nMatchCount++; break; } } } //HYK modified if (nMatchCount == (int)aryAttri.size()) return child; }// cout<<"QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE)----------3\n"; return QDomNode((EXML_HANDLE)EXML_INVALID_HANDLE);}//==================================================================================================////= End: 兼容老版本接口:与老版本程序接口名称及参数保持一致//==================================================================================================//bool CXMLReader::GetAttributeValue(QDomNode& node, const char* pszAttriName, QString& qstrAttriValue){ if (! node.IsValidNode()) { return false; } for (int nAttri=0; nAttri<node.GetAttributeCount(); nAttri++) { IEXMLAttribute attri = node.GetAttribute(nAttri); string strName = attri.GetName(); if (0 == strcmp_lower(pszAttriName, strName)) { qstrAttriValue = attri.GetValue(); return true; } } return false;}bool CXMLReader::GetAttributeValue(QDomNode& node, const char* pszAttriName, int& nAttrValue){ QString strAttriValue; if ( GetAttributeValue(node, pszAttriName, strAttriValue) ) { nAttrValue = strAttriValue.toInt(); return true; } return false;}int CXMLReader::GetChildNodeCount(QDomNode& node){ if (! node.IsValidNode()) return 0; return node.GetChildCount();}QDomNode CXMLReader::InsertNode(const char* pszParentName, const char* pszChildName){ QDomNode root = m_DocXML.GetRootNode(); if (! root.IsValidNode()) return false; m_Mutex.lock(); for (int nNode=0; nNode<root.GetChildCount(); nNode++) { QDomNode child = root.GetChildNode(nNode); if (child.IsValidNode()) { string strName = child.GetName(); if (0 == strcmp_lower(pszParentName, strName)) { QDomNode node(pszChildName, ""); child.AddChild(&node); m_Mutex.unlock(); return true; } } } m_Mutex.unlock(); return false;}//在DomNode节点的最后插入子节点szChildName,返回新插入子节点的指针QDomNode CXMLReader::InsertChildNode(QDomNode& node, const char* pszChildName){ if (! node.IsValidNode()) return false; m_Mutex.lock(); QDomNode child(pszChildName, ""); node.AddChild(&child); m_Mutex.unlock(); return child;}//在Node节点中添加或修改属性szAttrName,值为szAttrValuebool CXMLReader::InsertAttribute(QDomNode& node, const char* pszAttriName, const char* pszAttriValue){ if (! node.IsValidNode()) return false; m_Mutex.lock(); IEXMLAttribute attri(pszAttriName, pszAttriValue); node.AddAttribute(&attri); m_Mutex.unlock(); return true;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -