Deserializing OPS XML output to Csharp class objects

This space is made available to users of Open Patent Services (OPS) web-service and now also to users of EPO’s raw data subscription products such as 14.7 DOCDB - worldwide bibliographic master database, 14.11 Worldwide legal status (INPADOC), 14.12 EP full text in XML, 14.1 EBD and more.

Users can ask each other questions, exchange experiences and solutions, post ideas. The moderator will use this space to announce changes or other relevant information.
Post Reply

Mike_k43
Posts: 8
Joined: Fri Jan 06, 2017 1:34 pm

Deserializing OPS XML output to Csharp class objects

Post by Mike_k43 » 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


OPS support
Posts: 788
Joined: Thu Feb 22, 2007 5:32 pm

Re: Deserializing OPS XML output to Csharp class objects

Post by OPS support » Tue Jan 10, 2017 9:27 am

Hi,

We spoke to the IT team in charge of OPS and they have assure us that the documentation is 100% correct and there the version online needs no updates.

As we are not in a position to assist you with such very specific tecnical requests we ask other forum users to help you further or assist with giving advice what is the best way to use our web service applications.

Regards,
OPS support


OPS support
Posts: 788
Joined: Thu Feb 22, 2007 5:32 pm

Re: Deserializing OPS XML output to Csharp class objects

Post by OPS support » Wed Jun 14, 2017 1:46 pm

An OPS user suggests the following work-around for this issue:

To be able to deserialize the response from the service correctly, manually add the following additional values to the countryCode enumeration in the code generated from the xsd: XN, AA, XP, RD, EX, TA.

Kind regards,
OPS support


hammarnet
Posts: 1
Joined: Mon Jun 26, 2017 2:59 pm

Re: Deserializing OPS XML output to Csharp class objects

Post by hammarnet » Mon Jun 26, 2017 3:03 pm

I´m facing the same problem, and the solution above doesn´t resolve it for me. Anyone having success with this?


Mike_k43
Posts: 8
Joined: Fri Jan 06, 2017 1:34 pm

Re: Deserializing OPS XML output to Csharp class objects

Post by Mike_k43 » Sat Jul 15, 2017 7:23 am

Here is now what I have found out after literally days of work. In order to obtain a csharp code file from the provided XSD files, proceed as follows:

1) Copy the files ops.xsd, exchange-documents.xsd, fulltext-documents.xsd, CPCSchema.xsd, rplus.xsd and ops_legal.xsd to a local folder.

2) Replace in the file ops.xsd the lines
<xs:import namespace="http://www.epo.org/exchange" schemaLocation="exchange-documents.xsd" />
<xs:import namespace="http://www.epo.org/fulltext" schemaLocation="fulltext-documents.xsd" />
<xs:import namespace="http://www.epo.org/cpcexport" schemaLocation="CPCSchema.xsd" />
<xs:import namespace="http://www.epo.org/register" schemaLocation="rplus.xsd" />
by the lines
<xs:import namespace="http://www.epo.org/exchange" schemaLocation="http://ops.epo.org/3.2/schema/exchange-documents.xsd" />
<xs:import namespace="http://www.epo.org/fulltext" schemaLocation="http://ops.epo.org/3.2/schema/fulltext-documents.xsd" />
<xs:import namespace="http://www.epo.org/cpcexport" schemaLocation="http://ops.epo.org/3.2/schema/CPCSchema.xsd" />
<xs:import namespace="http://www.epo.org/register" schemaLocation="http://ops.epo.org/3.2/schema/rplus.xsd" />

3) Replace in the file ops.xsd the line
<xs:include schemaLocation="ops_legal.xsd" />
by the line
<xs:import schemaLocation="http://ops.epo.org/3.2/schema/ops_legal.xsd" />

4) Delete in the file ops.xsd the line
<xs:attribute ref="xlink:href" use="optional" />

5) Copy the xsd.exe executable to the same folder as the xsd files.

6) Run in that folder the command
xsd.exe ops.xsd exchange-documents.xsd fulltext-documents.xsd CPCSchema.xsd rplus.xsd ops_legal.xsd /l:cs /c

This should give one cs code file named
ops_exchange-documents_fulltext-documents_CPCSchema_rplus_ops_legal.cs
which seems to work.

mike_k43


Post Reply