1

I got an relative complex xml file, which i want to use as a template for my serialization and deserialization. Because it might change and grow over time, i kinda hoped that i could rely on the generation of the code via xsd.exe or svcutil.exe. But sadly iam not able to get it working easily inside Xamarin AND UWP. UWP doesnt seem to support the default xml stuff, so i had to go with svcutil.exe to get a file with DataContract-Attributes.

The problem is in Xamarin the System.Runtime.Serialization.XmlSerializableServices.AdDefaultSchema() method is missing and in UWP the whole class System.Runtime.Serialization.XmlSerializableServices is missng.

Is there a way to automatically generate the code for Xamarin and UWP? If not what would be another way to achieve a easy way of parsing an xml in both systems or should i just do it by myself?

Noires
  • 643
  • 8
  • 19
  • Why not use the [`XmlReader`](https://developer.xamarin.com/api/type/System.Xml.XmlReader)? – Demitrian Jan 10 '17 at 13:19
  • If there would be changes to the xsd, i could automaticallly generate the models again for serialization and deserialization. Else i would have to adjust the xsd, do the parsing partly myself and adjust the models aswell. Atleast thats how i see it at the moment. – Noires Jan 10 '17 at 13:21
  • Are you asking for a method to programmatically generate class model for your complex xml file in xamarin? – Grace Feng Jan 11 '17 at 06:35
  • Well actually i was looking for a way to create them both for xamarin and uwp. And actually it works with the xsd.exe. Posting answer below. – Noires Jan 11 '17 at 08:18

1 Answers1

3

I found the answer in the following post:

how can i use the file that is generated by xsd.exe in windows 10 universal app

I just use now the xsd.exe to create a *.cs file with the models, which works fine for xamarin without any extra work. For the uwp project, i just link the file now from the other project and added some "dummy" code, like in the post above.

namespace System
{
    internal class SerializableAttribute : Attribute
    {
    }
}
namespace System.ComponentModel
{
    internal class DesignerCategoryAttribute : Attribute
    {
        public DesignerCategoryAttribute(string _) { }
    }
}  

It seems to work fine that way and means if there will be changes to the xsd, i just can generate a new *.cs file with the models and dont have to handle the changes by myself.

Community
  • 1
  • 1
Noires
  • 643
  • 8
  • 19