Reputation: 80
If the longest value for a string in my DB is
"ABC<DEF"
should the maxLength restriction for this string datatype in the XSD be 7 (pre-encoding) or should it be 10 (post-encoding), i.e.
"ABC<DEF"
Upvotes: 3
Views: 826
Reputation: 21658
Short answer: pre-encoding.
Encoding characters in XML doesn't affect the "real" length value of the string.
Quick test:
<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="http://tempuri.org/XMLSchema.xsd" elementFormDefault="qualified" xmlns="http://tempuri.org/XMLSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="root">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="2"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:schema>
Valid XML :)
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/XMLSchema.xsd">&1</root>
Upvotes: 2