Introducing the XmlPreloadedResolver
The XmlPreloadedResolver is a new type that we’ve been working on in SilverLight that provides the ability to load a DTD without a call to the network. The new type can act as a manually maintainable cache of DTD’s and XML Streams.
Let’s look at two examples of how the XmlPreloadedResolver can be used.
The XmlPreloadedResolver can be used to pre-load an external DTD. In the following example, a user-defined DTD is pre-loaded into the resolver. The resolver is then used when loading the XML file.
String strDtd = "<!ENTITY entity 'Replacement text'>";
String strXml = @"<!DOCTYPE doc SYSTEM 'myDtd.dtd'>
System.Xml.Resolvers.XmlPreloadedResolver resolver = new XmlPreloadedResolver();
resolver.Add(resolver.ResolveUri(null, "myDtd.dtd"), strDtd);
XmlReaderSettings rs = new XmlReaderSettings();
rs.XmlResolver = resolver;
rs.DtdProcessing = DtdProcessing.Parse;
XmlReader reader = XmlReader.Create(new StringReader(strXml), rs);
For the complete example, refer to: https://msdn.microsoft.com/en-us/library/cc189063(VS.95).aspx
The XmlPreloadedResolver also contains two well-known DTD sets: XHTML 1.0 and RSS 0.91. These two well known DTD sets can be enabled via the XmlKnownDtd enumeration. The following is an example of using the XmlPreloadedResolver to preload the XHTML 1.0 DTD into an XmlReaderSettings object. In this example, no network calls are needed to parse an XHTML file.
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse;
XmlReader reader = XmlReader.Create("HTMLPage.html", settings);
XDocument document = XDocument.Load(reader);
For the complete example, refer to: https://msdn.microsoft.com/en-us/library/cc189059(VS.95).aspx
Look for this new class in System.Xml.Resolvers namespace in a new DLL: System.Xml.Utils.dll that will be included as part of the upcoming SilverLight 2.0 SDK.
Program Manager | Data Programmability
- and -
Senior Software Development Engineer | Data Programmability