Should the maxLength constraint for a string data type in XSD be based on data before or after encoding?

If the longest value for a row in my DB

"ABC<DEF"

if the maxLength constraint for this string data type in XSD is 7 (precoding) or should be 10 (after encoding), i.e.

"ABC&lt;DEF"
+3
source share
1 answer

Short answer: precoding.

Character encoding in XML does not affect the value of the "real" string length.

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">&amp;1</root>
+2
source

All Articles