Introducing the XmlPreloadedResolver

Introducing the XmlPreloadedResolver

  • Comments 6

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:  http://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: http://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

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

  • 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.

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

  • I would also like to chime in and vote +1 for getting this feature in the full .NET Framework.

    In a project at my previous employer we suffered through big performance problems when parsing XHTML 1.0 as XML using .NET 1.1. This happened when the XHTML contained hundreds of entity references. We were feeding the full XHTML DTD to the XML parser. Parsing performance degraded much faster than linearly with the number of entity references in the XHTML.

    As a workaround we had to manually strip the XHTML DTD down to contain just the entity definitions (&euml; etc). Performance become acceptable in that case. I hope these issues have been fixed.

  • 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;.

  • 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

Page 1 of 1 (6 items)