. Create a dummy xml
. use xsd.exe to create the .xsd file
. use Visual studio to tweak the XSD for a) cardinality and b) data types

Caveat: There may alternate ways to generate the complex types in the XSD than the default approach that XSD takes. Nevertheless it should work.

A detailed example

Step1

Based on the EDI document create a dummy xml document. Here is an example. Don't worry about entering repeat elements as you need to tweak the resulting XSD anyway and you can do it at that time


(shipmentStatus)
	(!--1 to many details --)
	(hdr)
		(hdr-ref)
			(refnum /)
			(shipment-num /)
			(scac /)
		(/hdr-ref)
		(RefNumber)
			(number /)
			(qualifier /)
			(description /)
		(/RefNumber)
		(Remarks)
			(Remarks1 /)
			(Remarks2 /)
		(/Remarks)
		(stop)
			(entity-code /)
			(entity-name /)
			(code-qualifier /)
		(/stop)
		(carrier-details)
			(scac /)
			(routing-code /)
			(city-name /)
			(transportation-method /)
			(state /)
		(/carrier-details)
	(/hdr)
	(!--1 to many details --)
	(detail)
		(stop-detail)
			(status-code /)
			(reason-code /)
			(app-status-code /)
			(app-reason-code /)
			(status-date /)
			(status-time /)
			(time-code /)
			(city-name /)
			(state /)
			(country-code /)
			(longitude /)
			(latitude /)
			(longitude-direction /)
			(latitude-direction /)
			(scac /)
			(eq-number /)
			(eq-description-code /)
			(eq-check-digit /)
		(/stop-detail)
		(det-ref-number)
			(number /)
			(qualifier /)
			(description /)
		(/det-ref-number)
		(variance)
			(variance-code /)
			(packaging-code /)
			(variance-quantity /)
		(/variance)
		(handling)
			(handling-code /)
			(service-code /)
			(description /)
		(/handling)
		(measures)
			(wt-qualifier /)
			(wt-code /)
			(weight /)
			(prmpk-quantity /)
			(secpk-quantity /)
			(vol-qualifier /)
			(volume /)
		(/measures)
	(/detail)
	(trailer)
		(ref-number /)
		(ship-number /)
		(scac /)
	(/trailer)
(/shipmentStatus)

Step2

Run xsd as follows


xsd.exe test.xml

This will generate a test.xsd

Step3

This will generate an xsd as follows


(?xml version="1.0" encoding="utf-8"?)
(xs:schema id="shipmentStatus" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata")
  (xs:element name="shipmentStatus" msdata:IsDataSet="true")
    (xs:complexType)
      (xs:choice maxOccurs="unbounded")
        (xs:element name="hdr")
          (xs:complexType)
            (xs:sequence)
              (xs:element name="hdr-ref" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="refnum" type="xs:string" minOccurs="0" /)
                    (xs:element name="shipment-num" type="xs:string" minOccurs="0" /)
                    (xs:element name="scac" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
              (xs:element name="RefNumber" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="number" type="xs:string" minOccurs="0" /)
                    (xs:element name="qualifier" type="xs:string" minOccurs="0" /)
                    (xs:element name="description" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
              (xs:element name="Remarks" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="Remarks1" type="xs:string" minOccurs="0" /)
                    (xs:element name="Remarks2" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
              (xs:element name="stop" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="entity-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="entity-name" type="xs:string" minOccurs="0" /)
                    (xs:element name="code-qualifier" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
              (xs:element name="carrier-details" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="scac" type="xs:string" minOccurs="0" /)
                    (xs:element name="routing-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="city-name" type="xs:string" minOccurs="0" /)
                    (xs:element name="transportation-method" type="xs:string" minOccurs="0" /)
                    (xs:element name="state" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
            (/xs:sequence)
          (/xs:complexType)
        (/xs:element)
        (xs:element name="detail")
          (xs:complexType)
            (xs:sequence)
              (xs:element name="stop-detail" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="status-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="reason-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="app-status-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="app-reason-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="status-date" type="xs:string" minOccurs="0" /)
                    (xs:element name="status-time" type="xs:string" minOccurs="0" /)
                    (xs:element name="time-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="city-name" type="xs:string" minOccurs="0" /)
                    (xs:element name="state" type="xs:string" minOccurs="0" /)
                    (xs:element name="country-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="longitude" type="xs:string" minOccurs="0" /)
                    (xs:element name="latitude" type="xs:string" minOccurs="0" /)
                    (xs:element name="longitude-direction" type="xs:string" minOccurs="0" /)
                    (xs:element name="latitude-direction" type="xs:string" minOccurs="0" /)
                    (xs:element name="scac" type="xs:string" minOccurs="0" /)
                    (xs:element name="eq-number" type="xs:string" minOccurs="0" /)
                    (xs:element name="eq-description-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="eq-check-digit" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
              (xs:element name="det-ref-number" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="number" type="xs:string" minOccurs="0" /)
                    (xs:element name="qualifier" type="xs:string" minOccurs="0" /)
                    (xs:element name="description" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
              (xs:element name="variance" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="variance-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="packaging-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="variance-quantity" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
              (xs:element name="handling" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="handling-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="service-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="description" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
              (xs:element name="measures" minOccurs="0" maxOccurs="unbounded")
                (xs:complexType)
                  (xs:sequence)
                    (xs:element name="wt-qualifier" type="xs:string" minOccurs="0" /)
                    (xs:element name="wt-code" type="xs:string" minOccurs="0" /)
                    (xs:element name="weight" type="xs:string" minOccurs="0" /)
                    (xs:element name="prmpk-quantity" type="xs:string" minOccurs="0" /)
                    (xs:element name="secpk-quantity" type="xs:string" minOccurs="0" /)
                    (xs:element name="vol-qualifier" type="xs:string" minOccurs="0" /)
                    (xs:element name="volume" type="xs:string" minOccurs="0" /)
                  (/xs:sequence)
                (/xs:complexType)
              (/xs:element)
            (/xs:sequence)
          (/xs:complexType)
        (/xs:element)
        (xs:element name="trailer")
          (xs:complexType)
            (xs:sequence)
              (xs:element name="ref-number" type="xs:string" minOccurs="0" /)
              (xs:element name="ship-number" type="xs:string" minOccurs="0" /)
              (xs:element name="scac" type="xs:string" minOccurs="0" /)
            (/xs:sequence)
          (/xs:complexType)
        (/xs:element)
      (/xs:choice)
    (/xs:complexType)
  (/xs:element)
(/xs:schema)