Do I need a schema namespace?
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?
agent154
Junior Poster in Training
72 posts since Jul 2009
Reputation Points: 29
Solved Threads: 1
You don't technically need one if your project is never going to be used outside your own software. The default one provided will suffice, you don't need to restructure anything. However, providing a namespace is painless and correct but the final choice is up to you.
hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 167