How to load an inline DTD for use with XDocument?

You need to enable DTD processing when you read the XML document. To do that use a XmlReader with appropriate settings.

Up vote 0 down vote favorite share g+ share fb share tw.

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: > 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 list1 = new List(); 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?

C# xml windows-phone-7 xdocument dtd-parsing link|improve this question edited Jul 7 '11 at 23:13R. Martinho Fernandes35.4k1368124 asked Jul 7 '11 at 12:30Graham How1.

MSDN do have WP7 specific forums: forums.create.msdn.com/forums – Matt Lacey Jul 7 '11 at 13:06 1 Don't ask us to click over to the MSDN forums to read the question. Ask it again, in full, with relevant code, here. – ctacke Jul 7 '11 at 15:05.

You need to enable DTD processing when you read the XML document. To do that use a XmlReader with appropriate settings: var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing. Parse }; XmlReader reader = XmlReader.

Create(str, settings); XDocument data = XDocument. Load(reader); If you want to have the DTD external you need to specify a XmlResolver in the settings: var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing. Parse, XmlResolver = /* some resolver here */, }; The default XmlResolver is an XmlUrlResolver which resolves URLs without using credentials.

You may want to consider resolving the DTD from a local source instead. For that you can use a prepopulated XmlPreloadedResolver.

This makes sense and it doesn't matter if I do DTD inline. I tried this but I'm still getting errors, from the stack trace: Message=NotSupportedException StackTrace: at System.Xml. XmlTextReaderImpl.

ParseDoctypeDecl() at System.Xml. XmlTextReaderImpl. ParseDocumentContent() at System.Xml.

XmlTextReaderImpl.Read() at System.Xml.Linq.XDeclaration..ctor(XmlReader r) at System.Xml.Linq.XDocument. Load(XmlReader reader, LoadOptions options) Hmm, I had the idea this was supported. I'll have to double-check tomorrow how we did that at work.

– R. Martinho Fernandes Jul 8 '11 at 2:01 UPDATE: Remove inline DTD and include special characters = exception; Remove special characters and include inline DTD = exception; Remove inline DTD and remove special charactes = OK. – Graham How Jul 8 '11 at 2:15.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions