I wa开发者_如何学编程nt to parse a complex XML schema file and export to a C# file.
Do I need take use System.XML.Schema
namespace?
You can use XSD.EXE, and the command will be something like this:
XSD.EXE your.xsd /c
The generated source has a couple of quirks:
- It generates
[SerializableAttribute]
,[XmlTypeAttribute]
,[XmlRootAttribute]
, etc., rather than[DataContract]
and[DataMember]
, which may (not) be a problem for you. - It defines child/detail structures using arrays within, rather than generic
List<T>
structures.
I usually have to tweak it fairly heavily (with a few search & replace operations), plus manually handling the lists. Regardless, it provides a good starting point.
You need to use the XSD tool. It does have limitations but it is free and likely already on your system.
If you need bigger and costlier guns I'd suggest Liquid Xml Studio or Altova.
精彩评论