locked
Using C# Class Generated using xsd.exe RRS feed

  • Question

  • Dear All,

    I am new to serialisation, and indeed XML. I have been provided an .xsd (XML Schema file) and I am required to provide an .xml data file which conforms to this schema. The data I have is stored and acessed via SQL Server, so I wish to transfer/copy my data from an SQL Server database (.mdf file) to an .xml file according to the provided schema. I wish to do this in C# and I have so far managed to create a C# class from the .xsd schema using the xsd.exe tool. The issue is that I have no idea how to use the created C# class, can anyone point me to an example of this? I know serialisation comes in to this but I am unsure as to how to access/adopt the schema's original structure?

    Any help would be most appreciated.

    Camus


    "Everything should be made as simple as possible, but not simpler" - Einstein
    Tuesday, June 14, 2011 1:45 PM

Answers

  • Hi Camuvingian,

    Welcome to the MSDN Forum.

    I'd like to suggest that you first check out thus two official knowledge bases from MSDN Library:Serialize Method (XmlWriter, Object) & Deserialize Method (XmlReader). You may find that the main parts of them come down to the two samples provided. After reading them, I think you'll have a unambiguous understanding of their mechanism, that is: No matter serializing or deserializing, the data are transformed from the original format to the target format:
    Serializing: Object => XML.
    Deserializing: XML => Object.

    So these are the general purposes of many situations. But which role does the CS class generated by the XSD.exe tool act? That is the Type in the follow line, which controls the format of serializing and deserializing:
        // Create an instance of the XmlSerializer specifying type and namespace.
        XmlSerializer serializer = new
        XmlSerializer(typeof(OrderedItem));
    

    You can change the OrderedItem to your own class generated by the XSD.exe tool.

    >> I have created the "XmlSchema.cs" class from xsd.exe using a supplied schema file "XmlSchema.xsd". What do I do with the class now? How do I initiate the data using that class? How do I transform my .mdf data ready to be serialised into XML using the generated .cs file?
    For this purpose, you should follow the following steps:
    1> Create a instance of your class.
    2> Populate the class with data got from the database, the data may be first stored in a DataSet object.
    3> Serialize the instance into an XML data file, through the way indicated in the sample of the official doc, like this:
          OrderedItem i = new OrderedItem();
          //Populate the instance with the data got from the database.
          //...
    
          XmlSerializer serializer = new XmlSerializer(typeof(OrderedItem));
    
          // Create an XmlTextWriter using a FileStream.
          using (Stream stream = new FileStream(filename, FileMode.Create))
          {
            XmlWriter writer =
            new XmlTextWriter(stream, Encoding.Unicode);
            // Serialize using the XmlTextWriter.
            serializer.Serialize(writer, i);
            writer.Close();
          }
    

    Theoretically this method is definitely right, while it is not suggested, because there is a much easier way: Populate a DataSet object with the data got from the database, directly use the DataSet.WriteXml(String FileName) Method to write the data into an XML file.

    While it is suggested to deserialize the data from the XML file into an object instance, this is really efficient.

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Camuvingian Wednesday, June 15, 2011 8:46 AM
    Wednesday, June 15, 2011 8:40 AM
    Moderator
  • Hi Camuvingian,

    You are welcome.

    >> I would happly make this process easier by doing as you suggest, but the whole point is to be able to write the XML file according to the schema (.xsd file), in which case the above "direct" method will not work - is that right or am I missing something?

    Actually this "direct" method really does follow the structure which is defined by the schema(.xsd file). If you are still wondering about this, just open the xml data file generated by the DataSet.WriteXml(String FileName) Method, what do you see in the namespace declaration within the root node? My schema is NorthwindDataSet.xsd, so I see this:
     
         <NorthwindDataSet xmlns="http://tempuri.org/NorthwindDataSet.xsd">

    So you may wonder when to use the CS class generated by the XSD.exe tool now. When data objects like DataSet are not used, when the data are not fetched from the database or some other data holders but are created manually, which is not appropriate to be used to populate a data object, etc. In thus cases, just instantiate a instance which contains the required data, and then serialize the instance to an XML file.

    For converting the XML data to a class instance which holds the data, using the CS class generated by the XSD.exe tool collaborating with the XmlSerializer.Deserialize Method (XmlReader) to deserialize is the only and desirable way. In this case, the effect of the CS class generated by the XSD.exe tool is irreplaceable. That is why I said "While it is suggested to deserialize the data from the XML file into an object instance, this is really efficient".
    You can check out this article for more details:
    http://www.codingday.com/xml-c-class-generator-for-c-using-xsd-for-deserialization/.
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    -------------------------------------------------
    This response contains links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thursday, June 16, 2011 1:40 AM
    Moderator

