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 bulk data subscription products such as 14. EPO worldwide bibliographic database (DOCDB), 14.11 EPO worldwide legal status database (INPADOC), 14.12 EP full text data, 14.1 EP bibliographic data (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: 52
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


EPO / OPS Support
Posts: 1298
Joined: Thu Feb 22, 2007 5:32 pm

Re: Deserializing OPS XML output to Csharp class objects

Post by EPO / 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


EPO / OPS Support
Posts: 1298
Joined: Thu Feb 22, 2007 5:32 pm

Re: Deserializing OPS XML output to Csharp class objects

Post by EPO / 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: 52
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


martienmol
Posts: 1
Joined: Thu Jun 07, 2018 11:24 am

Re: Deserializing OPS XML output to Csharp class objects

Post by martienmol » Thu Jun 07, 2018 11:27 am

I've followed the steps as described above, but still a lot of warnings and errors on ops.xsd and exchange-documents.xsd. For the other ones I'm able to generate a c-sharp class. Is there any way you can provide me the complete .cs file?


rui.180
Posts: 1
Joined: Sat Sep 08, 2018 3:53 pm

Re: Deserializing OPS XML output to Csharp class objects

Post by rui.180 » Sat Sep 08, 2018 5:15 pm

Hi,

I'd like to share some info that I figured out when deserializing ops.xsd, but first I have to explain that I'm implementing it for Java, with xjc.exe. I'm not acquainted to C#, but maybe the idea might work out fine for it too.

As I understand, the deserializing of ops.xsd demands the existence of some other files. For example, take lines 3 and 8 into consideration:

3 - xmlns:exch="http://www.epo.org/exchange" xmlns:ftxt="http://www.epo.org/fulltext"
8 - <xs:import namespace="http://www.epo.org/exchange" schemaLocation="exchange-documents.xsd" />

There we have that the namespace "exch" points to "http://www.epo.org/exchange", which ends up pointing to file "exchange-documents.xsd".

So, for the deserializing, its mandatory to have the file "exchange-documents.xsd" at the same folder of "ops.xsd".

Reading the imports, from line 8 to 14, we can see that there are some files missing at https://www.epo.org/searching-for-paten ... html#tab-3, like "ccd.xsd" and "CPCDefinitions.xsd".

Luckly, those two files can be downloaded using OPS 3.2, the same way we get "ops.xsd" from these links:
http://ops.epo.org/3.2/schema/ccd.xsd
http://ops.epo.org/3.2/schema/CPCDefinitions.xsd

Now, I'm facing a second situation while deserializing. Even tough I have all the necessary imported files, I'm having trouble when resolving the name 'cpc:class-title' as an element delcaration. Looking at the imports at line 4, "cpc" points to "CPCSchema.xsd", at line 28. Well, the name is there, but I still don't know why the it can't be resolved. But maybe, just adding those two missing imports might solve the problem with C# deserializing.


Post Reply