谁能给个示范。怎么指定这个xml的dtd文件的位置,用什么函数去读取dtd文件
解决方案 »
- 求教一个C# double小数点位数保留问题
- C#调用ocx控件的方法,传递ref byte参数出错
- 在64位系统下,C#调用C++的64位DLL,报错:1114错误,同样的编译成32位的DLL就没问题
- 有关水晶报表的问题
- 关于获取datagridview中单元格的问题
- 今天我在microsoft 上下的一个demo 有些地方看不懂,请大家指教!
- xml导入sql server 2005 急!!!
- 问一个WINDOWS SERVER 2003的问题
- 编译时出现的“对路径"9xvenne-0.dll"的访问被拒绝”的警告出现的原因?高手请帮忙!
- 用C#如何实现象Office助手的功能(浮在最上层,可以任意拖动)?????????
- 【求助】数据库修改问题,各位帮帮忙
- 辣手的XML,如何将sql server批量导出到xml?
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);
} }
}
}
这个有什么问题?
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