BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in .NET XML, System.XML

 
 
Page 2956 of 20224

Introducing the XmlPreloadedResolver

Blogger : MSDN Blogs
All posts : All posts by MSDN Blogs
Category : .NET XML, System.XML
Blogged date : 2008 Aug 14

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


Read comments or post a reply to : Introducing the XmlPreloadedResolver
Page 2956 of 20224

Newest posts
 

    Email TopXML