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?
asked
May 09 '12 at 09:58 AM
Marnix
1.3k
●
22
●
31
●
45