天道酬勤,学无止境

xsd.exe

Programmatically use XSD.exe tool feature (generate schema from class) through .NET Framework classes?

Question I want to generate an XML Schema based upon a class, just as you can do with the Xsd.exe tool. E.g. xsd.exe /type: typename /outputdir:c:\ assmeblyname. Is there a way to do this by using classes in the .NET Framework instead of using the standalone tool? I'm sure I've seen information about task references or similar - i.e. something programmatic - that can be used in place of some of these standalone utilities, or that some standalone utilities get their features through the FCL or a Microsoft API. Answer1 Found this which looks like it should do the trick... public static string

2021-12-01 08:21:02    分类:技术分享    .net   xsd.exe   fcl

Can't find xsd.exe in the path during MSBuild Community Tasks BeforeBuild step in Visual Studio

Question I am using MSBuild Community Tasks to run Xsd.exe as part of my build in Visual Studio as thus: <Import Project="$(SolutionDir)Common.targets" /> <PropertyGroup> <MSBuildCommunityTasksPath>$(SolutionDir)TeamBuildTypes</MSBuildCommunityTasksPath> </PropertyGroup> <Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets" /> <UsingTask TaskName="XSD" AssemblyFile="$(VCTargetsPath)$(CPPTasks)" /> <Target Name="BeforeBuild"> <!--Exec Command="'$(DevEnvDir)..\Tools\vsvars32.bat'" /--> <XSD Sources="MySchema.xsd" GenerateFromSchema="classes" Language="CS" /> </Target>

2021-11-22 15:07:27    分类:技术分享    xml   visual-studio   msbuild   xsd.exe   msbuildcommunitytasks

Tool that can combine many XSD files into one?

Question I need to create XML serializer classes for approximately 65 XSD files, for which I am using Microsoft's XSD.EXE to generate the C# code... However, I keep running into Window CMD's character limit in the resulting output file (in which XSD.EXE combines the name of every XSD included): "The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters." To make a long story short, it seems that the only way I can get all these to validate and generate together is if I can merge

2021-11-21 19:12:56    分类:技术分享    .net-3.5   xsd   xml-serialization   xsd.exe

XSD.exe and "Circular Group references"

Question I am attempting to build some classes so that I can deserialise an XML file created by a third party application. Luckily the developer of the 3rd party application included a schema file with their code so that the XML file can be understood. When I use the XSD.exe tool from Visual Studio the process fails reporting the following error "Group 'SegGroupOrSegmentGrouping' from targetNamespace='' has invalid definition: Circular group reference." Any help in how I can generate the class files in light of this error would be appreciated. A copy of the schema file can be found here

2021-11-19 15:34:08    分类:技术分享    c#   .net   schema   xsd.exe

how to ask XSD.exe to generate proper class for me, so that i can create a fine XML

Question I have created an XSD file from Visual Studio 2010, Then I use xsd /c mydemo.xsd to generate class for me, so that I can create a XML file at runtime. However, when I use that class, fill in some values, and serialize the object, the XML file does not look nice to me. Here is my XSD file Click here to see What I expected the XML file to be is Click here to see (Generated from Visual Studio "Sample XML") But when I try to serialize it, the XML file is like this CLick here to see The format is totally different e.g Expecting: <ColumnInfo> <Column Type="Type1" DisplayValue="DisplayValue1

2021-10-26 11:40:50    分类:技术分享    c#   xml-serialization   xsd   xsd.exe

How do I deserialize this simple xml config with the XmlSerializer class?

Question I have the following xml I'd like to deserialize into a class <?xml version="1.0" encoding="utf-8" ?> <root> <element1>String1</element1> <element2>String2</element2> </root> I am trying to serialize it into the following class: [XmlRoot("root")] public class root { [XmlElement("element1")] internal string element1 { get; set; } [XmlElement("element2")] internal string element2 { get; set; } } When I try deserializing it using the following code, the config object is instantiated, but the strings are null. using (TextReader reader = new StreamReader(configFile)) { XmlSerializer

2021-10-24 18:18:18    分类:技术分享    xml   xml-serialization   xsd.exe

Generating cXML classes from xsd throws error "The element 'uri:ds:Signature' is missing."

Question I'm trying to generate cXML classes for version cXML 1.2.034 as per http://cxml.org/ XSD (converted by visual studio). I converted the cXML.dtd to xsd. Then Tried running: xsd.exe cXML.xsd /c /language:CS /n:MyNamespace But it threw an error: Error: Error generating classes for schema 'cXML'. - The element 'uri:ds:Signature' is missing. Then I found this issue here: Generating C# classes from XSD which seems relevant. So I downloaded xmldsig-core-schema.xsd from http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd Then I ran xsd.exe cXML.xsd xmldsig-core-schema.xsd /c /language

2021-10-16 08:28:05    分类:技术分享    xml   xsd   dtd   xsd.exe   cxml

Deserialize XML dateTime to UTC

Question I am consuming an XML webservice with XSD elements such as: <xs:element nillable="true" type="xs:dateTime" name="ENDDATE"/> XML might look like the following: <ENDDATE>2016-08-01T18:35:49+04:00</ENDDATE> I used XSD.exe to autogenerate C# classes, when I inspect these the DateTime object will contain the time in system-local time, with Kind==Local. Is there a way I can force the DateTime instances to be in UTC time without manually hacking the auto-generated classes for every such field (there are rather a lot)? Answer1 I think that you can't tune this behavior using XSD (see here). So

2021-10-15 01:48:46    分类:技术分享    c#   .net   xsd   xsd.exe

XSD.exe - How to initialize a type created from xs:choice

Question I'm fairly new to working with XSD's and serialization de-serialization, I'm looking for some advice on how to initialise the resulting class object created from a xs:choice element in the XSD, to start here's some info on the XSD and Object class: Examples taken from a larger XSD, object class. XSD: <xs:element name="main-contact"> <xs:complexType> <xs:sequence> <xs:choice> <xs:element name="person"> <xs:complexType> <xs:group ref="person"/> </xs:complexType> </xs:element> <xs:element name="company"> <xs:complexType> <xs:group ref="company"/> </xs:complexType> </xs:element> </xs

2021-10-07 08:52:00    分类:技术分享    c#   serialization   xsd.exe

XML Serialization of the default values of optional attributes

Question I have a set of classes build using xsd.exe, and I am trying to serialise them. However, an attribute is not being included in the resulting XML. Here is part of the schema where the problem lies. <xsd:element name="Widget"> <xsd:complexType> /* sequence removed for brevity */ <xsd:attribute name="Version" type="Version" use="optional" default="1.1"/> </xsd:complexType> </xsd:element> <xsd:simpleType name="Version"> <xsd:restriction base="xsd:string"> <xsd:enumeration value="1.0"/> <xsd:enumeration value="1.1"/> </xsd:restriction> </xsd:simpleType> xsd.exe generated a property called

2021-09-29 22:12:24    分类:技术分享    c#   .net   serialization   xml-serialization   xsd.exe