Does anyone know how to generate an XSD using LinqToXml? I can’t find any examples of this anywhere. The XSD will be of the following fairly low level of complexity:
<?xml version='1.0' encoding='utf-8' ?> <!--Created with Liquid XML Studio 6.1.18.0 - FREE Community Edition (http://www.liquid-technologies.com)--> <xs:schema elementFormDefault='qualified' targetNamespace='http://schemas.xxx.yy/CRM/2009/01/DeadAnimalReport' xmlns:xs='http://www.w3.org/2001/XMLSchema'> <xs:element name='Name'> <xs:simpleType> <xs:restriction base='xs:string'> <xs:length value='35' /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name='Email' type='xs:string' /> <xs:element name='Selection'> <xs:simpleType> <xs:restriction base='xs:string'> <xs:length value='15' /> </xs:restriction> </xs:simpleType> </xs:element> <xs:element name='DeliveryDate' type='xs:date' /> </xs:schema>
The context construction of tooling to allow business analysts to generate message schemas along with some related artefacts that are out of scope of the question. The tooling XSD will be generated from CLR objects in the application’s object model.
The objects are pretty simple – a root object that contains enough information to construct the namespace along with a collection of other objects representing the elements (type, name, etc).
Thanks
Sean
Why do you want to use LINQ in this scenario? How does the source data look like?
Not much information given but anyway:
You can construct your XSD using similar code:
If you have some sort of objects, then you can use projections:
where
GetXsdDefinition is a method that takes your object as an argument and returns it’s XSD definition