Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2315251
  • 博文数量: 527
  • 博客积分: 10343
  • 博客等级: 上将
  • 技术积分: 5565
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-26 23:05
文章分类

全部博文(527)

文章存档

2014年(4)

2012年(13)

2011年(19)

2010年(91)

2009年(136)

2008年(142)

2007年(80)

2006年(29)

2005年(13)

我的朋友

分类: WINDOWS

2009-04-08 17:51:38

    public static void RunSnippet()
    {
        string xml_str = @"




"
;
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xml_str);
        // Find the element which has a preceding sibling with attribite dever

        string xpath = "//a[ preceding-sibling::*[@name='dever'] ]";
        XmlElement ma = doc.SelectSingleNode(xpath) as XmlElement;
        if(ma != null)
        {
        WL( ma.OuterXml );
        }
    }

要查找要节点本身并没有特别的特征, 因此不能在xpath中指定其查找条件, 条件在于它前面的兄弟节点的特征, 希望找到这样的节点之下的节点, 上面的办法还有点绕, 其实可以用更直观的:

string xpath = "//a[ @name='dever']/following-sibling::a/following-sibling::a";

查找到该节点开始的第二个兄弟节点, 不过没办法指定数字来循环, 想要第10个兄弟节点时就累了.

阅读(1569) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~