Dtd - moh-hassan/odata2poco GitHub Wiki

OData with DTD section

OData library do not allow xml files with DTD section to be parsed for security reasons. Example: booksDtd.xml

An error is fired like:

Error: Error in executing o2pgen Error: For security reasons DTD is prohibited in this XML document.

OData library don't enable DTD processing.

To resolve the DTD issue, we have to remove DTD section from the metadata xml file.

You can follow the next steps:

  • Save the OData metadata as xml file e.g source.xml.
  • Use the c# function RemoveDtd in My Gist to remove DTD section and generate new xml file without DTD e.g target.xml.
  public static void RemoveDtd(string inputFile, string outputFile)

You can find a demo how to use the function RemoveDtd in fiddle

The generated file without DTD sample

  • use o2pgen with the new file:
  o2pgen -r path/to/target.xml .... <other options>