w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
XML Schema: Element with attributes containing "restricted" text only

Your question is more or less a duplicate of this question (just answered it).

Think in these terms:

  • if your element has attributes and/or nested elements, it must be a complex type.
  • if your element can have text, but no markup (nested elements) then it must be of simpleContent
  • simpleContent can only be extended from a simple type (if you need to add an attribute). If you need additional constraints on the simple type, you need to specifically create a new simple type, restricting the base type, then extend that in a simple content.

This post on SO shows you an end-to-end example, of the above explanation. For your particular case:

<?xml version="1.0" encoding="utf-8" ?>
<!-- XML Schema generated by QTAssistant/XSD Module
(http://www.paschidev.com) -->
<xsd:schema elementFormDefault="qualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:simpleType name="tSomeRestrictedText">
        <xsd:restriction base="xsd:string">
            <xsd:pattern value="AAA"/>
        </xsd:restriction>
    </xsd:simpleType>
    <xsd:element name="some_element">
        <xsd:complexType>
            <xsd:simpleContent>
                <xsd:extension base="tSomeRestrictedText">
                    <xsd:attribute name="my_attr" type="xsd:string"/>
                </xsd:extension>
            </xsd:simpleContent>
        </xsd:complexType>
    </xsd:element>
</xsd:schema>




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.