KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm trying to do xpath queries over an xhtml document. Using .NET 3.5. The document looks like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> .... </head> <body> ... </body> </html> Because the document includes various char entities ( and so on), I need to use the DTD, in order to load it with an XmlReader . So my code looks like this: var s = File.OpenRead(fileToRead) var reader = XmlReader.Create(s, new XmlReaderSettings{ ProhibitDtd=false }); But when I run this, it returns An error has occurred while opening external DTD ' http://www.w3.org/TR/xhtml1-transitional.dtd ': The remote server returned an error: (503) Server Unavailable. Now, I know why I am getting the 503 error. W3C explained it very clearly . I've seen "workarounds" where people just disable the DTD. This is what ProhibitDtd=true can do, and it eliminates the 503 error. But in my case that leads to other problems - the app doesn't get the entity defintions and so isn't well-formed XML. How can I validate with the DTD, and get the entity definitions, without hitting the w3.org website? I think .NET 4.0 has a nifty built-in capability to handle this situation: the <a href="http://msdn.microsoft.com/en-us/library/system.xml.resolvers.xmlpreloadedresolver(VS.95).aspx" rel="nofollow norefer
Tags (comma-separated)
Save Edits
Cancel