XSD from XML with multiple rows

This should cover W3C XML Schema, Relax NG and DTD related problems.
tsmith
Posts: 1
Joined: Wed May 11, 2011 12:20 am

XSD from XML with multiple rows

Post by tsmith » Wed May 11, 2011 12:25 am

Is there a way to automatically generate XSD from the following XML which includes each row w/FieldName (not including the value attribute):

Code: Select all

<SelectResult>
<Document DocumentType="Orders" DocumentKey="100000" Company="Z-Corp">
<Header>
<Row FieldName="Cust No." Value=""/>
<Row FieldName="Order No." Value="2066"/>
<Row FieldName="PO Number" Value="09-31"/>
<Row FieldName="Ship To Address Line 1" Value="EMERALD POINTE GOLF CLUB"/>
<Row FieldName="Ship To Address Line 2" Value="7000 HOLIDAY ROAD"/>
<Row FieldName="Ship To Name" Value="LAKE LANIER ISLAND RESORT"/>
<Row FieldName="Ship To Country" Value="United States of America"/>
<Row FieldName="Ship To City" Value="BUFORD - LAKE LANIER ISLAND"/>
<Row FieldName="Ship To Zip" Value="30518"/>
<Row FieldName="Ship To State" Value="GA"/>
<Row FieldName="Order Total" Value="1723.78"/>
<Row FieldName="Ship Via" Value="TRUCK"/>
<Row FieldName="Terms" Value="1.5% -10 - 30"/>
<Row FieldName="Company Name" Value="Dewitt - Play"/>
<Row FieldName="Company Address 1" Value="905 South Kingshighway"/>
<Row FieldName="Company Address 2" Value=""/>
<Row FieldName="Company City" Value="Sikeston"/>
<Row FieldName="Company State" Value="MO"/>
<Row FieldName="Company Zip code" Value="63801"/>
<Row FieldName="Company Phone" Value="573-472-0048"/>
<Row FieldName="Company Contact person" Value=""/>
<Row FieldName="Ship To Contact Name" Value=""/>
<Row FieldName="Ship To Phone" Value="256-766-2091"/>
<Row FieldName="Ship Date" Value="11/19/2008"/>
</Header>
</Document>
</SelectResult>
Currently all I'm getting is the following:

Code: Select all

<xs:element name="Row">
<xs:complexType>
<xs:attribute name="FieldName" use="required"/>
<xs:attribute name="Value" use="required"/>
</xs:complexType>
</xs:element>

george
Site Admin
Posts: 2101
Joined: Thu Jan 09, 2003 2:58 pm

Re: XSD from XML with multiple rows

Post by george » Wed May 11, 2011 8:30 am

Hi,

You can pass the XML file though a simple XSLT like below that will remove the Value attribute, then pass that to the XML Schema instance generator:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<!-- copy -->
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<!-- do nothing on Row/@Value -->
<xsl:template match="Row/@Value"/>

</xsl:stylesheet>
Best Regards,
George
George Cristian Bina

Post Reply