Thursday, September 3, 2009

About XmlPreloadedResolver

when using Silverlight then XmlPreloadedResolver meaning is very useful, its a new type which can be useful when your working with XML . on XmlPreloadedResolver it has the Ability to load the DTD without call to network. This type manually maintain the DTD cache and all other with xml streams. XmlPreloadedResolver includes RSS1.0 and XHTML1.0 Defination of DTD.

sample code on how to work with XmlPreloadedResolver

String strDtd = "";
XmlPreloadedResolver resolver = new XmlPreloadedResolver();
resolver.Add(resolver.ResolveUri(null, "nameofDTD.dtd"), strDtd);
XmlReaderSettings rs = new XmlReaderSettings();
rs.XmlResolver = resolver;
rs.DtdProcessing = DtdProcessing.Parse;
XmlReader reader = XmlReader.Create("samplexml.xml", rs);

now you can also set the DTD sets Enable using XmlKnownDtds enumeration.
XmlKnownDtds is used with the XmlPreloadedResolver to identify the well-known DTD

the following example shos preloading Xhtml1.0 DTd into the XmlReaderSettings object
here there is no need of network call to parse the Xhtml will done automatically.

XmlReaderSettings settings = new XmlReaderSettings();
//define the Setting object to parsing DTD
settings.DtdProcessing = DtdProcessing.Parse;
// Define preloading Xhtml10 DTD
settings.XmlResolver = new XmlPreloadedResolver(XmlKnownDtds.Xhtml10);
//suppose read the sample.html file using XmlReader
XmlReader reader = XmlReader.Create("sample.html", settings);
// and load using XDocument object
XDocument document = XDocument.Load(reader);

for more refer to :

No comments:

Post a Comment