I've never used XML schemas before, though I know what their purpose is for. I did some research into how to write one, and I've got everything done I think. The problem is that I don't understand the purpose of a namespace, or if I even need to use one given the extremely small scope of my project. I'm not using this for some web service; its only purpose is to validate the structure of an XML document stored locally for use with an application I'm writing.
Here's my XSD file:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
targetNamespace="XMLSchema1.xsd"
elementFormDefault="qualified"
xmlns="XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>
<xs:complexType name="ingredient">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="amount" type="xs:string" use="required"/>
<xs:attribute name="format" type="xs:string"/>
<xs:attribute name="calories" type="xs:positiveInteger"/>
<xs:attribute name="fat" type="xs:positiveInteger"/>
<xs:attribute name="sodium" type="xs:positiveInteger"/>
<xs:attribute name="carbs" type="xs:positiveInteger"/>
<xs:attribute name="protein" type="xs:positiveInteger"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="recipe">
<xs:complexType>
<xs:sequence>
<xs:element name="ingredient" type="ingredient" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="step" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
<xs:element name="tip" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="title" type="xs:string" use="required"/>
<xs:attribute name="yield" type="xs:positiveInteger"/>
<xs:attribute name="preptime" type="xs:string"/>
<xs:attribute name="cooktime" type="xs:string"/>
<xs:attribute name="description" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:schema>
When I wrote the XSD file using visual studio, it put in as a template targetNamespace="http://tempuri.org/XMLSchema1.xsd"
. I don't have, nor do I need, a web URI for this application. So knowing this, do I even need to bother thinking about namespaces? Or do I just have to structure it differently or something?