The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,799 other followers

Archive for the ‘XSD’ Category

C#, XSD.exe, xsd2code and generating nullable fields+properties from an XSD with and without Specified fields/properties

Posted by jpluimers on 2016/07/27

It comes down to these cases for XML elements having maxOccurs="1" (which the default for maxOccurs):

  1. adding nillable="true" will convert from a regular type to a nullable type.
  2. adding minOccurs="0" will add boolean …Specified properties in the generated C# for each element.
  3. you can have both nillable="true" and minOccurs="0" in an element which gets you a nullable type and a …Specified property.

Note I’m not considering fixed or default here, nor attributes (that have use instead of minOccurs/maxOccurs, but do not allow for nillable) nor larger values of maxOccurs (which both xsd.exe and xsd2code regard as unbounded).

From the above, XML has a richer type system than C#, so in XML there are subtle a differences between:

  1. an explicit nil in the XML element
  2. the XML element being absent
  3. the XML element being empty.

Hopefully later more text and examples to show how to actually work with this.

Note that xsd2code.codeplex.com (unlike XmlGen#) has at least two forks at github:

From the specs:

–jeroen

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Development, Software Development, XML, XML/XSD, XSD | Leave a Comment »

XSD enumerations: key value pairs

Posted by jpluimers on 2016/04/26

One of the things you cannot do in XSD, is have string enumerations contain both a key and a value.

But there is a little appinfo trick inside annotation that you can user under some circumstances, for instance when you interpret the XSD:

appinfo is the application counterpart of documentation: both can contain any xml, but appinfo is aimed at machines, whereas documentation is aimed at humans.

–jeroen

via:

Posted in Development, Software Development, XML, XML/XSD, XSD | Leave a Comment »

XSD enumerations: restrict strings, integers, etc.

Posted by jpluimers on 2016/04/21

XSD enumerations are nice as they can be used to restrict simple XSD types to a set of values.

But they can also be hard if the set changes over time: restricting further is not possible, but extending isn’t always easy either.

Some interesting links:

–jeroen

Posted in Development, XML/XSD, XSD | Leave a Comment »

Support of import in xsd.exe – Jose Luis Calvo Salanova – Site Home – MSDN Blogs

Posted by jpluimers on 2016/04/20

I tend to forget this: xsd.exe can resolve xs:include, but not xs:import. When using xs:import it will complain about missing types.

Simple solution: reference all imported XSDs (but not included XSDs) on the same command-line:

I was trying to create a C# class with xsd.exe from an schema that imports others schemas like that xsd.exe /c schema.xsd and it fails miserably reporting an error like “The datatype ‘xxx’ is missing.”. Basically xsd.exe doesn’t resolve the schemaLocation attribute.

Dare Obasanjo’s article addresses the problem, and Scott Hanselman had the same problem -and solved it-.

The solution isn’t very nice, but at least it’s simple. You have to tell xsd.exe all the schema referenced, xsd.exe /c schema.xsd importedSchema1.xsd importedSchema2.xsd

Be aware that the C# filename is sometimes generated from all XSD filenames on the command-line (I’ve noticed this when the import is specified before the actual XSD file, if the import is at the end, the name of the import is used.

If my memory serves me right, older versions of XSD.exe could not resolve unix-style relative paths on the command-line, but newer versions do.

–jeroen

via: Support of import in xsd.exe – Jose Luis Calvo Salanova – Site Home – MSDN Blogs.

Posted in .NET, C#, Development, Software Development, XML/XSD, XSD | Leave a Comment »

existing complex XSD types: use xs:complexContent in combination with xs:extension

Posted by jpluimers on 2016/04/19

I tend to forget how to extend existing complex XSD types. It is by using xs:complexContent in combination with xs:extension: Element (complexContent).

A cool thing: xsd.exe supports this when generating .NET code (for instance C#).

More at XSD Tutorial – Part 3/5 – Extending Existing ComplexTypes and SimpleTypes.

–jeroen

Posted in Development, Software Development, XML/XSD, XSD | Leave a Comment »

 
%d bloggers like this: