zoukankan      html  css  js  c++  java
  • XPATH 命名空间

    XmlDocument config = new XmlDocument();
    //读XML文件

    config.Load(HttpContext.Current.Server.MapPath("/web.sitemap"));
    XmlNode root = config.DocumentElement;
    XmlNamespaceManager n = new XmlNamespaceManager(config.NameTable);
    n.AddNamespace("china", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
    string xpath = "//china:siteMapNode[@title='" + platename + "']";
    //版块
    // XmlNode platenode = config.SelectSingleNode(xpath, n);
    XmlNode platenode =config.SelectSingleNode(xpath, n);
    //XmlNode platenode = root.SelectSingleNode(xpath, n);
    string plateurl = platenode.Attributes["url"].Value;

    注意命名空间,当时这问题搞了近一小时,一找发现是命名空间不对。

    命名空间为向下包含

    应用  xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"

    定义 xmlns:m="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0"

      定义后,子级元素可以直接 xmlns=m

    主要部分

    XmlNamespaceManager n = new XmlNamespaceManager(config.NameTable);
    n.AddNamespace("china", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
    string xpath = "//china:siteMapNode[@title='" + platename + "']";

  • 相关阅读:
    翻转单词顺序序列
    左旋转字符串
    查找第一个只出现一次的字符
    C语言函数与程序结构
    C语言实现快速排序法(分治法)
    C语言binsearch,shellsort,insertsort
    c语言的类型、运算符与表达式
    进程和线程
    CMS和G1
    Python IO编程
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/3059434.html
Copyright © 2011-2022 走看看