Skip to content

Commit

Permalink
Add option to parse DTD.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroslaw-dutka committed Jun 12, 2024
1 parent 59ba300 commit 82e8849
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/):
Expand Down
3 changes: 3 additions & 0 deletions XmlSchemaClassGenerator.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 7 additions & 1 deletion XmlSchemaClassGenerator/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ public bool SerializeEmptyCollections
set { _configuration.SerializeEmptyCollections = value; }
}

public bool AllowDtdParse
{
get { return _configuration.AllowDtdParse; }
set { _configuration.AllowDtdParse = value; }

Check warning on line 348 in XmlSchemaClassGenerator/Generator.cs

View check run for this annotation

Codecov / codecov/patch

XmlSchemaClassGenerator/Generator.cs#L348

Added line #L348 was not covered by tests
}

public bool ValidationError { get; private set; }

static Generator()
Expand All @@ -352,7 +358,7 @@ static Generator()
public void Generate(IEnumerable<string> 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;
Expand Down
5 changes: 5 additions & 0 deletions XmlSchemaClassGenerator/GeneratorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,5 +348,10 @@ public void WriteLog(string message)
/// Determines whether empty collections should be serialized as empty elements. Default is false.
/// </summary>
public bool SerializeEmptyCollections { get; set; } = false;

/// <summary>
/// Allow DTD parsing. Default is false.
/// </summary>
public bool AllowDtdParse { get; set; } = false;
}
}

0 comments on commit 82e8849

Please sign in to comment.