Monday, 29 September 2014

XML invalid child element same as expected



I have created some xsd schemas and receive the below error when trying to read from it in c#



The element 'PartnerPSTNTransfer' in namespace 'http://localhost/Orders-PartnerPSTNTransfer-v1-0' has invalid child element 'StartDate' in namespace 'http://localhost/Orders-Connection-v1-0'. List of possible elements expected: 'StartDate' in namespace 'http://localhost/Orders-PartnerPSTNTransfer-v1-0'.


However the expected element is StartDate and it is present in the xml file so I am unsure why this error would be shown. I'll attatch the .xsd for the schemas i created:



<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="PartnerPSTN"
targetNamespace="http://localhost/Orders-PartnerPSTN-v1.0"
elementFormDefault="qualified"
xmlns="http://localhost/Orders-PartnerPSTN-v1.0"
xmlns:mstns="http://localhost/Orders-PartnerPSTN-v1.0"
xmlns:xs="http://ift.tt/tphNwY"
xmlns:a="http://localhost/Orders-Address-v1-0"
xmlns:c="http://localhost/Orders-Common-v1-0" >

<xs:simpleType name="Contract">
<xs:restriction base="xs:token">
<xs:enumeration value="Monthly_12"></xs:enumeration>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="PackageOption">
<xs:restriction base="xs:string">
<xs:enumeration value="Data Only" />
<xs:enumeration value="Free Evening and Weekend" />
<xs:enumeration value="1000 Anytime" />
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="FeatureOption">
<xs:list>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="Feature0"/>
<xs:enumeration value="Feature0.A"/>
<xs:enumeration value="Feature0.B"/>
<xs:enumeration value="Feature0.C"/>
<xs:enumeration value="Feature1"/>
<xs:enumeration value="Feature2"/>
<xs:enumeration value="Feature2.A"/>
<xs:enumeration value="Feature3"/>
<xs:enumeration value="Feature3.A"/>
<xs:enumeration value="Feature3.B"/>
<xs:enumeration value="Feature3.C"/>
</xs:restriction>
</xs:simpleType>
</xs:list>
</xs:simpleType>

<xs:complexType name="PartnerPSTNConfiguration">
<xs:sequence>
<xs:element name="Package" type="PackageOption" />
<xs:element name="Feature" type="FeatureOption" />
</xs:sequence>
</xs:complexType>
</xs:schema>


Schema 2:



<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="PartnerPSTNTransfer"
targetNamespace="http://localhost/Orders-PartnerPSTNTransfer-v1-0"
elementFormDefault="qualified"
xmlns="http://localhost/Orders-PartnerPSTNTransfer-v1-0"
xmlns:mstns="http://localhost/Orders-PartnerPSTNTransfer-v1-0"
xmlns:xs="http://ift.tt/tphNwY"
xmlns:a="http://localhost/Orders-Address-v1-0"
xmlns:padsl="http://localhost/Orders-PartnerPSTN-v1.0"
xmlns:c="http://localhost/Orders-Common-v1-0"
xmlns:conn="http://localhost/Orders-Connection-v1-0">

<xs:import namespace="http://localhost/Orders-Common-v1-0" schemaLocation="../../Common.xsd" />
<xs:import namespace="http://localhost/Orders-PartnerPSTN-v1.0" schemaLocation="PartnerPSTN.xsd" />

<xs:complexType name="PartnerPSTNTransfer">
<xs:sequence>
<xs:element name="TelephoneNumber" type="c:Landline" />
<xs:element name="StartDate" type="xs:date" />
<xs:element name="Postcode" type="c:RequiredString" />
<xs:element name="Configuration" type="padsl:PartnerPSTNConfiguration" />
</xs:sequence>
</xs:complexType>

<xs:element name="PartnerPSTNTransfer" type="PartnerPSTNTransfer"></xs:element>
</xs:schema>

No comments:

Post a Comment