tijian_tieying/web/cyqdata-master/Xml/XHtmlUrlResolver.cs
2025-02-20 12:14:39 +08:00

80 lines
2.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CYQ.Data.Properties;
using CYQ.Data.Tool;
using System;
using System.IO;
namespace CYQ.Data.Xml
{
internal class ResolverDtd
{
public static void Resolver(ref System.Xml.XmlDocument xmlDoc)
{
xmlDoc.XmlResolver = XHtmlUrlResolver.Instance;
}
}
internal class XHtmlUrlResolver : System.Xml.XmlUrlResolver
{
private static XHtmlUrlResolver _Resolver = null;
public static XHtmlUrlResolver Instance
{
get
{
if (_Resolver == null)
{
_Resolver = new XHtmlUrlResolver();
}
return _Resolver;
}
}
private string dtdUri = null;
public string DtdUri
{
get
{
if (dtdUri == null)
{
dtdUri = AppConfig.XHtml.DtdUri;
string folder = Path.GetDirectoryName(dtdUri);
//检测文件是否存在
if (!Directory.Exists(folder))//有异常直接抛
{
Directory.CreateDirectory(folder);
}
string[] items = new string[] { "/xhtml1-transitional.dtd", "/xhtml-lat1.ent", "/xhtml-special.ent", "/xhtml-symbol.ent" };
if (!File.Exists(folder + items[0]))
{
using (FileStream fs = File.Create(folder + items[0]))
{
fs.Write(Resources.xhtml1_transitional, 0, Resources.xhtml1_transitional.Length);
}
using (FileStream fs = File.Create(folder + items[1]))
{
fs.Write(Resources.xhtml_lat1, 0, Resources.xhtml_lat1.Length);
}
using (FileStream fs = File.Create(folder + items[2]))
{
fs.Write(Resources.xhtml_special, 0, Resources.xhtml_special.Length);
}
using (FileStream fs = File.Create(folder + items[3]))
{
fs.Write(Resources.xhtml_symbol, 0, Resources.xhtml_symbol.Length);
}
}
}
return dtdUri;
}
}
///assemblyShortName;component/resourceLocation 例如"/SilverlightLibraryAssembly;component/image.png"。 请注意,需要使用前导斜杠和 component 关键字(后跟一个斜杠)。
public override Uri ResolveUri(Uri baseUri, string relativeUri)
{
if (relativeUri.Contains("xhtml1-transitional.dtd") && DtdUri != null)
{
relativeUri = DtdUri;
}
return base.ResolveUri(baseUri, relativeUri);
}
}
}