Question

I have XML files which contains a doctype:

<!DOCTYPE someName SYSTEM "fileName.dtd">

The file is provided by a 3rd party, I have no control over how it is generated. I use XSLT to transform the XML, but XSLT complains about the dtd not found; how do I tell XSLT to ommit it so it doesn't try to access the dtd file which I don't have.

Thanks

Was it helpful?

Solution 3

Found out how to do it for C#

XmlReaderSettings x = new XmlReaderSettings();
x.DtdProcessing = DtdProcessing.Ignore;
myXslTransform.Load(xslFile);
myXslTransform.Transform(XmlReader.Create(xslFile, x), XmlWriter.Create(xmlFileOutput));

OTHER TIPS

You can set the EntityResolver of the XML parser to an EntityResolver that substitutes a local file (perhaps an empty file) when the DTD is requested. Create an XMLReader (parser) with this setting, then supply a SAXSource containing this XMLReader as the source input to the transformation.

Which xslt-processor do you use? You have to find a way to disable validation for it. E.g. for Java you could do it so: http://www.stylusstudio.com/xsllist/200205/post80150.html

The main reason why it's here: the dtd could have default data which affects xml content. E.g. if an attribute "align" has default value "left", the xslt template match "[@align='left']" will match even if attribute is not occurring in an XML.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top