XDocument and Document Type Definition

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi
I have a question regarding how to include a document type definition into an XML file, or from and XML file, that is being loaded into XDocument, in WP7. I have DTD file that is similar to this:

<pre lang="x-xml <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root [
<!ELEMENT root (Person*)>

<!ELEMENT Person (Name*, Description*)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Description (#PCDATA)>

<!ENTITY egrave "&#232;
<!ENTITY eacute "&#233;
<!ENTITY euro "&#8364;
]>[/code]

<br/>
I need to add this DTD to the XML Im gettng to catch special characters, such as "&eacute;".
I am getting the XML from the web to use in Linq using the following method:

<div style="color:black; background-color:white
<pre> <span style="color:blue private <span style="color:blue void PhoneApplicationPage_Loaded(<span style="color:blue object sender, RoutedEventArgs e)
{
<span style="color:blue string documentUrl = <span style="color:#a31515 "http://www.example.com";

WebClient client = <span style="color:blue new WebClient();

client.OpenReadCompleted += <span style="color:blue new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(<span style="color:blue new Uri(documentUrl, UriKind.Absolute));
}

<span style="color:blue void client_OpenReadCompleted(<span style="color:blue object sender, OpenReadCompletedEventArgs e)
{
Stream str = e.Result;

XDocument data = XDocument.Load(str);

<span style="color:green // Saving the XML to the file system for later use
IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream = <span style="color:blue new IsolatedStorageFileStream(<span style="color:#a31515 "my.xml", FileMode.OpenOrCreate, isoFile);
StreamWriter sw = <span style="color:blue new StreamWriter(isoStream);
XmlWriter xw = XmlWriter.Create(isoStream);

data.Save(xw);

<span style="color:green // Creating a list to populate a listbox
List<MyObject> list1 = <span style="color:blue new List<MyObject>();

items = (<span style="color:blue from query <span style="color:blue in data.Descendants(<span style="color:#a31515 "Person")
<span style="color:blue select <span style="color:blue new MyObject()
{
<span style="color:green // Doing stuff here...
}).ToList();

listBox1.ItemsSource = items;

}
[/code]

<br/>
It seems that XDocument wont pass the XML if the DTD is put inline, i.e. in the actual XML itself.
Ive tried many ways of using XDocumentType based on http://stackoverflow.com/questions/1413053/how-do-i-add-a-document-type-to-an-xdocument" target="_blank
this post, but I cant figure it out.
Any help loading DTD for use in XDocument greatly appreciated.
Thanks!

View the full article
 
Back
Top