Reputation: 415
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
Upvotes: 0
Views: 1135
Reputation: 415
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));
Upvotes: 0
Reputation: 163458
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.
Upvotes: 2
Reputation: 28981
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.
Upvotes: 0