开发者

xsd2code multiple xsd file create duplicate sub classes

I am using xsd2code to generate classes from the xsd schema provided by the star standard.

I did try to use xsd.exe to generate the classes, but it did not do a good job.

When I generate the class from 'ProcessCreditApplication.xsd' it generates a single file with all the needed classes. Everything works fine at this point.

When I generate another xsd, ConfirmBOD.xsd I get ambiguity errors, as both files contain the same base classes.

For example both files generate a 'Description' class. Because both file are in the same namespace there is ambiguity between the two classes in the same namespace.

Is there a way to generate classes from multiple xsd such that sub classes are not duplicated?

My only thought to get around this problem is to but each generated file in its own namespace. This is not ideal but works.

I would like to use xsd.exe as it seems to take multipliable files, but the 开发者_开发百科code it generates does not work for my needs.

Update I tried Linq to xsd, and it did not work. It complained that same types have 'already been declared'.

For reference: here is where I am getting the schema's:

http://www.starstandard.org/SIGXMLSTAR4/XMLSchemas http://www.starstandard.org/uploads/SIGXMLSTAR4/STARSchemaRepository_Rev444.zip


I've had issues using xsd.exe as well. I've had success using Microsoft's LinqToXsd project to generate C# code from XSD files. I haven't tried it with extremely complex XSD files, but you may give it a shot.

The LinqToXsd project is open source on CodePlex

The command line usage syntax is:

LinqToXsd <schemaFile> [one or more schema files] [/fileName:<csFileName>.cs] [/lib:<assemblyName>] [/config:<configFileName>.xml] [/enableServiceReference] [/nameMangler2]


I think there are really only two choices:

  1. Use a different namespace for each generated file.
  2. Give all your types unique names (probably not an option for your situation).

If you think about it, each generated file is actually a bunch of classes, not just one class, so it actually makes sense to give each its own namespace.


You can use an additional XML file for LinqToXsd namespace configuration.

Example by mogness, http://blog.mogness.com/?p=36

<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="http://www.microsoft.com/xml/schema/linq">
  <Namespaces>
    <Namespace Schema="http://www.Schema1" Clr="My.Schema1"/>
    <Namespace Schema="http://www.Schema2" Clr="My.Schema2"/>
    <Namespace Schema="" Clr="My"/>
  </Namespaces>
</Configuration>

Additional details for smooth integration with Visual Studio, by ehosca, http://linqtoxsd.codeplex.com/discussions/238570#PostDetailsCell_591728

create an XML file in the same solution as your XSD and ( call it linq2xsdconfig.xml)

Select the build action of the linq2xsdconfig.xml to : LinqToXsdConfiguration

You can also pass the same XML file to LinqToXsd.exe, as noted by @bporter.

LinqToXsd <schemaFile> /config:linq2xsdconfig.xml


There is now "Exclude included types" checkbox, so should be no problem anymore.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