<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
 <context-param>
 <param-name>isSuperNode</param-name>
    <param-value>yes</param-value>
      </context-param>
      
  <context-param>
    <param-name>superNode</param-name>
    <param-value>192.168.0.32_192.168.0.83_192.168.0.44_192.168.0.88_192.168.0.7_192.168.0.66_192.168.0.29</param-value>
  </context-param>
  
  <context-param>
    <param-name>generalNode</param-name>
    <param-value>192.168.0.1_192.168.0.2</param-value>
  </context-param>
  
  <context-param>
    <param-name>webPath</param-name>
   <param-value></param-value>
  </context-param>
  
  <context-param>
    <param-name>timeOut</param-name>
    <param-value>100</param-value>
  </context-param>
</web-app>
如果把根结点那些命名空间和规范信息去掉,读取就没有错误,如果加上就空指针异常,请高手帮忙! XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("D:\\web.xml");           XmlNode root = xmlDoc.SelectSingleNode("web-app");            //XmlNode root = xmlDoc.FirstChild;              //XmlNodeList xnl = root.ChildNodes;
            if(root.HasChildNodes)   //这句抛出异常
            {
            }

解决方案 »

  1.   

    应该是你的schema文件没找到吧
      

  2.   

    XmlSchemaSet schemaSet = new XmlSchemaSet();
    schemaSet.Add("<nameSpace>", "<path to schema file>");
    XmlDocument sessionDocument = new XmlDocument();
    sessionDocument.Schemas = schemaSet;
    sessionDocument.Load("<path to xml file>");ValidationEventHandler eventHandler = new ValidationEventHandler(HandleValidationError);
    sessionDocument.Validate(eventHandler);
      

  3.   

    using System;
    using System.IO;
    using System.Xml;
    using System.Xml.Schema;
    namespace XmlSchemaVal
    {
       class Program
       {
          static void Main(string[] args)
          {
             XmlSchemaSet schemas = new XmlSchemaSet();
             schemas.Add("http://tempuri.org/XMLSchema1.xsd", "..\\..\\XmlSchema1.xsd");
             XmlDocument doc = new XmlDocument();
             doc.Schemas = schemas;         bool containsErrors = false;         doc.Load("..\\..\\XmlFile1.xml");
             ValidationEventHandler validator = delegate(object sender, ValidationEventArgs e)
             {
                containsErrors = true;
                Console.WriteLine("{0}: {1}", e.Severity, e.Message);
             };         doc.Validate(validator);
             if (containsErrors)
             {
                Console.WriteLine("Document Contains Errors");
             }
          }
       }
    }