Processing DTD Content in Silverlight
The Microsoft .NET Framework for Silverlight consists of a subset of the .NET Framework class library and some additional types and members that are not included in the standard .NET Framework class library. The differences between the two frameworks include some design and functionality changes related to processing DTD content in Silverlight. This topic describes these changes.
For examples of how to load DTDs, see the following topics:
The DtdProcessing enumeration contains the Prohibit, Ignore, and Parse enumerators. This enumeration is set on the DtdProcessing property. In the .NET Framework for Silverlight, the XmlReaderSettings.DtdProcessing property replaces the ProhibitDTD property and adds the ability to ignore the DOCTYPE element.
Parse is used for parsing DTDs. If you only have to parse internal DTDs, you use Parse without resolvers. If an external DTD is referenced, you have to use XmlXapResolver, XmlPreloadedResolver, or your own resolver.
Ignore causes the DOCTYPE element to be ignored. In this case, no DTD processing occurs. If the XmlReader encounters an entity (such as ), an XmlException is thrown with a message that states that no entities can be processed.
XmlPreloadedResolver uses the XmlKnownDtds enumeration. This enumeration defines which well-known DTDs XmlPreloadedResolver recognizes. Because XmlKnownDtd is a flags enumeration, you can use the or operator (|) to specify multiple DTDs.
Xhtml10 specifies that XmlPreloadedResolver will recognize DTDs and entities that are defined in XHTML 1.0. For more information about XHTML, see the XHTML 1.0 specification. The following example creates an XmlPreloadedResolver that preloads the XHTML 1.0 DTD.
// Only the XHTML 1.0 DTD will be recognized. new XmlPreloadedResolver(XmlKnownDtds.Xhtml10);
// Only RSS 0.91 DTD will be recognized. new XmlPreloadedResolver(XmlKnownDtds.Rss091);
All specifies that the XmlPreloadedResolver will recognize all currently supported DTDs. This is the default behavior. The following example creates an XmlPreloadedResolver that preloads both RSS 0.91 and XHTML 1.0 DTDs.
// All DTDs will be recognized. new XmlPreloadedResolver(XmlKnownDtds.All); // Both XHTML 1.0 and RSS 0.91 DTDs will be loaded and recognized. new XmlPreloadedResolver(XmlKnownDtds.Xhtml10 | XmlKnownDtds.Rss091);
When the XmlPreloadedResolver preloads well-known DTDs, it does not invoke network connections, because the DTDs are already embedded in the System.Xml.Utils assembly.
The XmlPreloadedResolver type is used as a resolver when automatic calls to the network are not desired or are not possible. For example, this type can be used for loading cached external DTDs. Or, you might use XmlPreloadedResolver to preload well-known DTDs that are defined in XHTML 1.0. Preloading a well-known DTD does not invoke any network connections, because these DTDs are already embedded in the System.Xml.Utils assembly. Currently, XmlPreloadedResolver includes DTDs defined in XHTML 1.0 and RSS 0.91.