- Home /
Dtd validation with TextAsset xml gives exception
I am trying to load xml files and validate them on a DTD file that I've created. But an error is returned by the XmlDocument
. I find it quite obvious why the error is thrown, but I would also like to know how to fix this.
XmlSchemaException: XmlSchema error: XmlSchema error: Specified external entity not found. Target URL is config.dtd . XML Line 2, Position 1.
And the code that performs the DTD validation:
private void ReadConfig()
{
// load the file from resources
TextAsset text = (TextAsset)Resources.Load(filePath);
StringReader sr = new StringReader(text.text);
sr.Read(); // skip BOM, Unity catch!
// validate with a DTD file
XmlReaderSettings settings = new XmlReaderSettings() { ValidationType = ValidationType.DTD, ProhibitDtd = false};
XmlReader r = XmlReader.Create(sr, settings);
XmlDocument doc = new XmlDocument();
doc.Load(r);
}
The xml file that is read contains the following first lines:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Scene SYSTEM "config.dtd">
Why is the dtd file not found? That is because this config.xml is located in Resources\Configs\config.xml
. The dtd-file is in the same folder, but cannot be referenced. Because the file was loaded through a TextAsset
.
Question: How can I reference to the correct dtd file without changing the doctype in the xml-file?
Your answer
Follow this Question
Related Questions
Problems with Loading a XML File for a TileMap using XMLTextReader 1 Answer
How do I use TextAssets for my XML file? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Save and Load from XML help 1 Answer