Deserializing OPS XML output to Csharp class objects
Posted: Fri Jan 06, 2017 2:43 pm
I wanted to de-serialize the raw XML output from OPS to an exchangedocuments object, using the Csharp XmlSerializer.Deserialize Method. This would be very straightforward.
Unfortunately the method throws an InvalidOperationException, with the InnerException:
"{"<world-patent-data xmlns='http://ops.epo.org'> wurde nicht erwartet." }
This is indicative that said raw XML output does not correspond to the class declaration for the exchangedocuments object, as autogenerated from the EPO's "exchange-documents.xsd" file. The XmlSerializer expects the raw XML output to correspond to the class declaration.
The class declaration for the exchangedocuments object, as autogenerated from the exchange-documents.xsd file, reads as follows:
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.epo.org/exchange")]
[System.Xml.Serialization.XmlRootAttribute("exchange-documents", Namespace="http://www.epo.org/exchange", IsNullable=false)]
public class exchangedocuments {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("exchange-document")]
public exchangedocument[] exchangedocument;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public countryType country;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool countrySpecified;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("date-produced", DataType="nonNegativeInteger")]
public string dateproduced;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("date-of-exchange", DataType="nonNegativeInteger")]
public string dateofexchange;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("dtd-version")]
public string dtdversion;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string file;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("no-of-documents", DataType="integer")]
public string noofdocuments;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("originating-office")]
public countryType originatingoffice;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool originatingofficeSpecified;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string status;
}
Is there an updated version of the exchange-documents.xsd file available?
As an addendum: I think that actually the ops.xsd file should be converted to Csharp code, because it contains the definition for the wordpatentdata object and the remainder of the .xsd filed is referenced to by "include" directives. I am however not sur about that. The XSD tool (of VisualStudio 2005, framework version 2.0), when run over the ops.xsd file, generates upon validation of the file many warnings about duplicate declarations, then during conversion to code seemingly generates an error for each such warning. This file cannot be converted by the tool to code. The problem thus persists for the moment
Unfortunately the method throws an InvalidOperationException, with the InnerException:
"{"<world-patent-data xmlns='http://ops.epo.org'> wurde nicht erwartet." }
This is indicative that said raw XML output does not correspond to the class declaration for the exchangedocuments object, as autogenerated from the EPO's "exchange-documents.xsd" file. The XmlSerializer expects the raw XML output to correspond to the class declaration.
The class declaration for the exchangedocuments object, as autogenerated from the exchange-documents.xsd file, reads as follows:
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.epo.org/exchange")]
[System.Xml.Serialization.XmlRootAttribute("exchange-documents", Namespace="http://www.epo.org/exchange", IsNullable=false)]
public class exchangedocuments {
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("exchange-document")]
public exchangedocument[] exchangedocument;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public countryType country;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool countrySpecified;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("date-produced", DataType="nonNegativeInteger")]
public string dateproduced;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("date-of-exchange", DataType="nonNegativeInteger")]
public string dateofexchange;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("dtd-version")]
public string dtdversion;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string file;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("no-of-documents", DataType="integer")]
public string noofdocuments;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute("originating-office")]
public countryType originatingoffice;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public bool originatingofficeSpecified;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string status;
}
Is there an updated version of the exchange-documents.xsd file available?
As an addendum: I think that actually the ops.xsd file should be converted to Csharp code, because it contains the definition for the wordpatentdata object and the remainder of the .xsd filed is referenced to by "include" directives. I am however not sur about that. The XSD tool (of VisualStudio 2005, framework version 2.0), when run over the ops.xsd file, generates upon validation of the file many warnings about duplicate declarations, then during conversion to code seemingly generates an error for each such warning. This file cannot be converted by the tool to code. The problem thus persists for the moment