growled on Friday, February 10, 2006 9:41:13 PM (Pacific Standard Time, UTC-08:00)
barked at coding

Xsd.exe

This is a cool little utility that comes with Visual Studio .NET 2003 and makes it very simple to create XML schemas. All you have to do is create what you want your XML file to look like and then run "xsd filename.xml". It will then generate a schema file (.xsd) for you.

For example, it will take this XML:

<ListToSubmit>
    
<ListJobId />
    <
IPList>
        
<IP>
            
<Hostname />
            <
Domain />
            <
OperatingSystem />
            <
DeviceType />
            <
Pingable />
        </
IP>
    
</IPList>
    
<ExceptionList>
        
<IPNumber />
    </
ExceptionList>
</ListToSubmit>

Colorized by: CarlosAg.CodeColorizer

And turn it into this Schema Defintion:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  
<xs:element name="ListToSubmit">
    
<xs:complexType>
      
<xs:sequence>
        
<xs:element name="ListJobId" type="xs:string" minOccurs="0" />
        <
xs:element name="IPList" minOccurs="0" maxOccurs="unbounded">
          
<xs:complexType>
            
<xs:sequence>
              
<xs:element name="IP" minOccurs="0" maxOccurs="unbounded">
                
<xs:complexType>
                  
<xs:sequence>
                    
<xs:element name="Hostname" type="xs:string" minOccurs="0" />
                    <
xs:element name="Domain" type="xs:string" minOccurs="0" />
                    <
xs:element name="OperatingSystem" type="xs:string" minOccurs="0" />
                    <
xs:element name="DeviceType" type="xs:string" minOccurs="0" />
                    <
xs:element name="Pingable" type="xs:string" minOccurs="0" />
                  </
xs:sequence>
                
</xs:complexType>
              
</xs:element>
            
</xs:sequence>
          
</xs:complexType>
        
</xs:element>
        
<xs:element name="ExceptionList" minOccurs="0" maxOccurs="unbounded">
          
<xs:complexType>
            
<xs:sequence>
              
<xs:element name="IPNumber" type="xs:string" minOccurs="0" />
            </
xs:sequence>
          
</xs:complexType>
        
</xs:element>
      
</xs:sequence>
    
</xs:complexType>
  
</xs:element>
  
<xs:element name="NewDataSet" msdata:IsDataSet="true">
    
<xs:complexType>
      
<xs:choice maxOccurs="unbounded">
        
<xs:element ref="ListToSubmit" />
      </
xs:choice>
    
</xs:complexType>
  
</xs:element>
</xs:schema>

Colorized by: CarlosAg.CodeColorizer

You can then customize the schema with your namespace, element types, maxOccurs, etc. Easy as pie. And this definitely beats doing it manually! ;-)

~tod

Comments are closed.