Ich habe folgende (errorous) XML:Xsd Validierungsproblem
<jobs>
<job>
<id>1</id>
<state><![CDATA[IL]]></state>
</job>
<job>
<id>2</id>
</job>
</jobs>
sowohl die ID und die Zustandsknoten Elemente werden reqired. Ich schrieb ein XSD für sie:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="importvalidator"
elementFormDefault="qualified"
targetNamespace="http://foo.org/importvalidator.xsd"
xmlns="http://foo.org/importvalidator.xsd"
xmlns:mstns="http://foo.org/importvalidator.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="jobs">
<xs:complexType>
<xs:sequence>
<xs:element name="job" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="id" type="xs:string" minOccurs="1"/>
<xs:element name="state" type="xs:string" minOccurs="1"/>
</xs:all>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Und es bestätigt noch als strukturell gültigen XML-Code. Was fehlt mir hier?
Update1: Der Code, den ich in C#:
XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add("http://foo.org/importvalidator.xsd", "validator.xsd");
XDocument doc = XDocument.Load(fileName);
if (doc == null | doc.Root == null)
{
throw new ApplicationException("xml error: the referenced stream is not xml.");
}
doc.Validate(schemas, (o, e) =>
{
throw new ApplicationException("xsd validation error: xml file has structural problems");
});
@ 13ren: Ich habe seine Formatierung korrigiert, damit die Close-Tags sichtbar sind. Sie haben die richtige Antwort: Es wird nicht wegen des Namensraums überprüft. –
@ 13ren: mit einem ungarischen Tastaturlayout + Google Chrome, bin ich glücklich, wenn ich nur Code-Blöcke einfügen kann ...:/ – balint
@ 13ren, @John: OK, aber wie kann ich eine Validierung ohne Namespace-Deklaration machen ? – balint