Why XSD sequence shows as ambiguous [duplicate] - c#

This question already has an answer here:
Content model ambiguity in a schema
(1 answer)
Closed 8 years ago.
I'd like to have a xsd to valide an xml containing file elements, but in xsd have error
Warning 1 Wildcard '##any' allows element 'http://www.irica.com/ECEP/1383-12/SendSchema:Attachments', and causes the content model to become ambiguous. A content model must be formed such that during validation of an element information item sequence, the particle contained directly, indirectly or implicitly therein with which to attempt to validate each item in the sequence in turn can be uniquely determined without examining the content or attributes of that item, and without any information about the items in the remainder of the sequence. ECEP_Letter.xsd 204 18
Please help me
This is my xsd:
<xs:schema targetNamespace="http://www.irica.com/ECEP/1383-12/SendSchema" xmlns:irecetns="http://www.irica.com/ECEP/1383-12/SendSchema" xmlns="http://www.irica.com/ECEP/1383-12/SendSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="qualified" version="1.01">
<xs:element name="Letter">
<xs:complexType>
<xs:sequence>
<xs:element name="Protocol" nillable="false" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:attribute name="Name" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Version" type="xs:string" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:complexType>
</xs:element>
<xs:element name="Software" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="SoftwareDeveloper" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Version" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="GUID" type="xs:string" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="Sender" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:attribute name="Organization" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Department" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Position" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Name" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Code" type="xs:string" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:complexType>
</xs:element>
<xs:element name="Receiver" nillable="false" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:attribute name="Organization" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Department" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Position" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Name" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Code" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="ReceiveType" type="irecetns:ReceiveType" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:complexType>
</xs:element>
<xs:element name="OtherReceivers" nillable="false" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="OtherReceiver" nillable="false" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="Organization" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Department" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Position" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Name" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Code" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="ReceiveType" type="irecetns:ReceiveType" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="LetterNo" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="LetterDateTime" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:dateTime">
<xs:attribute name="ShowAs" type="irecetns:DateType" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="RelatedLetters" minOccurs="0" maxOccurs="1" nillable="false">
<xs:complexType>
<xs:sequence>
<xs:element name="RelatedLetter" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="RelationType" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:attribute name="Name" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Code" type="xs:string" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:complexType>
</xs:element>
<xs:element name="RelatedLetterNo" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="RelatedLetterDateTime" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:dateTime">
<xs:attribute name="ShowAs" type="irecetns:DateType" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="RelatedLetterSender" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:attribute name="Organization" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Department" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Position" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Name" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Code" type="xs:string" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Subject" minOccurs="0" maxOccurs="1" nillable="true">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="Priority" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:attribute name="Name" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Code" type="xs:string" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:complexType>
</xs:element>
<xs:element name="Classification" nillable="false" maxOccurs="1" minOccurs="1">
<xs:complexType>
<xs:attribute name="Name" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Code" type="xs:string" use="required" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:complexType>
</xs:element>
<xs:element name="Keywords" nillable="false" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Keyword" nillable="false" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Origins" nillable="false" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="Origin" nillable="false" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="ContentType" type="irecetns:FileType" use="required" form="unqualified"/>
<xs:attribute name="Extension" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Description" type="xs:string" use="optional" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Attachments" minOccurs="0" maxOccurs="1" nillable="false">
<xs:complexType>
<xs:sequence>
<xs:element name="Attachment" nillable="true" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:base64Binary">
<xs:attribute name="ContentType" type="xs:string" use="required" form="unqualified"/>
<xs:attribute name="Extension" type="xs:string" use="optional" form="unqualified"/>
<xs:attribute name="Description" type="xs:string" use="optional" form="unqualified"/>
<xs:anyAttribute namespace="##any" processContents="skip"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:any minOccurs="0" maxOccurs="unbounded" processContents="lax" namespace="##any"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:simpleType name="FileType">
<xs:restriction base="xs:string">
<xs:enumeration value="image/jpeg"/>
<xs:enumeration value="image/tiff"/>
<xs:enumeration value="image/gif"/>
<xs:enumeration value="image/png"/>
<xs:enumeration value="application/msword"/>
<xs:enumeration value="application/pdf"/>
<xs:enumeration value="text/plain"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="DateType">
<xs:restriction base="xs:string">
<xs:enumeration value="gregorian"/>
<xs:enumeration value="Ahmadi"/>
<xs:enumeration value="hijri"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="ReceiveType">
<xs:restriction base="xs:string">
<xs:enumeration value="Origin"/>
<xs:enumeration value="Copy"/>
<xs:enumeration value="Refer"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>
what is correct XSD file ?

You've got an optional Attachments element, followed by an xs:any which also permits an Attachments element. So if the parser encounters an Attachments element, it doesn't know whether to validate it against your Attachments declaration or against the wildcard.
This rule disappears in XSD 1.1: if the input can match either a specific element declaration or a wildcard, it automatically chooses the specific element declaration.
In XSD 1.0 the usual solution is to set up the wildcard so it only allows names in a different namespace.

Related

XML Schema with repeating elements

