diff --git a/README.md b/README.md index 6576021..0a0d6a3 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,8 @@ Options: --uc, --unionCommonType generate a common type for unions if possible ( default is false) + --dtd, --allowDtdParse + allow DTD parsing (default is false) ``` For use from code use the [library NuGet package](https://www.nuget.org/packages/XmlSchemaClassGenerator-beta/): diff --git a/XmlSchemaClassGenerator.Console/Program.cs b/XmlSchemaClassGenerator.Console/Program.cs index 5edc1f4..6aee3ce 100644 --- a/XmlSchemaClassGenerator.Console/Program.cs +++ b/XmlSchemaClassGenerator.Console/Program.cs @@ -66,6 +66,7 @@ static int Main(string[] args) var unionCommonType = false; var separateNamespaceHierarchy = false; var serializeEmptyCollections = false; + var allowDtdParse = false; var options = new OptionSet { { "h|help", "show this message and exit", v => showHelp = v != null }, @@ -160,6 +161,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l { "ca|commandArgs", "generate a comment with the exact command line arguments that were used to generate the source code (default is true)", v => generateCommandLineArgs = v != null }, { "uc|unionCommonType", "generate a common type for unions if possible (default is false)", v => unionCommonType = v != null }, { "ec|serializeEmptyCollections", "serialize empty collections (default is false)", v => serializeEmptyCollections = v != null }, + { "dtd|allowDtdParse", "allows dtd parse (default is false)", v => allowDtdParse = v != null }, }; var globsAndUris = options.Parse(args); @@ -248,6 +250,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l MapUnionToWidestCommonType = unionCommonType, SeparateNamespaceHierarchy = separateNamespaceHierarchy, SerializeEmptyCollections = serializeEmptyCollections, + AllowDtdParse = allowDtdParse }; if (nameSubstituteMap.Any()) diff --git a/XmlSchemaClassGenerator/Generator.cs b/XmlSchemaClassGenerator/Generator.cs index c543b1c..b9d96f5 100644 --- a/XmlSchemaClassGenerator/Generator.cs +++ b/XmlSchemaClassGenerator/Generator.cs @@ -342,6 +342,12 @@ public bool SerializeEmptyCollections set { _configuration.SerializeEmptyCollections = value; } } + public bool AllowDtdParse + { + get { return _configuration.AllowDtdParse; } + set { _configuration.AllowDtdParse = value; } + } + public bool ValidationError { get; private set; } static Generator() @@ -352,7 +358,7 @@ static Generator() public void Generate(IEnumerable files) { var set = new XmlSchemaSet(); - var settings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore }; + var settings = new XmlReaderSettings { DtdProcessing = AllowDtdParse ? DtdProcessing.Parse : DtdProcessing.Ignore }; var readers = files.Select(f => XmlReader.Create(f, settings)); ValidationError = false; diff --git a/XmlSchemaClassGenerator/GeneratorConfiguration.cs b/XmlSchemaClassGenerator/GeneratorConfiguration.cs index 6cd6692..4541bc0 100644 --- a/XmlSchemaClassGenerator/GeneratorConfiguration.cs +++ b/XmlSchemaClassGenerator/GeneratorConfiguration.cs @@ -348,5 +348,10 @@ public void WriteLog(string message) /// Determines whether empty collections should be serialized as empty elements. Default is false. /// public bool SerializeEmptyCollections { get; set; } = false; + + /// + /// Allow DTD parsing. Default is false. + /// + public bool AllowDtdParse { get; set; } = false; } }