Building XSD for secific xml

33 views Asked by At

I have been strugling with this for days. I need to build an xsd for a provided XML. But due to the way this xml is formatted, nothing seems to validate correctly. Itried most online generators, but whatever xsd they create, does not validate the schema. Could someone help me out please?

<?xml version="1.0" encoding="utf-8"?>
<MMIT_Data_Record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Supplier_Code xmlns="http://schemas.multi-mit.com/DataFormat">XXX</Supplier_Code>
    <Country_Code xmlns="http://schemas.multi-mit.com/DataFormat">UK</Country_Code>
    <Market_Code xmlns="http://schemas.multi-mit.com/DataFormat">xxxxxx</Market_Code>
    <Source_Code xmlns="http://schemas.multi-mit.com/DataFormat">xxxxxxx</Source_Code>
    <Source xmlns="http://schemas.multi-mit.com/DataFormat">XX</Source>
    <External_Reference_Id xmlns="http://schemas.multi-mit.com/DataFormat">123456789</External_Reference_Id>
    <Person_Data xmlns="http://schemas.multi-mit.com/DataFormat">
        <First_Names>John</First_Names>
        <Last_Names>Doe</Last_Names>
    </Person_Data>
    <Company_Data xmlns="http://schemas.multi-mit.com/DataFormat">
        <Company_Name Order="1">The Company</Company_Name>
    </Company_Data>
    <Address xmlns="http://schemas.multi-mit.com/DataFormat">
        <Address_Display>
             <Address_Line_1>xxxxxxxxxxx</Address_Line_1>
             <Address_Line_2 />
             <Address_Line_3 />
             <Postal_Code>XXX123</Postal_Code>
             <Town>The Town</Town>
             <County>The County</County>
             <Country>US</Country>
         </Address_Display>
    </Address>
</MMIT_Data_Record>

The schema is bigger, but this gives the basic idea. My main problem is that the root element is not namespaced, most generators simply leave it out, but then when validating this element is not found. If the element is included, then all child elements are not found in the namespace. I need to build an XSD for this and a WSDL elements part, but I can not figure out how. Please help.

Update: here is the xsd that most automated generatos create. Problem is when trying to validate, it does not find the root element MMIT_Data_Record.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.multi-mit.com/DataFormat">
    <xs:element name="Supplier_Code" type="xs:string"/>
    <xs:element name="Country_Code" type="xs:string"/>
    <xs:element name="Market_Code" type="xs:string"/>
    <xs:element name="Source_Code" type="xs:string"/>
    <xs:element name="Source" type="xs:string"/>
    <xs:element name="External_Reference_Id" type="xs:int"/>
    <xs:element name="Person_Data">
        <xs:complexType>
           <xs:sequence>
               <xs:element type="xs:string" name="First_Names"/>
               <xs:element type="xs:string" name="Last_Names"/>
           </xs:sequence>
        </xs:complexType>
     </xs:element>
     <xs:element name="Company_Data">
         <xs:complexType>
             <xs:sequence>
                 <xs:element name="Company_Name">
                     <xs:complexType>
                         <xs:simpleContent>
                             <xs:extension base="xs:string">
                                 <xs:attribute type="xs:byte" name="Order"/>
                             </xs:extension>
                         </xs:simpleContent>
                     </xs:complexType>
                 </xs:element>
             </xs:sequence>
         </xs:complexType>
     </xs:element>
     <xs:element name="Address">
         <xs:complexType>
             <xs:sequence>
                 <xs:element name="Address_Display">
                     <xs:complexType>
                         <xs:sequence>
                             <xs:element type="xs:string" name="Address_Line_1"/>
                             <xs:element type="xs:string" name="Address_Line_2"/>
                             <xs:element type="xs:string" name="Address_Line_3"/>
                             <xs:element type="xs:string" name="Postal_Code"/>
                             <xs:element type="xs:string" name="Town"/>
                             <xs:element type="xs:string" name="County"/>
                             <xs:element type="xs:string" name="Country"/>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
             </xs:sequence>
         </xs:complexType>
    </xs:element>
</schema>
0

There are 0 answers