I am trying to deserialise the following XML:
<queries>
<query name='abc'>
<statement>SELECT * FROM table1</statement>
<label row='1' name='id'/>
<label row='2' name='name'/>
</query>
<query name='another'>
<statement>SELECT * FROM table2</statement>
<label row='1' name='myTabID'/>
<label row='2' name='myTabName'/>
</query>
</queries>
To validate the schema I am using:
<xs:complexType name="Queries">
<xs:sequence>
<xs:element name="query" type="Query"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="Query">
<xs:sequence>
<xs:element name="statement" minOccurs="1" maxOccurs="1"/>
<xs:element name="label">
<xs:complexType>
<xs:attribute name="row" type="xs:int" use="required"/>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="name" type="xs:string"/>
</xs:complexType>
Validation is failing with the message:
Not valid.
Error - Line 7, 48: org.xml.sax.SAXParseException; lineNumber: 7; columnNumber: 48; cvc-complex-type.2.4.d: Invalid content was found starting with element 'label'. No child element is expected at this point.
Error - Line 9, 31: org.xml.sax.SAXParseException; lineNumber: 9; columnNumber: 31; cvc-complex-type.2.4.d: Invalid content was found starting with element 'query'. No child element is expected at this point.
What am I missing please? Do I need to specify a different tag than sequence? I want to enforce at least one query existing.
Thank you in advanced :)
The error message complains about the definition
<xs:element name="label">
and the use
<label row='1' name='id'/>
<label row='2' name='name'/>
The default values (W3) for minOccurs and maxOccurs is 1, so you can only use one label there. You need to change it if you like to use more labels. Use unbounded for arbitrary amount.
Also note that similar maxOccurs adjustment (unbounded or greater than 1) is needed for query (as commented by #kjhughes)
try this :
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="queries">
<xs:complexType>
<xs:sequence>
<xs:element name="query" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="statement"/>
<xs:element name="label" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:int" name="row" use="optional"/>
<xs:attribute type="xs:string" name="name" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="name" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

XSD Use single restriction for multiple elements

I have an XML file that is produced from a customer system where decimal values are output with commas instead of decimal points so like 10,5 or 1250,50 instead of 10.5 or 1250.50.
I need to validate and deserialise this XML file so I am trying to get a XSD schema created to do the validation and once validated deserialise the file.
Everything works ok except for validating the numbers because of the comma.
I have the following restriction for the XSD but I cannot figure out how to add the restriction once and use it for multiple different elements since there can be a lot of items with numbers in them:
<xs:restriction base="xs:string">
<xs:pattern value="^\d+(\,\d{1,2})?$"/>
</xs:restriction>
I've tried to add the following block inside the InvoiceRow element in the XSD sample below but it just seems to break the XSD format:
<xs:simpleType name="DecimalValidation">
<xs:restriction base="xs:string">
<xs:pattern value="^\d+(\,\d{1,2})?$"/>
</xs:restriction>
</xs:simpleType>
This is my XSD and the places where "xs:decimal" have been set are the items that have the number values with the commas in it and I need to use the restriction to validate them.
<xs:element name="InvoiceRow" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="ArticleIdentifier"/>
<xs:element type="xs:string" name="ArticleName"/>
<xs:element name="OrderedQuantity">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:short">
<xs:attribute type="xs:string" name="QuantityUnitCode" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="UnitPriceAmount">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute type="xs:string" name="AmountCurrencyIdentifier" use="optional"/>
<xs:attribute type="xs:string" name="UnitPriceUnitCode" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element type="xs:short" name="RowVatRatePercent"/>
<xs:element name="RowVatAmount">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute type="xs:string" name="AmountCurrencyIdentifier" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="RowVatExcludedAmount">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute type="xs:string" name="AmountCurrencyIdentifier" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="RowAmount">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute type="xs:string" name="AmountCurrencyIdentifier" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Thanks for any info or suggestions around this.
Because your simple type DecimalValidation is named, it should appear at the top level of the schema as a global declaration (that is, as a child of xs:schema), and you should then be able to replace all references to xs:decimal by references to DecimalValidation. (It looks like there are no namespaces involved, but if there are, you might need to add a suitable namespace prefix.)

Getting error parsing xsd into c# classes

Here is the XSD I am using (downloaded straight from source)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.newyorkfed.org/resources/sdmxml/schemas/V2_1/fundRate" xmlns:dsd="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/structurespecific" xmlns:common="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" xmlns:codes="http://www.newyorkfed.org/resources/sdmxml/schemas/V2_1/fundRateCommon" targetNamespace="http://www.newyorkfed.org/resources/sdmxml/schemas/V2_1/fundRate" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:import namespace="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/structurespecific" schemaLocation="SDMXDataStructureSpecific.xsd"/>
<xs:import namespace="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" schemaLocation="SDMXCommon.xsd"/>
<xs:import namespace="http://www.newyorkfed.org/resources/sdmxml/schemas/V2_1/fundRateCommon" schemaLocation="fundRateCommon.xsd"/>
<xs:complexType name="RateDataSetType">
<xs:complexContent>
<xs:restriction base="dsd:TimeSeriesDataSetType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
<xs:element name="DataProvider" type="common:DataProviderReferenceType" form="unqualified" minOccurs="0"/>
<xs:element name="Group" type="GroupType" form="unqualified" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice minOccurs="0">
<xs:element name="Series" type="RateSeriesType" form="unqualified" maxOccurs="unbounded"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="REPORTING_YEAR_START_DAY" type="xs:gMonthDay" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="SupplementalDataSetType">
<xs:complexContent>
<xs:restriction base="dsd:TimeSeriesDataSetType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
<xs:element name="DataProvider" type="common:DataProviderReferenceType" form="unqualified" minOccurs="0"/>
<xs:element name="Group" type="GroupType" form="unqualified" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice minOccurs="0">
<xs:element name="Series" type="SupplementalSeriesType" form="unqualified" maxOccurs="unbounded"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="REPORTING_YEAR_START_DAY" type="xs:gMonthDay" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="GroupType" abstract="true">
<xs:complexContent>
<xs:restriction base="dsd:GroupType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="type" type="GroupType.ID" use="optional"/>
<xs:anyAttribute namespace="##local"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="GroupType.ID">
<xs:restriction base="common:IDType">
<xs:enumeration value="RateSiblingGroup"/>
<xs:enumeration value="SupplementalSiblingGroup"/>
<xs:enumeration value="RateGroup"/>
<xs:enumeration value="SupplementalGroup"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="RateSiblingGroup">
<xs:complexContent>
<xs:restriction base="GroupType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="DECIMALS" type="codes:SDMX.CL_DECIMALS.1.0" use="optional"/>
<xs:attribute name="FUNDRATE_OBS_POINT" type="codes:FRBNY.CL_FUNDRATE_OBS_POINT.1.0" use="required"/>
<xs:attribute name="FUNDRATE_TYPE" type="codes:FRBNY.CL_FUNDRATE_TYPE.1.0" use="required"/>
<xs:attribute name="TITLE" type="xs:string" use="optional"/>
<xs:attribute name="type" type="GroupType.ID" use="optional" fixed="RateSiblingGroup"/>
<xs:attribute name="UNIT_MEASURE" type="codes:SDMX.CL_UNIT_MEASURE.1.0" use="optional"/>
<xs:attribute name="UNIT_MULT" type="codes:SDMX.CL_UNIT_MULT.1.0" use="optional"/>
<xs:attribute name="LAST_DAY_OF_MAINTENANCE_PERIOD" type="xs:boolean" use="optional"/>
<xs:attribute name="REPORTING_YEAR_START_DAY" type="xs:gMonthDay" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="SupplementalSiblingGroup">
<xs:complexContent>
<xs:restriction base="GroupType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="DECIMALS" type="codes:SDMX.CL_DECIMALS.1.0" use="optional"/>
<xs:attribute name="FUNDRATE_SUPPLEMENTAL" type="codes:FRBNY.CL_FUNDRATE_SUPPLEMENTAL.1.0" use="required"/>
<xs:attribute name="FUNDRATE_TYPE" type="codes:FRBNY.CL_FUNDRATE_TYPE.1.0" use="required"/>
<xs:attribute name="TITLE" type="xs:string" use="optional"/>
<xs:attribute name="type" type="GroupType.ID" use="optional" fixed="SupplementalSiblingGroup"/>
<xs:attribute name="UNIT_MEASURE" type="codes:SDMX.CL_UNIT_MEASURE.1.0" use="optional"/>
<xs:attribute name="UNIT_MULT" type="codes:SDMX.CL_UNIT_MULT.1.0" use="optional"/>
<xs:attribute name="REPORTING_YEAR_START_DAY" type="xs:gMonthDay" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="RateGroup">
<xs:complexContent>
<xs:restriction base="GroupType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="COLL_METHOD" type="xs:string" use="optional"/>
<xs:attribute name="FUNDRATE_TYPE" type="codes:FRBNY.CL_FUNDRATE_TYPE.1.0" use="required"/>
<xs:attribute name="type" type="GroupType.ID" use="optional" fixed="RateGroup"/>
<xs:attribute name="REPORTING_YEAR_START_DAY" type="xs:gMonthDay" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="SupplementalGroup">
<xs:complexContent>
<xs:restriction base="GroupType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="COLL_METHOD" type="xs:string" use="optional"/>
<xs:attribute name="FUNDRATE_TYPE" type="codes:FRBNY.CL_FUNDRATE_TYPE.1.0" use="required"/>
<xs:attribute name="type" type="GroupType.ID" use="optional" fixed="SupplementalGroup"/>
<xs:attribute name="REPORTING_YEAR_START_DAY" type="xs:gMonthDay" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="RateSeriesType">
<xs:complexContent>
<xs:restriction base="dsd:TimeSeriesType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
<xs:element name="Obs" type="ObsType" form="unqualified" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="FREQ" type="codes:SDMX.CL_FREQ.1.0" use="required"/>
<xs:attribute name="FUNDRATE_OBS_POINT" type="codes:FRBNY.CL_FUNDRATE_OBS_POINT.1.0" use="required"/>
<xs:attribute name="FUNDRATE_TYPE" type="codes:FRBNY.CL_FUNDRATE_TYPE.1.0" use="required"/>
<xs:attribute name="REPORTING_YEAR_START_DAY" type="xs:gMonthDay" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="SupplementalSeriesType">
<xs:complexContent>
<xs:restriction base="dsd:TimeSeriesType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
<xs:element name="Obs" type="ObsType" form="unqualified" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="FREQ" type="codes:SDMX.CL_FREQ.1.0" use="required"/>
<xs:attribute name="FUNDRATE_SUPPLEMENTAL" type="codes:FRBNY.CL_FUNDRATE_SUPPLEMENTAL.1.0" use="required"/>
<xs:attribute name="FUNDRATE_TYPE" type="codes:FRBNY.CL_FUNDRATE_TYPE.1.0" use="required"/>
<xs:attribute name="REPORTING_YEAR_START_DAY" type="xs:gMonthDay" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="ObsType">
<xs:complexContent>
<xs:restriction base="dsd:TimeSeriesObsType">
<xs:sequence>
<xs:element ref="common:Annotations" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="CONF_STATUS_OBS" type="codes:SDMX.CL_CONF_STATUS_OBS.1.0" use="optional"/>
<xs:attribute name="OBS_STATUS" type="codes:SDMX.CL_OBS_STATUS.1.0" use="optional"/>
<xs:attribute name="OBS_VALUE" type="xs:decimal" use="required"/>
<xs:attribute name="TIME_PERIOD" type="xs:date" use="required"/>
<xs:attribute name="LAST_DAY_OF_MAINTENANCE_PERIOD" type="xs:boolean" use="optional"/>
<xs:attribute name="REPORTING_YEAR_START_DAY" type="xs:gMonthDay" use="prohibited"/>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>
When I run XSD to code I get this error:
I've tried adding complex type elements at the base level that define each one with a name and type property and this didn't seem to work.
I think the problem is that you lack some of the necessary XSD documents. On the web page you link to in the comments: https://www.newyorkfed.org/markets/effr-obfr, two XSD files can be obtained: fundRateCommon.xsd and fundRate.xsd.
But in fundRate.xsd, there are several import statements:
<xs:import namespace="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/data/structurespecific" schemaLocation="SDMXDataStructureSpecific.xsd"/>
<xs:import namespace="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" schemaLocation="SDMXCommon.xsd"/>
<xs:import namespace="http://www.newyorkfed.org/resources/sdmxml/schemas/V2_1/fundRateCommon" schemaLocation="fundRateCommon.xsd"/>
and from this page, you could not have downloaded SDMXCommon.xsd and SDMXDataStructureSpecific.xsd. The error you get from XSD2Code appears to be about content from SDMXDataStructureSpecific.xsd.
Download those XSD files, too and try again.
It seems like you are missing the base SDMX .xsd's.. these are available from
sdmx.org under the standards tab...

C#/.NET XML Schema Validation - MSXML strange behavior: ENTITY referenced but not declared

I´m trying to validate some XML documents with a xml schema (xsd).
sample code:
private static void validateXml(string file, string schema)
{
if (!File.Exists(schema))
{
Console.WriteLine("File not found.");
return;
}
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Parse;
settings.ValidationType = ValidationType.Schema;
settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
settings.Schemas.Add(null, schema);
using (XmlReader reader = XmlReader.Create(file, settings))
while (reader.Read()) ;
}
private static void ValidationCallBack(object sender, ValidationEventArgs args)
{
Console.WriteLine("Error: " + args.Message);
}
sample xml:
<?xml version="1.0"?>
<!--PUBLIC "-//AECMA//DTD AECMA 1000D AirCrew 20010401//EN"-->
<!DOCTYPE dmodule SYSTEM "dm_aecma_avee_c_190.dtd"[
<!ENTITY entity1 SYSTEM "entity1.CGM" NDATA CGM>
]>
<dmodule>
<content>
<refs>
<norefs/>
</refs>
<acrw>
<descacrw>
<para0>
<title>Text</title>
<drill drilltyp="Text" ordered="Text">
<step id="Text" memorize="Text" dotline="Text" ordered="Text">
<procd>
<para>
<xref xrefid="fi0001-hot2" xidtype="hotspot">Text</para>
</procd>
</step>
<step id="Text" memorize="Text" dotline="Text" ordered="Text">
<procd>
<para>Text<xref xrefid="fi0001-hot3" xidtype="hotspot">Text</xref>Text</para>
</procd>
</step>
<figure id="fi0001">
<title>Text</title>
<graphic boardno="entity1">
<hotspot id="fi0001-hot1" apsname="1" type="POS" title="Text"/>
<hotspot id="fi0001-hot2" apsname="2" type="POS" title="Text"/>
<hotspot id="fi0001-hot3" apsname="3" type="POS" title="Text"/>
</graphic>
<legend>
<deflist>
<term>1</term>
<def>
<xref xrefid="fi0001-hot1" xidtype="hotspot">Text</xref>
</def>
<term>2</term>
<def>
<xref xrefid="fi0001-hot2" xidtype="hotspot">Text</xref>
</def>
<term>3</term>
<def>
<xref xrefid="fi0001-hot3" xidtype="hotspot">Text</xref>
</def>
</deflist>
</legend>
</figure>
</drill>
</para0>
</descacrw>
</acrw>
</content>
</dmodule>
sample xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="dmodule">
<xs:complexType>
<xs:sequence>
<xs:element ref="idstatus"/>
<xs:element ref="content"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="modelic" type="modelicType"/>
<xs:element name="supeqvc" type="supeqvcType"/>
<xs:element name="ecscs" type="ecscsType"/>
<xs:element name="eidc" type="eidcType"/>
<xs:element name="cidc" type="cidcType"/>
<xs:element name="discode" type="discodeType"/>
<xs:element name="discodev" type="discodevType"/>
<xs:element name="incode" type="incodeType"/>
<xs:element name="incodev" type="incodevType"/>
<xs:element name="itemloc" type="itemlocType"/>
<xs:element name="techname" type="xs:string"/>
<xs:element name="infoname" type="xs:string"/>
<xs:element name="issno">
<xs:complexType>
<xs:attribute name="issno" type="issnovalueType" use="required"/>
<xs:attribute name="type" type="issnotypeType" default="new"/>
</xs:complexType>
</xs:element>
<xs:element name="issdate">
<xs:complexType>
<xs:attribute name="year" type="YEAR" use="required"/>
<xs:attribute name="month" type="MONTH" use="required"/>
<xs:attribute name="day" type="DAY" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="language">
<xs:complexType>
<xs:attribute name="language" type="languagetypeType" use="required"/>
<xs:attribute name="country" type="countryType"/>
</xs:complexType>
</xs:element>
<xs:element name="security">
<xs:complexType>
<xs:attribute ref="class" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="rpc">
<xs:complexType mixed="true">
<xs:attribute name="rpcname" type="xs:string"/>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="orig">
<xs:complexType mixed="true">
<xs:attribute name="origname" type="xs:string"/>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="applic">
<xs:complexType>
<xs:sequence>
<xs:element ref="type" minOccurs="0"/>
<xs:element ref="model" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="type" type="xs:string"/>
<xs:element name="model">
<xs:complexType>
<xs:sequence>
<xs:element ref="version" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="mfc" minOccurs="0"/>
<xs:element ref="batchno" minOccurs="0"/>
<xs:element ref="moduleno" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="serialno" minOccurs="0"/>
<xs:element ref="pnr" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="nsn" minOccurs="0"/>
<xs:element ref="customer" minOccurs="0"/>
<xs:element ref="softprog" minOccurs="0"/>
<xs:element ref="config" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="model" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="version">
<xs:complexType>
<xs:sequence>
<xs:element ref="versrank" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="version" type="xs:string" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="unverif">
<xs:complexType/>
</xs:element>
<xs:element name="firstver">
<xs:complexType>
<xs:attribute name="type" type="firstvertypeType" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="sbc">
<xs:complexType mixed="true">
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="content">
<xs:complexType>
<xs:sequence>
<xs:element ref="refs"/>
<xs:element ref="acrw"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="refs">
<xs:complexType>
<xs:choice>
<xs:element ref="norefs"/>
<xs:element ref="rdandrt"/>
<xs:element ref="refdms"/>
<xs:element ref="reftp"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="refdms">
<xs:complexType>
<xs:sequence>
<xs:element ref="refdm" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="refdm">
<xs:complexType>
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:choice>
<xs:element ref="age"/>
<xs:element ref="avee"/>
</xs:choice>
<xs:element ref="issno" minOccurs="0"/>
<xs:element ref="dmtitle" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="target" type="xs:string"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="xref">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="subscrpt"/>
<xs:element ref="supscrpt"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="xrefid" type="xs:IDREF"/>
<xs:attribute ref="xidtype"/>
<xs:attribute name="target" type="xs:string"/>
<xs:attribute name="destitle" type="xs:string"/>
<xs:attribute name="pretext" type="xs:string"/>
<xs:attribute name="posttext" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="symbol">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="boardno" type="xs:ENTITY" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="acrw">
<xs:complexType>
<xs:choice>
<xs:element ref="frc"/>
<xs:element ref="descacrw"/>
</xs:choice>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute ref="class"/>
</xs:complexType>
</xs:element>
<xs:element name="title">
<xs:complexType mixed="true">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="xref"/>
<xs:element ref="indxflag"/>
<xs:element ref="change"/>
<xs:element ref="emphasis"/>
<xs:element ref="symbol"/>
<xs:element ref="subscrpt"/>
<xs:element ref="supscrpt"/>
<xs:element ref="refdm"/>
<xs:element ref="reftp"/>
<xs:element ref="capgrp"/>
<xs:element ref="caption"/>
</xs:choice>
<xs:attribute ref="class"/>
</xs:complexType>
</xs:element>
<xs:element name="graphic">
<xs:complexType>
<xs:sequence>
<xs:element ref="hotspot" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="boardno" type="xs:ENTITY" use="required"/>
<xs:attribute name="id" type="xs:ID"/>
</xs:complexType>
</xs:element>
<xs:element name="hotspot">
<xs:complexType>
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="hotspot"/>
<xs:element ref="xref"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="apsid" type="xs:string"/>
<xs:attribute name="apsname" type="xs:string"/>
<xs:attribute name="type" type="xs:string"/>
<xs:attribute name="title" type="xs:string"/>
<xs:attribute name="descript" type="xs:string"/>
<xs:attribute name="coords" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="para">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:choice maxOccurs="unbounded">
<xs:choice minOccurs="0">
<xs:element ref="xref"/>
<xs:element ref="indxflag"/>
<xs:element ref="change"/>
<xs:element ref="emphasis"/>
<xs:element ref="symbol"/>
<xs:element ref="subscrpt"/>
<xs:element ref="supscrpt"/>
<xs:element ref="refdm"/>
<xs:element ref="reftp"/>
<xs:element ref="capgrp"/>
<xs:element ref="caption"/>
</xs:choice>
<xs:choice>
<xs:element ref="seqlist"/>
<xs:element ref="randlist"/>
<xs:element ref="deflist"/>
</xs:choice>
</xs:choice>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
<xs:attribute ref="class"/>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:choice maxOccurs="unbounded">
<xs:element ref="para"/>
<xs:choice maxOccurs="unbounded">
<xs:choice minOccurs="0">
<xs:element ref="xref"/>
<xs:element ref="indxflag"/>
<xs:element ref="change"/>
<xs:element ref="emphasis"/>
<xs:element ref="symbol"/>
<xs:element ref="subscrpt"/>
<xs:element ref="supscrpt"/>
<xs:element ref="refdm"/>
<xs:element ref="reftp"/>
<xs:element ref="capgrp"/>
<xs:element ref="caption"/>
</xs:choice>
<xs:choice>
<xs:element ref="seqlist"/>
<xs:element ref="randlist"/>
<xs:element ref="deflist"/>
</xs:choice>
</xs:choice>
</xs:choice>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="deflist">
<xs:complexType>
<xs:sequence>
<xs:sequence minOccurs="0">
<xs:element ref="applic" minOccurs="0"/>
<xs:element ref="title"/>
</xs:sequence>
<xs:sequence maxOccurs="unbounded">
<xs:element ref="term"/>
<xs:element ref="def"/>
</xs:sequence>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
<xs:attribute ref="class"/>
</xs:complexType>
</xs:element>
<xs:element name="term">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="xref"/>
<xs:element ref="indxflag"/>
<xs:element ref="change"/>
<xs:element ref="emphasis"/>
<xs:element ref="symbol"/>
<xs:element ref="subscrpt"/>
<xs:element ref="supscrpt"/>
<xs:element ref="refdm"/>
<xs:element ref="reftp"/>
<xs:element ref="capgrp"/>
<xs:element ref="caption"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="def">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:choice maxOccurs="unbounded">
<xs:element ref="para"/>
<xs:choice maxOccurs="unbounded">
<xs:choice minOccurs="0">
<xs:element ref="xref"/>
<xs:element ref="indxflag"/>
<xs:element ref="change"/>
<xs:element ref="emphasis"/>
<xs:element ref="symbol"/>
<xs:element ref="subscrpt"/>
<xs:element ref="supscrpt"/>
<xs:element ref="refdm"/>
<xs:element ref="reftp"/>
<xs:element ref="capgrp"/>
<xs:element ref="caption"/>
</xs:choice>
<xs:choice>
<xs:element ref="seqlist"/>
<xs:element ref="randlist"/>
<xs:element ref="deflist"/>
</xs:choice>
</xs:choice>
</xs:choice>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="drill">
<xs:complexType>
<xs:sequence>
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:element ref="title" minOccurs="0"/>
<xs:element ref="tabtitle" minOccurs="0"/>
<xs:sequence>
<xs:element ref="warning" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="caution" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="note" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:element ref="crew" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="para"/>
<xs:choice>
<xs:element ref="figure"/>
<xs:element ref="table"/>
<xs:element ref="foldout"/>
</xs:choice>
</xs:choice>
</xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:choice maxOccurs="unbounded">
<xs:element ref="step"/>
<xs:choice>
<xs:sequence>
<xs:element ref="if"/>
<xs:element ref="elseif" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:element ref="case"/>
</xs:choice>
</xs:choice>
<xs:element ref="subdrill" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
<xs:element ref="endmattr" minOccurs="0"/>
</xs:sequence>
<xs:attribute ref="drilltyp" default="none"/>
<xs:attribute ref="ordered" default="on"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
<xs:attribute ref="class"/>
</xs:complexType>
</xs:element>
<xs:element name="step">
<xs:complexType>
<xs:sequence>
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:sequence>
<xs:element ref="warning" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="caution" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="note" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element ref="para"/>
<xs:element ref="note" minOccurs="0" maxOccurs="unbounded"/>
<xs:choice minOccurs="0">
<xs:element ref="figure"/>
<xs:element ref="table"/>
<xs:element ref="foldout"/>
</xs:choice>
</xs:sequence>
<xs:choice>
<xs:sequence>
<xs:element ref="crew" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="procd"/>
<xs:choice minOccurs="0">
<xs:element ref="figure"/>
<xs:element ref="table"/>
<xs:element ref="foldout"/>
</xs:choice>
</xs:sequence>
<xs:sequence>
<xs:element ref="challeng"/>
<xs:sequence maxOccurs="unbounded">
<xs:element ref="crew" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="response"/>
</xs:sequence>
</xs:sequence>
</xs:choice>
<xs:element ref="note" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="step"/>
<xs:choice>
<xs:sequence>
<xs:element ref="if"/>
<xs:element ref="elseif" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:element ref="case"/>
</xs:choice>
</xs:choice>
</xs:sequence>
<xs:attribute name="label" type="xs:string"/>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
<xs:attribute ref="memorize" default="no"/>
<xs:attribute ref="dotline" default="dot"/>
<xs:attribute ref="ordered" default="on"/>
<xs:attribute ref="class"/>
</xs:complexType>
</xs:element>
<xs:element name="procd">
<xs:complexType>
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:element ref="para"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="figure">
<xs:complexType>
<xs:sequence>
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:element ref="title"/>
</xs:sequence>
<xs:choice>
<xs:sequence>
<xs:element ref="graphic"/>
<xs:element ref="rfa" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:sequence maxOccurs="unbounded">
<xs:element ref="sheet"/>
<xs:element ref="graphic"/>
<xs:element ref="rfa" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:choice>
<xs:element ref="legend" minOccurs="0"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
<xs:attribute ref="class"/>
</xs:complexType>
</xs:element>
<xs:element name="legend">
<xs:complexType>
<xs:sequence>
<xs:element ref="deflist"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="descacrw">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:sequence>
<xs:sequence>
<xs:element ref="warning" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="caution" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="note" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:element ref="para0" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:choice>
<xs:element ref="figure"/>
<xs:element ref="table"/>
<xs:element ref="foldout"/>
</xs:choice>
</xs:choice>
<xs:attribute ref="class"/>
</xs:complexType>
</xs:element>
<xs:element name="para0">
<xs:complexType>
<xs:sequence>
<xs:sequence>
<xs:sequence>
<xs:element ref="applic" minOccurs="0"/>
<xs:element ref="title" minOccurs="0"/>
</xs:sequence>
<xs:sequence>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="specpara"/>
<xs:element ref="para"/>
<xs:choice minOccurs="0">
<xs:element ref="figure"/>
<xs:element ref="table"/>
<xs:element ref="foldout"/>
</xs:choice>
</xs:choice>
<xs:element ref="drill" minOccurs="0"/>
</xs:sequence>
</xs:sequence>
<xs:element ref="subpara1" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="id" type="xs:ID"/>
<xs:attribute name="level" type="xs:NMTOKEN"/>
<xs:attribute name="mark" type="xs:NMTOKEN"/>
<xs:attribute ref="change"/>
<xs:attribute name="rfc" type="xs:string"/>
<xs:attribute ref="class"/>
</xs:complexType>
</xs:element>
<xs:simpleType name="modelicType">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9]{2,14}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="discodeType">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9]{2}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="discodevType">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9]{1,3}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="incodeType">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9]{3}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="incodevType">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9]{1}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="itemlocType">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9]{1}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="sdcType">
<xs:restriction base="xs:string">
<xs:pattern value="[A-Za-z0-9]{1,4}"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="issnovalueType">
<xs:restriction base="xs:nonNegativeInteger">
<xs:pattern value="\d{3}"/>
</xs:restriction>
</xs:simpleType>
<xs:attribute name="xidtype">
<xs:simpleType>
<xs:restriction base="xs:token">
<xs:enumeration value="figure"/>
<xs:enumeration value="table"/>
<xs:enumeration value="supply"/>
<xs:enumeration value="supequip"/>
<xs:enumeration value="spares"/>
<xs:enumeration value="para"/>
<xs:enumeration value="step"/>
<xs:enumeration value="sheet"/>
<xs:enumeration value="hotspot"/>
<xs:enumeration value="other"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>
I am not the author from the xsd file, so I cannot change it.
When I use Oxygen to validate the xml file, it validates successfully, which is right. But if I use Oxygen with the MSXML engine or my C# program, it does not validates, the error says: ENTITIY 'name' referenced but not declared.
Does anyone knows why the .NET parser did not "know" the ENTITIES?
UPDATE:
I added a better example. The original XSD file is about 5.000 lines long, so I tried to just copy the important part. So, the xml file is valid and Oxygen validates it correctly using default engine, xerces and saxon. BUT, with the MSXML .NET or MSXML 4.0 engine, the parser throws the same error as my program:
Programname: MSXML.NET
description: Verweis auf eine nicht deklarierte ID ist 'fi0001-hot3'.
line: 73 position: 34 (<para>Text<xref xrefid="fi0001-hot3" xidtype="hotspot">)
Programname: MSXML.NET
description: Verweis auf eine nicht deklarierte ID ist 'fi0001-hot2'.
line: 68 position: 16 (<xref xrefid="fi0001-hot2" xidtype="hotspot">Text</xref>)
And sometimes it even throws the error:
Programname: MSXML.NET
description: Verweis auf eine nicht deklarierte ENTITY ist 'entity1'.
But only the MSXML parser, the others working correctly.
So why has the MSXML parser a problem with ENTITIES and ID declarations?

