Relevant to In XSD I want to specify that an element can only have whitespace content and In XSD how do I allow only whitespace in an element's content?, I have XML data files for which I've created XSD files. After generating the XSD files, and testing them against input, I found that the incoming data files often have a pattern like the following with an element that does not take text:
<source
id="UGCStrain"
name="The Strain Complex"
abbrev="The Strain">
</source>
Currently, my XSD has a lot of elements like the following that have attributes, and sometimes children, but don't use embedded text:
<xs:element name="source">
<xs:complexType>
<xs:attribute name="id" use="required" type="uniqueID"/>
<xs:attribute name="name" use="required" type="xs:string"/>
<xs:attribute name="abbrev" type="xs:string" default=""/>
<xs:attribute name="description" type="xs:string" default=""/>
</xs:complexType>
</xs:element>
Others have text that I want to retain (and which is, in some cases, required). For example, this expression to indicate certain tagged elements need to be added:
<enmasse
stage="init">
component.Skill
</enmasse>
with corresponding XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="autotag">
<xs:complexType>
<xs:attribute name="group" use="required"/>
<xs:attribute name="tag" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="enmasse">
<xs:complexType mixed="true">
<xs:sequence minOccurs="0">
<xs:element maxOccurs="1" ref="autotag"/>
</xs:sequence>
<xs:attribute name="stage" use="required"/>
</xs:complexType>
</xs:element>
</xs:schema>
As per the two linked questions, it is possible to create a type that allows for whitespace only text without raising an error, but it requires every such element to be given that type. Is there any way to just make it work for every element such that, if it's a complextype without 'mixed="true"', it allows for whitespace "text"?
If it's relevant, I'm doing the XSD validation with the Python xmlschema library.