Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an XSD & an XML that XMLSpy created for me from connecting to a MySQL customer table. I have cut many of the columns out because it's a waste of space.

XSD: customer.xsd
XML
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="customer">
        <xs:complexType>
            <xs:sequence>
        <xs:element name="customer_PK">
          <xs:simpleType>
            <xs:restriction base="xs:unsignedInt">
              <xs:minInclusive value="0"/>
              <xs:maxInclusive value="4294967295"/>
            </xs:restriction>
          </xs:simpleType>
        </xs:element>                
   
        <xs:key name="customer_PrimaryKey_1">
            <xs:selector xpath="."/>
            <xs:field xpath="customer_PK"/>
        </xs:key>
       
    </xs:element>
</xs:schema>

NOW FOR THE XML: customer.xml
I could not get the code to display so I have replaced "<" with "[".
XML
<?xml version="1.0" encodong="UTF-8"?>
<Import name = "customer"
xmlns="http://....."
   xsi:noNamespaceSchemaLocation="customer.xsd">
<customer>
<customer>
</Import>
XML verification by the XSD doesn't recognize the "Import" element in the XML. I get a "cvc-assess-elt.1: Neither an element declaration nor a type defintion is known for element [Import]. Strict assessment failed.

ANY IDEAS how to get the XSD & XML the same?
Posted
Updated 8-May-15 17:37pm
v2
Comments
Sergey Alexandrovich Kryukov 8-May-15 23:42pm    
Care of your work at least a bit; and you will be fine.
—SA

First of all, you if know XML, you probably should know HTML enough to be able to enter your code correctly. I've done it for you, without fixing your bugs. Apparently, this is no well-formed XML. Please find the typo and unclosed tags. When you ask questions, you need to copy exact code. If this is your real code, it's not to Schema definition to detect the problem. Not well-formed XML is not XML.

And of course, everyone can see that the element Import is not defined in your schema. You could not possibly expect anything good from this pair: XML sample and totally unmatched schema.

—SA
 
Share this answer
 
v2
Comments
Maciej Los 9-May-15 5:23am    
5ed!
In addition to solution 1 by Sergey Alexandrovich Kryukov[^], i'd suggest to read these articles:
XML Schema (XSD) Validation with XmlSchemaSet[^]
Validation of XML with Schemas[^]

Tip:
Schema expects customer element and its field customer_PK, but the first element in xml is Import, so xml file should looks like:
HTML
<customer>
    <customer_PK>1</customer_PK>
</customer>

If you would like to store several customers, you need to change schema and xml structure to:
HTML
<customers>
    <customer>
        <customer_PK>1</customer_PK>
    </customer>
    <customer>
        <customer_PK>2</customer_PK>
    </customer>
</customers>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900