"Could not find schema information for the element" - but my schema file does contain information for the element

I'm trying to work with an application that i don't have the source code for. I'm trying to interface in some data in an XML file. i believe my file matches the applications required schema correctly, but i get the message "Could not find schema information for the element" for every element in my file. I've decomplied the applications code and rebuilt it in visual studio, and i get the error myself.
I'm going to go ahead and just dump the code... Its pretty long, but i'm starting to think its a pretty bone head mistake on my part.
The XML to be imported:
<WorkOrders>
<WorkOrder>
<Action>SAVE</Action>
<UserDef1>NotRequired1</UserDef1>
<UserDef2>NotRequired2</UserDef2>
<UserDef3>NotRequired3</UserDef3>
<UserDef4>NotRequired4</UserDef4>
<UserDef5>NotRequired5</UserDef5>
<UserDef6>NotRequired6</UserDef6>
<UserDef7>-1</UserDef7>
<UserDef8>-2</UserDef8>
<AutoRelease>N</AutoRelease> <!--Probably can hardcode as N-->
<BuildInstructions>Not Required BuildInstructions</BuildInstructions>
<!--<BuildLocation>Not required BuildLocation</BuildLocation>-->
<Company></Company> <!--should match compan on the item master-->
<!--<DimensionUm></DimensionUm>-->
<DueDate>12-31-2011</DueDate>
<!--<Error></Error>-->
<FinishedItem>SERIAL_TEST</FinishedItem>
<QtyToBeBuilt>12345</QtyToBeBuilt>
<!--<QtyUm></QtyUm>
<RevisionNum></RevisionNum>-->
<Warehouse>PPLant</Warehouse>
<WeightUm></WeightUm>
<WOAllocMethod></WOAllocMethod>
<WorkOrderDetails>
<Action>SAVE</Action>
<UserDef1>NotRequired1</UserDef1>
<UserDef2>NotRequired2</UserDef2>
<UserDef3>NotRequired3</UserDef3>
<UserDef4>NotRequired4</UserDef4>
<UserDef5>NotRequired5</UserDef5>
<UserDef6>NotRequired6</UserDef6>
<UserDef7>-1</UserDef7>
<UserDef8>-2</UserDef8>
<AllocationRule>WorkOrderAllocation</AllocationRule>
<BuildLevel>1</BuildLevel>
<!--<BuildSequence>1</BuildSequence>-->
<Company></Company>
<ComponentItem>SERIAL_TEST</ComponentItem>
<FromLocation></FromLocation>-->
<!-- these fields allow users to increase/decrease the component quantity required
<IncQtyAmount></IncQtyAmount>
<IncQtyEligible></IncQtyEligible>
<IncQtyMinAmount></IncQtyMinAmount>
<IncQtyType></IncQtyType>-->
<!-- <LogisticsUnit></LogisticsUnit>
<Lot></Lot>
<ParentLogisticsUnit></ParentLogisticsUnit>-->
<QtyNeededPerItem>10</QtyNeededPerItem>
<!--<QuantityUm></QuantityUm>-->
<Warehouse>PPLant</Warehouse>
</WorkOrderDetails>
<WorkOrderId>ExampleWorkOrderID001</WorkOrderId>
<AllocationRule>WorkOrderAllocation</AllocationRule>
</WorkOrder>
</WorkOrders>
The schema:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="WorkOrderDownload" targetNamespace="http://www.asdf.com/asdfNET/Interface" elementFormDefault="qualified" xmlns="http://www.asdf.com/asdfNET/Interface" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2008">
<xs:include schemaLocation="InterfaceEntity.xsd" />
<xs:element name="WorkOrders" nillable="false" type="WorkOrderList" />
<xs:complexType name="WorkOrderList">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" name="WorkOrder" nillable="true" type="WorkOrder" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="WorkOrder">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="AutoRelease" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="BuildInstructions" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="BuildLocation" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Company" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="DimensionUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="DueDate" type="xs:dateTime" />
<xs:element minOccurs="0" maxOccurs="1" name="Error" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="FinishedItem" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="InterfaceEntity" type="InterfaceEntity" />
<xs:element minOccurs="0" maxOccurs="1" name="InternalWorkOrderNum" type="xs:int" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemClass" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemColor" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemCost">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemDescription" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemHeight">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemLength">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemSize" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemStyle" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ItemValue">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemWeight">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="ItemWidth">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="PlannedUnitBuildTime">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="QtyToBeBuilt">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="QtyUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="RevisionNum">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="VolumeUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Warehouse" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="WeightUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="WOAllocMethod" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="WorkOrderDetails" type="WorkOrderDetailList" />
<xs:element minOccurs="0" maxOccurs="1" name="WorkOrderId" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="WorkOrderDetailList">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="WorkOrderDetail" nillable="true" type="WorkOrderDetail" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="WorkOrderDetail">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="AllocationRule" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="BuildLevel">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="BuildSequence">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="Company" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ComponentItem" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="FromLocation" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="IncQtyAmount" type="xs:double" />
<xs:element minOccurs="0" maxOccurs="1" name="IncQtyEligible" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="IncQtyMinAmount">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="IncQtyType" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="InterfaceEntity" type="InterfaceEntity" />
<xs:element minOccurs="0" maxOccurs="1" name="InternalWorkOrderNum">
<xs:simpleType>
<xs:restriction base="xs:int">
<xs:minInclusive value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="LogisticsUnit" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Lot" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="ParentLogisticsUnit" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="QtyNeededPerItem">
<xs:simpleType>
<xs:restriction base="xs:decimal">
<xs:minInclusive value="1" />
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element minOccurs="0" maxOccurs="1" name="QuantityUm" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1" name="Warehouse" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Schema;
namespace WorkOrderInterfaceValidation
{
class Program
{
static void Main(string[] args)
{
helper h = new helper();
h.main();
}
}
class helper
{
StringBuilder _valErrorMsgs;
public helper()
{
_valErrorMsgs = new StringBuilder();
}
public void main()
{
try
{
string error = "No error";
Console.WriteLine("hello world");
ValidateSchemaWithURI("C:\\Program Files\\software\\asdf\\2010\\Interface\\Input\\ExampleWorkOrder001.xml",
"http://www.asdf.com/asdfNET/Interface",
"\\\\localhost\\asdf\\Schemas\\Interface\\WorkOrderDownload.xsd",
out error
);
error += " err";
Console.WriteLine(error);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
Console.ReadKey();
}
public XmlReader ValidateSchemaWithURI(string inputUri, string targetNamespace, string schemaPath, out string error)
{
//StringBuilder _valErrorMsgs = new StringBuilder();
XmlReader reader = null;
XmlReader reader2;
try
{
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(targetNamespace, schemaPath);
settings.IgnoreWhitespace = true;
settings.ValidationType = ValidationType.Schema;
settings.ValidationFlags = XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler += new ValidationEventHandler(this.SchemaValidationEventHandler);
reader = XmlReader.Create(inputUri, settings);
foreach (var v in settings.Schemas.Schemas())
{
foreach (var e in ((XmlSchema)v).Attributes)
{
e.ToString();
}
}
while (reader.Read())
{
}
reader2 = reader;
}
catch (XmlException exception)
{
_valErrorMsgs.Append(exception.Message).Append(";");
Console.WriteLine(exception.Message);
reader2 = null;
}
finally
{
error = _valErrorMsgs.ToString();
if (reader != null)
{
reader.Close();
}
}
return reader2;
}
private void SchemaValidationEventHandler(object sender, ValidationEventArgs args)
{
this._valErrorMsgs.Append(args.Exception.Message).Append(";");
}
}
}
The error message:
XmlException: Could not find schema information for the element 'WorkOrders'.;Could not find schema information for the element 'WorkOrder'.;Could not find schema information for the element 'Action'.;Could not find schema information for the element 'UserDef1'.;Could not find schema information for the element 'UserDef2'.;Could not find schema information for the element 'UserDef3'.;Could not find schema information for the element 'UserDef4'.;Could not find schema information for the ....
I think you're missing the namespace. Try:
<WorkOrders xmlns="http://www.manh.com/ILSNET/Interface">

Categories

Resources