谁能给个示范。怎么指定这个xml的dtd文件的位置,用什么函数去读取dtd文件

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using System.IO;
    using System.Xml;namespace ReadDBLP
    {
        class ReadDBLP
        {        public class MyResolver : XmlUrlResolver
            {
                public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
                {
                    if (absoluteUri.AbsoluteUri == "D:/people.dtd")
                    {
                        return File.Open("people.dtd", FileMode.Open);
                    }                return base.GetEntity(absoluteUri, role, ofObjectToReturn);
                }        }        public void Load(string path)
            {
               
                XmlReaderSettings settings=new XmlReaderSettings();
                settings.ValidationType = ValidationType.DTD;
                settings.ProhibitDtd = false;
                settings.XmlResolver = new MyResolver();
                using (XmlReader reader = XmlReader.Create("D:/people.xml", settings))
                {
                    XDocument document = XDocument.Load(reader);
                }        }
        }
    }
    这个有什么问题?
      

  2.   

    using System;
    using System.IO;
    using System.Xml;
    using System.Net;public class Sample {  public static void Main() {    // Supply the credentials necessary to access the DTD file stored on the network.
        XmlUrlResolver resolver = new XmlUrlResolver();
        resolver.Credentials = CredentialCache.DefaultCredentials;    // Create and load the XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.XmlResolver = resolver;  // Set the resolver.
        doc.Load("book5.xml");    // Display the entity replacement text which is pulled from the DTD file.
        Console.WriteLine(doc.DocumentElement.LastChild.InnerText);
      
      }
    } // End class