I am writing a code generation tool that will take in a XSD file generated from Visual Studio’s Data Set Generator and create a custom class for each column in each table. I already understand how to implement a IVsSingleFileGenerator to do the code generation and how to turn that single file generator in to a multi-file generator. However it seems the step I am having the most trouble with is the one that should be the most simple. I have never really worked with XML or XML-Schema before and I have no clue what is the correct way to iterate through a XSD file and read out the column names and types so I can build my code.
Any recommendation on a tutorial on how to read a XSD file? Also any recommendations on how to pull each xs:element that represents a column out and read its msprop:Generator_UserColumnName, type, and msprop:Generator_ColumnPropNameInTable properties from each element.
As btlog says, XSDs should be parsed as XML files. C# does provide functionality for this.
XPath Tutorial: http://www.w3schools.com/xpath/default.asp
XQuery Tutorial: http://www.w3schools.com/xquery/default.asp
Random C#
XmlDocumenttutorial: http://www.codeproject.com/KB/cpp/myXPath.aspxIn C#, XPath/XQuery are used via
XmlDocument. In particular, through calls likeSelectSingleNodeandSelectNodes.I recommend
XmlDocumentoverXmlTextReaderif your goal is to pull out specific chunks of data. If you prefer to read it line by line,XmlTextReaderis more appropriate.Update: For those interested in using Linq to query XML, .Net 4.0 introduced
XDocumentas an alternative toXmlDocument. See discussion at XDocument or XmlDocument.