Reputation: 25
I am trying to validate my XML String against an XSD using xmllint but I keep getting this error:
file_0.xml:6: element No: Schemas validity error : Element '{http://www.mrq.gouv.qc.ca/T5}No': [facet 'pattern'] The value 'NP666666' is not accepted by the pattern '(NP|np)d{6}'."
"file_0.xml:6: element No: Schemas validity error : Element '{http://www.mrq.gouv.qc.ca/T5}No': 'NP666666' is not a valid value of the local atomic type.
I actually get 34 errors but they are all alike. Every other part passes but the numbers. My code is on JavaScript and I'm hand-making the objects to pass to XML.
XML :
<P><Annee>2019</Annee>
<TypeEnvoi>1</TypeEnvoi>
<Preparateur><No>NP999999</No>
<Nom1>Garderie Papillons</Nom1>
<Adresse><Ligne1>5 Street name</Ligne1>
<Ville>Toronto</Ville>
<Province>QC</Province>
<CodePostal>G5T6R4</CodePostal>
</Adresse>
</Preparateur>
<NoCertification>RQ-19-99-999</NoCertification>
<NomLogiciel>NomLogiciel</NomLogiciel>
<CourrielResponsable>CourrielResponsable</CourrielResponsable>
<IdPartenaireReleves>1234567891234567</IdPartenaireReleves>
<IdProduitReleves>1234567891234567</IdProduitReleves>
</P>
XSD:
<xsd:element
name="P"
type="PStruct" />
<xsd:complexType
name="PStruct">
<xsd:sequence>
<xsd:element
name="Annee"
type="AnImpositionType">
</xsd:element>
<xsd:element
name="TypeEnvoi"
type="Indicateur1-4-6Type">
</xsd:element>
<xsd:element
name="Preparateur">
<xsd:complexType>
<xsd:sequence>
<xsd:element
name="No">
<xsd:simpleType>
<xsd:restriction
base="xsd:string">
<xsd:pattern
value="(NP|np)\d{6}" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element
name="Type"
type="Indicateur1-3Type"
minOccurs="0">
</xsd:element>
<xsd:element
name="Nom1"
type="Char30Type">
</xsd:element>
<xsd:element
name="Nom2"
type="Char30Type"
minOccurs="0">
</xsd:element>
<xsd:element
name="Adresse"
type="Adresse2Struct"
minOccurs="0" />
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element
name="Informatique"
type="RessourceStruct"
minOccurs="0">
</xsd:element>
<xsd:element
name="Comptabilite"
type="RessourceStruct"
minOccurs="0">
</xsd:element>
<xsd:element
name="NoCertification">
<xsd:simpleType>
<xsd:restriction
base="xsd:string">
<xsd:pattern
value="RQ-\d{2}-\w{2}-\w{3}" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element
name="NomLogiciel"
type="Char40Type"
minOccurs="0">
</xsd:element>
<xsd:element
name="VersionLogiciel"
type="Char15Type"
minOccurs="0">
</xsd:element>
<xsd:element
name="CourrielResponsable"
type="Char60Type"
minOccurs="0">
</xsd:element>
<xsd:element
name="CourrielLangue"
type="LangueType"
minOccurs="0">
</xsd:element>
<xsd:element
name="IdPartenaireReleves"
type="Char16FixeType">
</xsd:element>
<xsd:element
name="IdProduitReleves"
type="Char16FixeType">
</xsd:element>
<xsd:element
name="NoCasEssai"
type="Char25Type"
minOccurs="0">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
Upvotes: 1
Views: 955
Reputation: 111601
(NP|np)d{6}
matches NPdddddd
or npdddddd
.
You probably meant (NP|np)\d{6}
, which would match digits rather than literal d
letters.
Update based on exchange in comments:
It appears that the XSD was being processed as a string such that the \d{6}
was interpreted as being escaped to just d{6}
prior to being used in validation.
Upvotes: 1