Вот мой stb20.tp1.01.xsd:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://univ.fr/stb20"
xmlns="http://univ.fr/stb20"
elementFormDefault="unqualified">
<xs:element name="stb">
<xs:complexType>
<xs:all>
<xs:element ref="title"/>
<xs:element ref="version"/>
<xs:element ref="date"/>
<xs:element ref="description"/>
<xs:element ref="client"/>
<xs:element ref="team"/>
<xs:element ref="detail"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="title" type="long128" />
<xs:element name="version" type="xs:double" default="0.1" />
<xs:element name="date" type="xs:date" />
<xs:element name="description" type="long128" />
<xs:element name="client" type="clientType" />
<xs:element name="team" type="teamType" />
<xs:element name="detail" type="detailType" />
<xs:complexType name="clientType" mixed="true">
<xs:sequence>
<xs:element name="entity" type="long32" />
<xs:element name="firstname" type="long32" />
<xs:element name="lastname" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:choice>
<xs:element name="mail" type="mail" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="tel" type="telephoneType" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
<xs:complexType name="teamType" mixed="true">
<xs:sequence>
<xs:element name="person" type="personType" minOccurs="2" maxOccurs="8"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="detailType" mixed="true">
<xs:sequence>
<xs:element name="feature" type="AllFeatureType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="personType" mixed="true">
<xs:sequence>
<xs:element name="firstname" type="members" />
<xs:element name="function" type="long32" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="featureType" mixed="true">
<xs:sequence>
<xs:element name="description" type="long128" />
<xs:element name="priority" type="priorityType" />
<xs:element name="delivery" type="xs:string" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="long32">
<xs:restriction base="xs:string">
<xs:maxLength value="32" />
<xs:pattern value="[a-zA-Z0-9\s\-']*"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="long128">
<xs:restriction base="xs:string">
<xs:maxLength value="128" />
<xs:pattern value="[a-zA-Z0-9\s\.,:;~@\(\)\-'!#?$*=&]*"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="priorityType">
<xs:restriction base="xs:int">
<xs:minInclusive value="0" />
<xs:maxInclusive value="10" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="mail">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9^._-][a-zA-Z0-9._-]*@[a-zA-Z0-9._-]*.[a-zA-Z]{2,3}"/>
<xs:pattern value="^([.][.])"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="members" mixed="true">
<xs:attribute name="gender" type="genderType" use="required"/>
<xs:attribute name="lastname" type="long32" use="optional" />
<xs:attribute name="mail" type="mail" use="required"/>
</xs:complexType>
<xs:complexType name="AllFeatureType" mixed="true">
<xs:complexContent>
<xs:extension base="featureType">
<xs:attribute name="name" type="long32" use="required"/>
<xs:attribute name="section" type="xs:integer" use="required"/>
<xs:attribute name="number" type="xs:integer" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:simpleType name="genderType" final="restriction" >
<xs:restriction base="xs:string">
<xs:enumeration value="M." />
<xs:enumeration value="Mme" />
<xs:enumeration value="Miss" />
<xs:enumeration value="Mrs" />
<xs:enumeration value="Mr" />
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="telephoneType" >
<xs:restriction base="xs:string">
<xs:pattern value="[0-9]{10}|([0-9]{2} ){4} [0-9]{2}|[0-9] ([0-9]{3} ){2} [0-9]{3}|\+33 [0-9] ([0-9]{2} ){3} [0-9]{2}" />
</xs:restriction>
</xs:simpleType>
</xs:schema>
Когда я использую валидатор с моим xmltested:
<?xml version="1.0" encoding="utf-8"?>
<p:stb xmlns:p="http://univ.fr/stb20" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://univ.fr/stb20 stb20.tp1.01.xsd ">
<p:title>str1234</p:title>
<p:version>3.1415926535</p:version>
<p:date>2012-12-13</p:date>
<p:description>str1234</p:description>
<p:client>
<entity>str1234</entity>
<firstname>str1234</firstname>
<lastname>str1234</lastname>
<mail>str1234@fjdj.com</mail>
</p:client>
<p:team>
<person>
<firstname gender="M." lastname="sdlvhfso" mail="str1234@sfvn.cf" />
<function>str1234</function>
</person>
<person>
<firstname gender="M." lastname="jslf" mail="str1234@euh.com" />
<function>str1234</function>
</person>
</p:team>
<p:detail>
<feature name="str1234" section="1234" number="1234">
<description>str1234</description>
<priority>5</priority>
<delivery>2012-12-13</delivery>
</feature>
<feature name="str123fdf4" section="12" number="1">
<description>str1fdz234</description>
<priority>2</priority>
<delivery>2012-12-18</delivery>
</feature>
</p:detail>
</p:stb>
Возвращает, что xml isn ' t valid.
Но я попытался с помощью команды
xmlstarlet val --xsd stb20.tp1.01.xsd xmltested.xml
И он возвращает, что xmltested действителен ...
Это проблема с пространствами имен?
Мой метод с помощью валидатора:
public static boolean validateXMLSchema(String xsd, String xml){
try {
File xsdfile = new File(xsd);
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(xsdfile);
Validator validator = schema.newValidator();
validator.validate(new StreamSource(new File(xml)));
} catch (IOException | SAXException e) {
return false;
}
return true;
}
Я много чего пробовал, но эта ошибка не позволяет мне завершить sh мой сервер отдыха.