Reputation: 58
I have geneated an XML from an XSD. IntelliJ IDEA finds no errors if I validate XSD, but generated XML is not valid because one field is not facet-valid with respect to a specified pattern.
This XSD element looks like that:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://filmrenting.nure.ua/entity/film/"
xmlns:tns="http://filmrenting.nure.ua/entity/film/"
xmlns:ent="http://filmrenting.nure.ua/entity/"
elementFormDefault="qualified">
<!-- other elements-->
<xsd:simpleType name="Duration">
<xsd:restriction base="xsd:duration">
<xsd:pattern value="[1-9][0-9]{0,2}M"></xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
<!-- other elements-->
</xsd:schema>
And the generated XML looks like that:
<film:film id="3" xmlns:film="http://filmrenting.nure.ua/entity/film/">
<!-- other elements -->
<film:duration>P1Y2M6DT14H25M13S</film:duration> <!-- not valid -->
</film:film>
I checked the pattern and it seems to have no mistakes. Even if I past a correct value to that field afterwards, it's still considered as not-valid. How to fix it?
Upvotes: 1
Views: 772
Reputation: 58
Found a mistake in the pattern. To get minutes only, you need to have "PT" at the beginning of it.
<xsd:simpleType name="Duration">
<xsd:restriction base="xsd:duration">
<xsd:pattern value="PT[1-9][0-9]{0,2}M"></xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
Though IDEA still generates invalid XMLs, if I edit that field with a value like "PT130M", there will be no errors detected by IDE. Java parsers recognize it too.
Upvotes: 0