Search code examples
javascriptxmldtddtd-parsingsarissa

How to make Sarissa use a DTD when parsing XML?


I am using Sarissa to convert a string of XML into a DOM document object. Everything is working except that Sarissa is completely ignoring my DTD. Deviations from the DTD rules are not noticed, nor do I see any messages about the DTD not being found.

My XML starts like this:

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE workspace SYSTEM "dtd/config.dtd">

and my JavaScript looks like this:

function toXML(str) {
    var responseDoc = (new DOMParser()).parseFromString(str, "text/xml");
    ...
}

How can I get Sarissa to use the DTD?


Solution

  • Sarissa's source code does not have any very special parsing code for DOMParser(). It basically wraps IE's, Safari's, or the Firefox/Opera native implementation, which may not parse DTDs in the browser you are using, since external DTD parsing is sadly an optional aspect of XML (even for entities), and validation is even less certain. The web kind of forces a person to work with server-side substitutions (or possibly internal document subset definitions which may still be ignored as far as validation).