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 file.it 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 : http://msdn.microsoft.com/en-us/library/cc189059(VS.95).aspx
No comments:
Post a Comment