XSD from XML with multiple rows

This should cover W3C XML Schema, Relax NG and DTD related problems.
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

<Document DocumentType="Orders" DocumentKey="100000" Company="Z-Corp">
<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"/>
Currently all I'm getting is the following:

Code: Select all

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

Site Admin
Posts: 2102
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


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"

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

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

Best Regards,
George Cristian Bina

Post Reply