1
Vote

Enable DTD processing to allow entity inclusion

description

It would be nice to be able to combine multiple XML files into one without having to go to too much trouble. For example, maybe the RSBuild.config file contains a lot of deployment-specific data but there is a file containing a lot of <Report Name="reportname"><FilePath>path.rdl</FilePath></Report> definitions that is constant between all deployments. In such a case, I’d like to do:
<?xml version="1.0"?>
<!DOCTYPE RSBuild [
<!ENTITY Reports SYSTEM "RSBuild.Reports.config" >
] >
<Settings>
  <Globals/>
  <!-- (and all of the other necessary config things) -->
  <Reports>
    <ReportGroup>
&Reports;
    </ReportGroup>
  </Reports>
</Settings>
and then in RSBuild.Reports.config I can have something like:
<!-- -*- mode: nxml; -*- -->
<!--
    Since this file is included into RSBuild.config using an entity reference,
    you may not prefix this file with a DOCTYPE or processing instructions
    (e.g., <?xml?>).
-->
<Report Name="reportname">
  <FilePath>path.rdl</FilePath>
</Report>
<Report Name="reportname2">
  <FilePath>path2.rdl</FilePath>
</Report>
<!--
    And so on. I could even automatically generate just this file based
    on some convention where ReportName.rdl sets Name="ReportName"
    and FilePath to ReportName.rdl automatically.
 -->
Another option would be to support something like xinclude or just force us to process our xml first, like
$ xmllint -noent -out RSBuild.config RSBuild.config.in
which would expand the &Reports; entity for me. But if you just enable DTD processing in MS’s parser, that’d be more convenient.

Right now, trying to use the entity reference results in:
[Settings]: Loading RSBuild settings from 'c:\Users\binki\AeroFS\repos_realwin\Main\Code\Database\Report Project\RSBuild.config'
[Settings]: For security reasons DTD is prohibited in this XML document. To enable DTD processing set the ProhibitDtd property on XmlReaderSettings to false and pass the settings into XmlReader.Create method.

Unhandled Exception: System.Xml.XmlException: For security reasons DTD is prohibited in this XML document. To enable DTD processing set the ProhibitDtd property on XmlReaderSettings to false and pass the settings into XmlReader.Create method.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseDoctypeDecl()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XsdValidatingReader.Read()
   at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
   at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at RSBuild.Settings.LoadSettings(String settingsFilePath) in c:\Users\binki\AeroFS\repos_realwin\rsbuild\trunk\src\RSBuild.Core\Settings.cs:line 131
   at RSBuild.Settings..ctor(String settingsFilePath) in c:\Users\binki\AeroFS\repos_realwin\rsbuild\trunk\src\RSBuild.Core\Settings.cs:line 80
   at RSBuild.Settings.Load(String settingsFilePath) in c:\Users\binki\AeroFS\repos_realwin\rsbuild\trunk\src\RSBuild.Core\Settings.cs:line 48
   at RSBuild.Dispatcher.Run() in c:\Users\binki\AeroFS\repos_realwin\rsbuild\trunk\src\RSBuild.Core\Dispatcher.cs:line 28
   at RSBuild.AppEntry.Main(String[] args)
Signal 79
The attached one-liner patch enables DTD processing, making this work. RSBuild.config is not a security issue because the person/script running RSBuild fully trusts RSBuild.config.

This is against r99885 trunk.

file attachments

comments

binki wrote Oct 16, 2015 at 5:52 PM

Well, I guess I can get away without this by preprocessing my input XML with XSLT. Just, it’d be nice if RSBuild could permit the macroish features built into XML to run, then I wouldn’t have to ;-).