100分CMarkup类实现的GetElemPath方法
100分求一个CMarkup类实现的GetElemPath方法
有代码跟思路都可,功能就是实现CMarkup类的GetElemPath方法:
MCD_STR CMarkup::GetElemPath() const;
The GetElemPath method returns the absolute path of the main position element.
自己写了一个在遇到重名节点的时候总遇到问题,EMAIL:Terry-no1@163.com
例子:
<config>
<diagnostics d="3">
<file>C:\temp\a.txt</file>
</diagnostics>
<diagnostics d="7">
<file>D:\temp\a.txt</file>
<proxy usedefault="true"/>
</diagnostics>
</config>
代码:
xml.ResetPos();
while ( xml.FindElem("//*") )
printf( xml.GetElemPath() );
结果:
/config
/config/diagnostics
/config/diagnostics/file
/config/diagnostics[2]
/config/diagnostics[2]/file
/config/diagnostics[2]/proxy
------解决方案--------------------
XPath就这样。。。
------解决方案--------------------
------解决方案--------------------
有代码跟思路都可,功能就是实现CMarkup类的GetElemPath方法:
MCD_STR CMarkup::GetElemPath() const;
The GetElemPath method returns the absolute path of the main position element.
自己写了一个在遇到重名节点的时候总遇到问题,EMAIL:Terry-no1@163.com
例子:
<config>
<diagnostics d="3">
<file>C:\temp\a.txt</file>
</diagnostics>
<diagnostics d="7">
<file>D:\temp\a.txt</file>
<proxy usedefault="true"/>
</diagnostics>
</config>
代码:
xml.ResetPos();
while ( xml.FindElem("//*") )
printf( xml.GetElemPath() );
结果:
/config
/config/diagnostics
/config/diagnostics/file
/config/diagnostics[2]
/config/diagnostics[2]/file
/config/diagnostics[2]/proxy
------解决方案--------------------
XPath就这样。。。
------解决方案--------------------
------解决方案--------------------
- C/C++ code
//功 能:根据所选择的树节点的句柄产生xml搜索数据路径,存在全局变量save_pathdata数组中 // 低16位表示节点的类型(节点号) // 高16位表示路径所经过的节点在同父下所有兄弟节点中的序号 //返回值:save_pathdata数组有效长度(非零值个数),即节点所在深度(第几层) int GetCurItem_datapath(HTREEITEM hTreeItem) { int data_valid_length = 1;//树项数据路径的有效值至少为1(至少为根节点),实际是所在深度(第几层) int current_sibling_num = 1;//当前节点所在所有兄弟节点中的序号 int treeroot_sibling_num = 1;//根节点序号唯一,且为1 memset(save_pathdata, 0, 50); if (hTreeItem == handle_TreeRoot) {//如果是根节点 save_pathdata[0] = node_rootpoint|(treeroot_sibling_num<<16); return 1;//datapath就根节点一个 } else { current_sibling_num = GetCurItem_serialnum(hTreeItem);//在所有节点中的序号 save_pathdata[0] = (m_tree.GetItemData(hTreeItem))|(current_sibling_num<<16); HTREEITEM hNextItem = m_tree.GetParentItem(hTreeItem); while(hNextItem) {//下一个父亲节点 data_valid_length++; current_sibling_num = GetCurItem_serialnum(hNextItem); save_pathdata[data_valid_length-1] = (m_tree.GetItemData(hNextItem))|(current_sibling_num<<16); hNextItem = m_tree.GetParentItem(hNextItem); } save_pathdata[data_valid_length-1] = node_rootpoint|(treeroot_sibling_num<<16);//最后一个必为根节点 return data_valid_length; } } //---------------------------------- //附: //函数功能取得树控件当前所选节点在所有兄弟节点中的序号(从1开始) int CCTD_UTK_MenuCreatDlg::GetCurItem_serialnum(HTREEITEM hTreeItem) { int CurItem_index = 1; HTREEITEM hNextItem = m_tree.GetPrevSiblingItem(hTreeItem); while(hNextItem) { //当前所选节点在所有兄弟节点中的序号 CurItem_index++; hNextItem = m_tree.GetPrevSiblingItem(hNextItem); } return CurItem_index; } //---------------------------------- //友情说明 //全局变量save_pathdata数组 可定义如下 DWORD save_pathdata[50] = {0};//存取树节点路径的完整数据(分高低各16位两个部分) //低16位表示节点的类型,高16位表示路径所经节点在同父下所有兄弟节点中的序号 //设计思想 //每当遇到一个节点的时候 就给他定义一个类型 设定一个类型值 //使用函数如:m_tree.SetItemData(handle_TreeRoot,node_rootpoint); //设置属性数据(与一个项关联的32位的应用程序指定值) //然后选择一个xml节点的时候 根据类型值和序号 递归方法向上找 就可以找到一个路径 //然后保存路径的值到数组中 不过这个路径值是反向的 //其他的具体的问题就请LZ自己解决了 根据数组生成path应该很容易了~~~ // // // // // // // //
------解决方案--------------------
呵呵 我之前弄了个比较笨的办法。。。就是利用cmarkup类里面提供的 父节点和子节点的位置的变量 貌似可以利用看看。。。xml.m_iPos; xml.m_iPosChild;