Export (0) Print
Expand All

Processing DTD Content in Silverlight

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.

Prohibit specifies that when a DTD is encountered, an XmlException is thrown with a message that states that DTDs are prohibited. This is the default behavior.

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.

Important note Important Note:

When DtdProcessing.Ignore is specified, the XmlReader will not report the DTDs. This means that the DTD/DOCTYPE will be lost on output.

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); 

Rss091 specifies that XmlPreloadedResolver will recognize DTDs and entities that are defined in RSS 0.91. The following example creates an XmlPreloadedResolver that preloads RSS 0.91 DTD.

// 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);

None specifies that the XmlPreloadedResolver will not recognize any of the predefined DTDs.

NoteNote:

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.

In Silverlight, the ProhibitDTD property was removed from XmlReaderSettings, and the DtdProcessing property was added. The default value of the DtdProcessing property is Prohibit.

Community Additions

ADD
Show:
© 2015 Microsoft