Problema con validazione schema

di il
1 risposte

Problema con validazione schema

Ciao a tutti ho qualche problema con la validazione tramite schema allego il codice ed i due file xml ed xsd ,ottengo lo stesso errore anche usando file tratti da esempi su internet quindi penso che l'errore sia proprio mio...
il codice
try {
XmlReaderSettings set = new XmlReaderSettings();
set.ValidationType = ValidationType.Schema;
XmlSchemaSet s = new XmlSchemaSet();
XmlSchema schema = new XmlSchema();
schema.SourceUri = @"C:\Users\gianmarco\documents\visual studio 2015\Projects\BookSamples\BookSamples\XMLFile1.xsd";
s.Add(schema);
set.Schemas = s;
string path = Server.MapPath("XMLEmployees012345.xml");
XmlReader r = XmlReader.Create(path, set);
while (r.Read());
r.Close();
} catch(Exception ex)
{
}

il file xml
<Employees>
<Employee><ID>0</ID><First>Primo</First><Last>Segundo</Last><Salary>2500</Salary></Employee>
<Employee><ID>1</ID><First>Primo</First><Last>Segundo</Last><Salary>2500</Salary></Employee>
<Employee><ID>2</ID><First>Primo</First><Last>Segundo</Last><Salary>2500</Salary></Employee>
<Employee><ID>3</ID><First>Primo</First><Last>Segundo</Last><Salary>2500</Salary></Employee>
<Employee><ID>4</ID><First>Primo</First><Last>Segundo</Last><Salary>2500</Salary></Employee>
</Employees>

il file xsd

<?xml version="1.0" ?>
<xs:schema id="Employees" xmlns:xs="http://www.w3.org/2001/XMLSchem">
<xs:element name="Employees" >
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
<xs:element name="Employee" type="Employee" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="Employee">
<xs:sequence maxOccurs="unbounded">
<xs:element name="ID" type="xs:string" />
<xs:element name="First" type="xs:string" />
<xs:element name="Last" type="xs:string" />
<xs:element name="Salary" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>

l'errore :
Elemento 'Employees' non dichiarato.

ho usato i due file xml ed xsd qua http://www.w3schools.com/xml/schema_complex_indicators.asp ed ho ottenuto lo stesso errore,
grazie in anticipo

1 Risposte

Devi accedere o registrarti per scrivere nel forum
1 risposte