나는 다음 (errorous) XML을 가지고XSD 검증 문제
<jobs>
<job>
<id>1</id>
<state><![CDATA[IL]]></state>
</job>
<job>
<id>2</id>
</job>
</jobs>
아이디 모두와 항목을 reqired있는 상태 노드를. 나는 그것을 위해 XSD를 썼다 :
<?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>
그리고 그것은 여전히 구조적으로 유효한 XML로 확인합니다. 내가 여기서 무엇을 놓치고 있니?
갱신 1 : 내가 사용 코드는 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 : 서식을 고정 했으므로 닫기 태그가 표시됩니다. 네임 스페이스 때문에 유효하지 않습니다. –
@ 13ren : 헝가리어 자판 배열 + Google 크롬을 사용하면 코드 블록을 삽입 할 수 있으면 행복합니다 .../ – balint
@ 13ren, @ John : 네임 스페이스 선언없이 유효성 검사를 수행하려면 어떻게해야합니까? ? – balint