All replies

  • Open your Visual Studio Command prompt and type xsd this will give your information on how to use xsd tool to generate the class.

    xsd "xsdFile.xsd" /language:cs /out:"outputpath"

    This will generate a .cs file which you can use to create objects and connect to the service.

     


    Regards, Krishnakant This answers, please mark as answered, if this helps please mark as helpful.
    Tuesday, June 14, 2011 2:34 PM
  •  

    Dear Krishnakant,

    As I have said in my post, I have created the class this is not the issue. The problem is how to use the class to create an .xml file from SQL Server data.

    Cheers,

    Camus


    "Everything should be made as simple as possible, but not simpler" - Einstein
    Tuesday, June 14, 2011 2:38 PM
  • Okay....

    I assume you know how to read data form SQL Server.

    Hence you will also be able to create object and assign appropriate data to appropriate properties of the objects...

    now the point you need to serialize the object here is the code to do that.

    Note these are extension methods and you can use them like

    Class object = new Class();

    string xml = object.TOXML();

    and then do what you need to do with your XML...

     

     

    using System;
    using System.IO;
    using System.Reflection;
    using System.Text;
    using System.Xml;
    using System.Xml.Serialization;
    
    namespace Utilities
    {
    	public static class SerializationHelper
    	{
    		#region Private Methods
    
    		private static string ByteArrayToString(byte[] characters)
    		{
    			string constructedString = Encoding.UTF8.GetString(characters);
    			return (constructedString);
    		}
    
    		private static Byte[] StringToByteArray(string pXmlString)
    		{
    			byte[] byteArray = Encoding.UTF8.GetBytes(pXmlString);
    			return byteArray;
    		}
    
    		private static string ToXML(this object pObject, bool replaceNewLineChar, bool returnEmptyIfNullOrError)
    		{
    			try
    			{
    				const string NEWLINECHAR = "\r\n";
    				if (pObject != null)
    				{
    					string xmlizedString = null;
    					MemoryStream memoryStream = new MemoryStream();
    					XmlSerializer xs = new XmlSerializer(pObject.GetType());
    					XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
    
    					xs.Serialize(xmlTextWriter, pObject);
    					memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
    					xmlizedString = ByteArrayToString(memoryStream.ToArray());
    					if (replaceNewLineChar)
    					{
    						return xmlizedString.ToString().Replace(NEWLINECHAR, string.Empty);
    					}
    					else
    					{
    						return xmlizedString.ToString();
    					}
    				}
    				else
    				{
    					if (returnEmptyIfNullOrError)
    					{
    						return string.Empty;
    					}
    					else
    					{
    						return null;
    					}
    				}
    			}
    			catch(Exception ex)
    			{
    				if (returnEmptyIfNullOrError)
    				{
    					return ex.Message;
    				}
    				else
    				{
    					return null;
    				}
    			}
    		}
    
    		private static string ToXML(this object pObject, bool replaceNewLineChar)
    		{
    			return ToXML(pObject, true, true);
    		}
    
    		private static string ToXML(this object instance, XmlSerializerNamespaces ns)
    		{
    			if (instance != null)
    			{
    				XmlSerializer serializer = new XmlSerializer(instance.GetType());
    				StringWriter writer = new StringWriter();
    				serializer.Serialize(writer, instance, ns);
    				return writer.ToString();
    			}
    			else
    			{
    				return string.Empty;
    			}
    		}
    
    		#endregion Private Methods
    
    		#region Public Methods
    
    		public static T ConvertTo<T>(this string pXmlizedString)
    		{
    			XmlSerializer xs = new XmlSerializer(typeof(T));
    			MemoryStream memoryStream = new MemoryStream(StringToByteArray(pXmlizedString));
    			XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8);
    			return (T)xs.Deserialize(memoryStream);
    		}
    
    		public static string ToXML(this object pObject)
    		{
    			return ToXML(pObject, false, true);
    		}
    
    		#endregion Public Methods
    	}
    }
    

     

    Hope this is what you are expecting...

    To use this code you need to create a file may be like SerializationHelper.cs

    then include it in your code file.i.e.

    Using Utilities;

    and then

    Class object = new Class();

    string xml = object.TOXML();

    you get the XML to work with..

     

    you can also refer to a POST on the same issue


    Regards, Krishnakant This answers, please mark as answered, if this helps please mark as helpful.
    Tuesday, June 14, 2011 2:45 PM
  •  

    Dear Krishnakant,

    Although your post is somewhat helpful, serialisation is not really the issue here. I have books on serialisation so will write my own methods/classes to deal with this process. The major problem is now to use the class generated by xsd.exe. The .xsd I have is quite complex in terms of hierarchy, which produces a fairly verbose corresponding .cs file. Ok, so here is exactly what I want to know:

    I have created the "XmlSchema.cs" class from xsd.exe using a supplied schema file "XmlSchema.xsd". What do I do with the class now? How do I initiate the data using that class? How do I transform my .mdf data ready to be serialised into XML using the generated .cs file?

    Thanks very much for your time,

    Camus 

     


    "Everything should be made as simple as possible, but not simpler" - Einstein

    Tuesday, June 14, 2011 3:09 PM
  • Well in that case you need to map your class with your tables in your .mdf. Write SQL to get data from the mdf and then map those classes to the results that you would get from the SQLs (table)...

    Ideally if your class / xsd is made keeping in mind your data structure this should not be difficult.

    Unfortunately we cannot should you the exact code as your .cs file and mdf structure is not know!


    Regards, Krishnakant This answers, please mark as answered, if this helps please mark as helpful.
    Tuesday, June 14, 2011 3:19 PM
  • Hi Camuvingian,

    Welcome to the MSDN Forum.

    I'd like to suggest that you first check out thus two official knowledge bases from MSDN Library:Serialize Method (XmlWriter, Object) & Deserialize Method (XmlReader). You may find that the main parts of them come down to the two samples provided. After reading them, I think you'll have a unambiguous understanding of their mechanism, that is: No matter serializing or deserializing, the data are transformed from the original format to the target format:
    Serializing: Object => XML.
    Deserializing: XML => Object.

    So these are the general purposes of many situations. But which role does the CS class generated by the XSD.exe tool act? That is the Type in the follow line, which controls the format of serializing and deserializing:
        // Create an instance of the XmlSerializer specifying type and namespace.
        XmlSerializer serializer = new
        XmlSerializer(typeof(OrderedItem));
    

    You can change the OrderedItem to your own class generated by the XSD.exe tool.

    >> I have created the "XmlSchema.cs" class from xsd.exe using a supplied schema file "XmlSchema.xsd". What do I do with the class now? How do I initiate the data using that class? How do I transform my .mdf data ready to be serialised into XML using the generated .cs file?
    For this purpose, you should follow the following steps:
    1> Create a instance of your class.
    2> Populate the class with data got from the database, the data may be first stored in a DataSet object.
    3> Serialize the instance into an XML data file, through the way indicated in the sample of the official doc, like this:
          OrderedItem i = new OrderedItem();
          //Populate the instance with the data got from the database.
          //...
    
          XmlSerializer serializer = new XmlSerializer(typeof(OrderedItem));
    
          // Create an XmlTextWriter using a FileStream.
          using (Stream stream = new FileStream(filename, FileMode.Create))
          {
            XmlWriter writer =
            new XmlTextWriter(stream, Encoding.Unicode);
            // Serialize using the XmlTextWriter.
            serializer.Serialize(writer, i);
            writer.Close();
          }
    

    Theoretically this method is definitely right, while it is not suggested, because there is a much easier way: Populate a DataSet object with the data got from the database, directly use the DataSet.WriteXml(String FileName) Method to write the data into an XML file.

    While it is suggested to deserialize the data from the XML file into an object instance, this is really efficient.

    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Camuvingian Wednesday, June 15, 2011 8:46 AM
    Wednesday, June 15, 2011 8:40 AM
    Moderator
  •  

    Hi Leo,

    Thank you very much for such a clear and concise answer!

    One more minor question though. You state "Theoretically this method is definitely right, while it is not suggested, because there is a much easier way: Populate a DataSet object with the data got from the database, directly use theDataSet.WriteXml(String FileName) Method to write the data into an XML file.". I would happly make this process easier by doing as you suggest, but the whole point is to be able to write the XML file according to the schema (.xsd file), in which case the above "direct" method will not work - is that right or am I missing something?

    Thanks very much for your time in this matter, it is most appreciated.

    Camus


    "Everything should be made as simple as possible, but not simpler" - Einstein
    Wednesday, June 15, 2011 8:50 AM
  • Hi Camuvingian,

    You are welcome.

    >> I would happly make this process easier by doing as you suggest, but the whole point is to be able to write the XML file according to the schema (.xsd file), in which case the above "direct" method will not work - is that right or am I missing something?

    Actually this "direct" method really does follow the structure which is defined by the schema(.xsd file). If you are still wondering about this, just open the xml data file generated by the DataSet.WriteXml(String FileName) Method, what do you see in the namespace declaration within the root node? My schema is NorthwindDataSet.xsd, so I see this:
     
         <NorthwindDataSet xmlns="http://tempuri.org/NorthwindDataSet.xsd">

    So you may wonder when to use the CS class generated by the XSD.exe tool now. When data objects like DataSet are not used, when the data are not fetched from the database or some other data holders but are created manually, which is not appropriate to be used to populate a data object, etc. In thus cases, just instantiate a instance which contains the required data, and then serialize the instance to an XML file.

    For converting the XML data to a class instance which holds the data, using the CS class generated by the XSD.exe tool collaborating with the XmlSerializer.Deserialize Method (XmlReader) to deserialize is the only and desirable way. In this case, the effect of the CS class generated by the XSD.exe tool is irreplaceable. That is why I said "While it is suggested to deserialize the data from the XML file into an object instance, this is really efficient".
    You can check out this article for more details:
    http://www.codingday.com/xml-c-class-generator-for-c-using-xsd-for-deserialization/.
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    -------------------------------------------------
    This response contains links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.

    Thursday, June 16, 2011 1:40 AM
    Moderator
  •  

    Hi Leo,

    I have got the XML file production working perfectly using the following method:

    1. Generate the .cs classes file using the xsd.exe tool.

    2. Query the relevant database to obtain the data in the form of multiple DataSets.

    3. Write this data to the classes generated by xsd.exe, eventually as a single object ("message").

    4. Serialise that object to a .xml file as follows:

    XmlWriter writer; // = new XmlTextWriter(stream, Encoding.Unicode);
    XmlSerializer serializer = new XmlSerializer(typeof(message));
    XmlWriterSettings XmlSettings = new XmlWriterSettings();
    XmlSettings.Indent = true; XmlSettings.NewLineOnAttributes = true;
    writer = XmlWriter.Create("TestTestTest.xml", XmlSettings); // writer, XmlSettings);
    serializer.Serialize(writer, VcdMsg);
    writer.Close();
    

    this produced the .xml file in exactly the required format.

    Could you please clarify your last post as it is not making too much sense to me, as I am new to this stuff. Are you saying that I do not have to use the classes structure generated by xsd.exe to get my structured .xml file? The issue with using the DataSet.WriteXml(string FileName) method is that I do not have a sinlge DataSet, as the structured data I wish to write to .xml file is contained in two seperate tables. Moreover, from the above posts I do not see how to include the schema format information into the .xml writing process?

    If you could clarify these points it would be most appreciated.

    All the best,

    Camus

     


    "Everything should be made as simple as possible, but not simpler" - Einstein
    Thursday, June 16, 2011 9:18 AM
  • >> I have got the XML file production working perfectly using the following method:
    I am glad to hear that.

    >> Are you saying that I do not have to use the classes structure generated by xsd.exe to get my structured .xml file? The issue with using the DataSet.WriteXml(string FileName) method is that I do not have a sinlge DataSet, as the structured data I wish to write to .xml file is contained in two seperate tables.
    2. Query the relevant database to obtain the data in the form of multiple DataSets.
    If I have not got it wrong, you've used two DataSet objects to store the data fetched from two database tables. Actually you can put the data fetched from the two tables in one DataSet, please check out this official knowledge base: Populating a DataSet from a DataAdapter. Just check these two sections: Multiple Result Sets & Populating a DataSet from Multiple DataAdapters.
    Below is a snippet got with the "multi-DataTable DataSet".WriteXml method: (I am supposing that you know what I wanna show, so no more explanation.)
    <?xml version="1.0" standalone="yes"?>
    <NorthwindDataSet xmlns="http://tempuri.org/NorthwindDataSet.xsd">
     <Customers>
      <CustomerID>ALFKI</CustomerID>
      <CompanyName>Alfreds Futterkiste</CompanyName>
      <ContactName>Maria Anders</ContactName>
      <ContactTitle>Sales Representative</ContactTitle>
      <Address>Obere Str. 57</Address>
      <City>Berlin</City>
      <PostalCode>12209</PostalCode>
      <Country>Germany</Country>
      <Phone>030-0074321</Phone>
      <Fax>030-0076545</Fax>
     </Customers>
     <Customers>
      <CustomerID>ANATR</CustomerID>
      <CompanyName>Ana Trujillo Emparedados y helados</CompanyName>
      <ContactName>Ana Trujillo</ContactName>
      <ContactTitle>Owner</ContactTitle>
      <Address>Avda. de la Constitución 2222</Address>
      <City>México D.F.</City>
      <PostalCode>05021</PostalCode>
      <Country>Mexico</Country>
      <Phone>(5) 555-4729</Phone>
      <Fax>(5) 555-3745</Fax>
     </Customers>
     <Customers>
      ...
     </Customers>
     ...
     <Orders>
      <OrderID>10248</OrderID>
      <CustomerID>VINET</CustomerID>
      <EmployeeID>5</EmployeeID>
      <OrderDate>1996-07-04T00:00:00+08:00</OrderDate>
      <RequiredDate>1996-08-01T00:00:00+08:00</RequiredDate>
      <ShippedDate>1996-07-16T00:00:00+08:00</ShippedDate>
      <ShipVia>3</ShipVia>
      <Freight>32.3800</Freight>
      <ShipName>Vins et alcools Chevalier</ShipName>
      <ShipAddress>59 rue de l'Abbaye</ShipAddress>
      <ShipCity>Reims</ShipCity>
      <ShipPostalCode>51100</ShipPostalCode>
      <ShipCountry>France</ShipCountry>
     </Orders>
     <Orders>
      <OrderID>10249</OrderID>
      <CustomerID>TOMSP</CustomerID>
      <EmployeeID>6</EmployeeID>
      <OrderDate>1996-07-05T00:00:00+08:00</OrderDate>
      <RequiredDate>1996-08-16T00:00:00+08:00</RequiredDate>
      <ShippedDate>1996-07-10T00:00:00+08:00</ShippedDate>
      <ShipVia>1</ShipVia>
      <Freight>11.6100</Freight>
      <ShipName>Toms Spezialitäten</ShipName>
      <ShipAddress>Luisenstr. 48</ShipAddress>
      <ShipCity>Münster</ShipCity>
      <ShipPostalCode>44087</ShipPostalCode>
      <ShipCountry>Germany</ShipCountry>
     </Orders>
     <Orders>
      ...
     </Orders>
     ...
    </NorthwindDataSet>
    

    >> Moreover, from the above posts I do not see how to include the schema format information into the .xml writing process?
    If you mean the procedure which has been performed successfully by you, the schema format info is indirectly involved in the generated CS file, and is passed to the serializing process within the following line:
    XmlSerializer serializer = new XmlSerializer(typeof(message));
    To be more visualized, just think about this: The mould generated a model, if we have only seen the model, it is not hard for us to infer what the mould looks like.

    P.S: Oh my god, this is totally an XML & Data related topic, how can I support it in the C# forum. Lol.
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, June 17, 2011 12:43 AM
    Moderator
  • Hi Camus,

    I have a similar issue that im working on right now, the part im stuck now is the step 3 of the process you have described here, could you give me a little more detailed description of this step please.

    Rean

    Monday, July 9, 2012 7:47 PM
  • You will need to buld the full class structure during step 3. So if I had

       
    class A
    {
        ...
        public List<B> listB { get; set; }
        public List<C> listC { get; set; }
        ...
    }
    
    class B
    {
        ...
        public string strB { get; set; }
        ...
    }
    
    class C
    {
        ...
        public string strC { get; set; }
        ...
    }
    
    
    A a = new A();
    B b = new B();
    C c = new C();
    a.listB = new List<B>();
    a.listC = new List<C>();
    
    foreach (string s in someStringList)
    {
        b.strB = c.strC = s;
        a.listB.Add(b);
        c.listC.Add(c);
    }
    
    
    
    

    That was building the structure, or class hierarchy. Then you serialise class A.

    I hope this helps.


    "Everything should be made as simple as possible, but not simpler" - Einstein

    Tuesday, July 10, 2012 9:38 AM
  • I know I'm tagging onto a new thread but I have a similar question on the C#usage. 

    My data is being passed to a class not coming from a database.  So I'm going to use the generated class from XSD to populate the XML and then serialize it.

    Here's the XML sample.  The Schema, and then the generated class.  My code is FIRST - my question is how to get this "hdr" item - the headers - into "items". That's my C# question.  As an aside, serialization fails because the generated class has a [] [] item in it that should be []  - I don't know why XSD does this.  See my comments in the generated class.  Look for TAH - where you see [][], I'd also like a comment on that.

    Here's my C#

                TAXPYMTHeader hdr = new TAXPYMTHeader();

                tp = null;

                Item itx = new Item();

                itx.Name = "CASHIER_INIT";

                itx.Value = "TAH";

                Item[] arr3 = new Item[] { itx };

                hdr.Item = arr3;

    // in need to get this "hdr" as one of the items in tp.items

    HOW?

              

                    XmlSerializer serx = new XmlSerializer(typeof(TAXPYMT));

                    using (TextWriter w1 = new StreamWriter("testing.xml"))

                    {

                        serx.Serialize(w1, tp);

                        w1.Close();

                    }

    The XML the XSD generated from:

     

    <?xml version="1.0" encoding="utf-8"?>
    <TAXPYMT>
      <!-- There will be only one of these. -->
      <Header>
        <Item Name="REGISTER_NO" Value=""/>
        <Item Name="CASHIER_INIT" Value=""/>
        <Date Name="EFFECTIVE_DATE" Year="" Month="" Day="" Hour="" Minute="" Second="" Millisecond=""/>
        <Date Name="BUSINESS_DATE" Year="" Month="" Day="" Hour="" Minute="" Second="" Millisecond=""/>
        <Date Name="ACTUAL_DATE" Year="" Month="" Day="" Hour="" Minute="" Second="" Millisecond=""/>
      </Header>

      <PaymentList>
        <!-- There will be one of these for each receipt number being paid. -->
        <Payment>
          <Item Name="RECEIPT_NO" Value=""/>
          <Item Name="PARID" Value=""/>
          <Item Name="TAXYEAR" Value=""/>
          <Item Name="PAYMENT_AMT" Value=""/>
          <Item Name="DISCOUNT" Value=""/>
          <Item Name="PENALTY" Value=""/>
          <Item Name="INTEREST" Value=""/>
          <Item Name="COURT_FEE" Value=""/>
          <Item Name="SHERRIF_FEE" Value=""/>
          <Item Name="COMM_FEE" Value=""/>
        </Payment>
      </PaymentList>
    </TAXPYMT>

    The XSD:

    <?xml version="1.0" encoding="utf-8"?>
    <xs:schema id="TAXPYMT" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <xs:element name="Item">
        <xs:complexType>
          <xs:attribute name="Name" type="xs:string" />
          <xs:attribute name="Value" type="xs:string" />
        </xs:complexType>
      </xs:element>
      <xs:element name="TAXPYMT" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
        <xs:complexType>
          <xs:choice minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="Item" />
            <xs:element name="Header">
              <xs:complexType>
                <xs:sequence>
                  <xs:element ref="Item" minOccurs="0" maxOccurs="unbounded" />
                  <xs:element name="Date" minOccurs="0" maxOccurs="unbounded">
                    <xs:complexType>
                      <xs:attribute name="Name" type="xs:string" />
                      <xs:attribute name="Year" type="xs:string" />
                      <xs:attribute name="Month" type="xs:string" />
                      <xs:attribute name="Day" type="xs:string" />
                      <xs:attribute name="Hour" type="xs:string" />
                      <xs:attribute name="Minute" type="xs:string" />
                      <xs:attribute name="Second" type="xs:string" />
                      <xs:attribute name="Millisecond" type="xs:string" />
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
            <xs:element name="PaymentList">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="Payment" minOccurs="0" maxOccurs="unbounded">
                    <xs:complexType>
                      <xs:sequence>
                        <xs:element ref="Item" minOccurs="0" maxOccurs="unbounded" />
                      </xs:sequence>
                    </xs:complexType>
                  </xs:element>
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:choice>
        </xs:complexType>
      </xs:element>
    </xs:schema>

    The Generated class:

                                                                                                                    

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.30319.296
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------

    using System.Xml.Serialization;

    // 
    // This source code was auto-generated by xsd, Version=4.0.30319.1.
    // 


    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
    public partial class Item {

        private string nameField;

        private string valueField;

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Name {
            get {
                return this.nameField;
            }
            set {
                this.nameField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Value {
            get {
                return this.valueField;
            }
            set {
                this.valueField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)]
    public partial class TAXPYMT {

        private object[] itemsField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Header", typeof(TAXPYMTHeader), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlElementAttribute("Item", typeof(Item))]
        [System.Xml.Serialization.XmlElementAttribute("PaymentList", typeof(TAXPYMTPaymentList), Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public object[] Items {
            get {
                return this.itemsField;
            }
            set {
                this.itemsField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    public partial class TAXPYMTHeader {

        private Item[] itemField;

        private TAXPYMTHeaderDate[] dateField;

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Item")]
        public Item[] Item {
            get {
                return this.itemField;
            }
            set {
                this.itemField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlElementAttribute("Date", Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public TAXPYMTHeaderDate[] Date {
            get {
                return this.dateField;
            }
            set {
                this.dateField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    public partial class TAXPYMTHeaderDate {

        private string nameField;

        private string yearField;

        private string monthField;

        private string dayField;

        private string hourField;

        private string minuteField;

        private string secondField;

        private string millisecondField;

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Name {
            get {
                return this.nameField;
            }
            set {
                this.nameField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Year {
            get {
                return this.yearField;
            }
            set {
                this.yearField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Month {
            get {
                return this.monthField;
            }
            set {
                this.monthField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Day {
            get {
                return this.dayField;
            }
            set {
                this.dayField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Hour {
            get {
                return this.hourField;
            }
            set {
                this.hourField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Minute {
            get {
                return this.minuteField;
            }
            set {
                this.minuteField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Second {
            get {
                return this.secondField;
            }
            set {
                this.secondField = value;
            }
        }

        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute()]
        public string Millisecond {
            get {
                return this.millisecondField;
            }
            set {
                this.millisecondField = value;
            }
        }
    }

    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
    public partial class TAXPYMTPaymentList {
    // TAH - need to change this from [][] to []
        private Item[][] paymentField;

        /// <remarks/>
        [System.Xml.Serialization.XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
        [System.Xml.Serialization.XmlArrayItemAttribute("Item", typeof(Item), IsNullable=false)]

        public Item[][] Payment {
            get {
                return this.paymentField;
            }
            set {
                this.paymentField = value;
            }
        }
    }

    Tuesday, November 27, 2012 2:25 PM