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:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root [
<!ELEMENT root (Person*)>
<!ELEMENT Person (Name*, Description*)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Description (#PCDATA)>
<!ENTITY egrave "è">
<!ENTITY eacute "é">
<!ENTITY euro "€">
]>
I need to add this DTD to the XML I'm getting to catch special characters, such as é
.
I am getting the XML from the web to use in Linq using the following method:
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
string documentUrl = "http://www.example.com";
WebClient client = new WebClient();
client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
client.OpenReadAsync(new Uri(documentUrl, UriKind.Absolute));
}
void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
Stream str = e.Result;
XDocument data = XDocument.Load(str);
// Saving the XML to the file system for later use
IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication();
IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("my.xml", FileMode.OpenOrCreate, isoFile);
StreamWriter sw = new StreamWriter(isoStream);
XmlWriter xw = XmlWriter.Create(isoStream);
data.Save(xw);
// Creating a list to populate a listbox
List<MyObject> list1 = new List<MyObject>();
items = (from query in data.Descendants("Person")
select new MyObject()
{
// Doing stuff here...
}).ToList();
listBox1.ItemsSource = items;
}
It seems that XDocument won't pass the XML if the DTD is put inline, i.e. in the actual XML itself. I've tried many ways of using XDocumentType based on this post, but I can't figure it out. How can I do this?