NewXMLNode变为null.如何解决这个问题 [英] NewXMLNode become null.how to solve this

查看:96
本文介绍了NewXMLNode变为null.如何解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net Web应用程序中,我有一个.ashx页面
.ashx页面中的代码是

in my asp.net web application i have a .ashx page
code in .ashx page is

  string  CommonPath = "~/Admin/Content/Dept/Gallery/CSE/gallery.xml";

XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(context.Server.MapPath(CommonPath));//"~/Admin/Content/Activites/Gallery/SportsGallery/gallery.xml"));

                DataSet ds = new DataSet();
                ds.ReadXml(context.Server.MapPath(CommonPath));

                //XmlNode newXMLNode = xmlDoc.SelectSingleNode("/gallery/category[contains(@name,'" + category + "')]");
                string test = "test";
                XmlNode newXMLNode = xmlDoc.SelectSingleNode("/gallery/category[contains(@name,'" + test + "')]");
                XmlNode childnode = xmlDoc.CreateNode(XmlNodeType.Element, "image", "");




这里newXMLNode变为null.如何解决此问题



我的xml是
...................






here newXMLNode become null.how to solve this



my xml is
...................



<?xml version="1.0" standalone="yes"?>
<gallery title="Tony's Photo Album" thumbDir="./images/thumbs/" imageDir="./images/" random="true">
  <category name="MECH">
    <image>
      <date>29/5/2012</date>
      <title>
      </title>
      <desc>
      </desc>
      <thumb>86.jpg</thumb>
      <img>86.jpg</img>
    </image>
    <image>
      <date>29/5/2012</date>
      <title>
      </title>
      <desc>
      </desc>
      <thumb>88.jpg</thumb>
      <img>88.jpg</img>
    </image>
    <image>
      <date>29/5/2012</date>
      <title>
      </title>
      <desc>
      </desc>
      <thumb>90.jpg</thumb>
      <img>90.jpg</img>
    </image>





<category name="test">
    <image>
      <date>3/8/2012</date>
      <title>
      </title>
      <desc>
      </desc>
      <thumb>Winter.jpg</thumb>
      <img>Winter.jpg</img>
    </image>
    <image>
      <date>3/8/2012</date>
      <title>
      </title>
      <desc>
      </desc>
      <thumb>Water lilies.jpg</thumb>
      <img>Water lilies.jpg</img>
    </image>

推荐答案

如果XPath查询的结果为null,则它将为null.没办法解决.
If the result of your XPath query is null, it will be null. There''s no way around that.


这篇关于NewXMLNode变为null.如何解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