Export (0) Print
Expand All

How to: Implicitly Load a DTD from a XAP Package Using XmlXapResolver

Silverlight

The example in this topic uses XmlXapResolver to load an XML file that references an external DTD from the XAP package. This implicitly loads the DTD.

To configure a Silverlight Visual Studio project to run this example

  1. In Solution Explorer, add assembly references to System.Xml.dll.

  2. Create the Nmtoken.dtd file, and add it to your project. This will also add it to your application's XAP package. Make sure that the Build Action property of the Nmtoken.dtd file is set to Content. Add the following content to Nmtoken.dtd:

    <!ELEMENT datatype (desc)>
    <!ELEMENT desc (#PCDATA)>
    <!ENTITY entity 'Replacement text'>
    <!ATTLIST desc
       att NMTOKEN #REQUIRED
    >
    
  3. Create the Nmtoken.xml file, and add it to your project. This will also add it to your application's XAP package. Make sure that the Build Action property of the Nmtoken.xmlfile is set to Content. Add the following content to Nmtoken.xml:

    <?xml version="1.0"?>
    <!DOCTYPE datatype SYSTEM "nmtoken.dtd">
    <datatype>
       <desc att="abc">&entity;</desc>
    </datatype>
    
  4. In the page.xaml.cs (page.xaml.vb in Visual Basic) source file for your application, add the following using statements (Imports in Visual Basic):

    
    using System.Xml;
    using System.Text;
    using System.Xml.Linq;
    
    
    

The following example shows how to load an XML file that references a DTD file from your application's XAP package, using XmlXapResolver.


StringBuilder output = new StringBuilder();

XmlReaderSettings rs = new XmlReaderSettings();
rs.DtdProcessing = DtdProcessing.Parse;

// XmlXapResolver is the default resolver.
using (XmlReader reader = XmlReader.Create("nmtoken.xml", rs))
{
    XDocument document = XDocument.Load(reader);
    OutputTextBlock.Text = document.ToString();
}


Community Additions

ADD
Show:
© 2014 Microsoft