x


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?

more ▼

asked May 09 '12 at 09:58 AM

Marnix gravatar image

Marnix
1.3k 22 31 45

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4359
x262
x45
x1

asked: May 09 '12 at 09:58 AM

Seen: 480 times

Last Updated: May 09 '12 at 09:58 AM