首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

!关于xpath 检索XML的有关问题!

2012-01-21 
求助!关于xpath 检索XML的问题!!各位:我用xpath语句是:dsxmlTool.GetData( //m[@l\ 欧洲联赛冠军杯\

求助!关于xpath 检索XML的问题!!
各位:
我用xpath   语句是:
    ds   =   xmlTool.GetData( "//m[@l=\ "欧洲联赛冠军杯\ "] ");
想提取所有的l=“欧洲联赛冠军杯”的节点。
语句已经成功!但是在ds中只有一行数据。是我xpath写的不对,还是下面的提取方法有问题。提取方法:
————————————————————————————————
public   DataSet   GetData(string   XmlPathNode)
                {
                                                DataSet   ds   =   new   DataSet();
                        StringReader   read   =   new   StringReader(objXmlDoc.SelectSingleNode(XmlPathNode).OuterXml);
                        ds.ReadXml(read);
                        return   ds;
                }
————————————————————————————————————


XML格式是:
——————————————————————————————————
  <?xml   version= "1.0 "   encoding= "gb2312 "   ?>  
  <g>
  <s>
    <m   i= "218057 "   l= "新加坡职业联赛 "   c= "#FF99CC "   a= "雅龙联 "   b= "卡沙 "   d= "2007,07,31,19,45 "   tv= " "   as= " "   bs= " "   ah= " "   bh= " "   ar= " "   br= " "   st= "未开赛 "   />  
    <m   i= "234837 "   l= "欧洲联赛冠军杯 "   c= "#F75000 "   a= "佩历克 "   b= "萨克达 "   d= "2007,07,31,23,00 "   tv= " "   as= " "   bs= " "   ah= " "   bh= " "   ar= " "   br= " "   st= "未开赛 "   />  
    <m   i= "234795 "   l= "友谊赛 "   c= "#003333 "   a= "华登舒特 "   b= "波琴 "   d= "2007,08,01,00,00 "   tv= " "   as= " "   bs= " "   ah= " "   bh= " "   ar= " "   br= " "   st= "未开赛 "   />  
    <m   i= "234839 "   l= "欧洲联赛冠军杯 "   c= "#F75000 "   a= "谭柏利 "   b= "索菲亚利夫斯基 "   d= "2007,08,01,00,00 "   tv= " "   as= " "   bs= " "   ah= " "   bh= " "   ar= " "   br= " "   st= "未开赛 "   />  
    <m   i= "234797 "   l= "友谊赛 "   c= "#003333 "   a= "费雷堡 "   b= "卡斯鲁厄 "   d= "2007,08,01,00,15 "   tv= " "   as= " "   bs= " "   ah= " "   bh= " "   ar= " "   br= " "   st= "未开赛 "   />  
 
   
    </s>
    </g>
————————————————————————————————————

[解决办法]
ds = xmlTool.GetData( "//m[@l=\ "欧洲联赛冠军杯\ "] ");
==>
ds = xmlTool.GetData( "g/s/m[@l= '欧洲联赛冠军杯 '] ");


[解决办法]
其实楼主先把数据读取到dataset,然后在dataset中过滤更方便。

DataSet ds = new DataSet();
ds.ReadXml(@ "f:\a.xml ");
ds.Tables[ "m "].DefaultView.RowFilter = "l= '欧洲联赛冠军杯 ' ";
[解决办法]
for dataset and xml, use XmlDataDocument
[解决办法]
SelectSingleNode

只取第一个节点。见名之意,楼主一定大意了。

热点排行