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 + "']";

  • 相关阅读:
    Cayley's Tree Formula & Prufer's Method
    POJ 2262:Goldbach's Conjecture
    The Sieve of Eratosthenes (素数筛选法)
    POJ 2244:Eeny Meeny Moo(稍加变形的约瑟夫问题)
    POJ 1595:Prime Cuts
    iframe标签的使用
    js笔记
    Asp.Net知识点
    Reapte控件的使用
    浮躁十年
  • 原文地址:https://www.cnblogs.com/zihunqingxin/p/3059434.html
Copyright © 2011-2022 走看看