This should do it (you may want to restrict names further than to xs:string
):
<?xml version="1.0" encoding="utf-8"?>
<!-- Remember to change namespace name with your own -->
<xs:schema
targetNamespace="http://tempuri.org/XMLSchema1.xsd"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root" type="Container"/>
<xs:element name="Directory" >
<xs:complexType>
<xs:complexContent>
<xs:extension base="Container">
<xs:attribute name="Name" type="xs:string" use="required"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="TextFile">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="Name" use="required"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:complexType name="Container">
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element ref="Directory"/>
<xs:element ref="TextFile"/>
</xs:choice>
</xs:complexType>
</xs:schema>
Tested on:
<?xml version="1.0" encoding="utf-8" ?>
<Root xmlns="http://tempuri.org/XMLSchema1.xsd">
<Directory Name="SomeName">
<TextFile Name="ExampleDocument.txt">This is the content of my sample text file.</TextFile>
<Directory Name="SubDirectory">
</Directory>
<TextFile Name="hej">
</TextFile>
</Directory>
<TextFile Name="file.txt"/>
</Root>