Freigeben über


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.

Example 1:

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'>

<doc>&entity;</doc>";

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

Example 2:

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;

settings.XmlResolver =

new XmlPreloadedResolver(XmlKnownDtds.Xhtml10);

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.

Shayne Burgess
Program Manager | Data Programmability

- and -

Helena Kotas
Senior Software Development Engineer | Data Programmability

Comments

  • Anonymous
    August 14, 2008
    PingBack from http://blog.a-foton.ru/2008/08/introducing-the-xmlpreloadedresolver/

  • Anonymous
    August 14, 2008
    Is it Silverlight-specific, or will it also appear in the full version of the Framework? Writing all the code to preload local DTDs for XML files is possible there at the moment, but very tedious. Something like this would really help.

  • Anonymous
    August 14, 2008
    Ditto the comment above, having this in the full framework would be incredibly useful.

  • Anonymous
    August 16, 2008
    The comment has been removed

  • Anonymous
    August 27, 2008
    Hey ALLO___XHTML preloadER DTD FOR XML FILES OVER TIME MACHINES AND DRIVES do nothing OR WE'LL BE TALKING like PHYSICAL APPLICATIONS FOR THESES PROCEDURES OR PROCESSES i DO NOT BELIEVE in it and can't BE DONE BECAUSE IT's LIKE ME SAYING APPARENTLY I HAVE SIMOLTANEUS INITIATIVES and yello dog the OKAY user IN A FIGHTING SCENEREO. The thesis for resolving such an issue is nothing + not working.....understand no resolver droped well or be on the matter ecx. think my machine will not come on without a physical application process R.S.V.P;.

  • Anonymous
    September 04, 2008
    Thanks for the feedback. Currently, the XmlPreloadedResolver is only in the SilverLight 2.0 SDK. We have talked about including it in the next version of the framework but we have not made a decision yet if we will. We will take this feedback into account, however, when we do make the decision. -Shayne