You can find the following in the documentation of LoadXml
method which you use in your code:
This method does not do DTD or Schema validation. If you want validation to occur, use the
Load
method and pass it anXmlValidatingReader
. SeeXmlDocument
for an example of load-time validation
The article, this one and many other provide code examples of DTD validation.