xml - How do I add namespaces to an XSD? -
the following xml , associated xsd:
xml
<?xml version="1.0" encoding="utf-8" ?> <!-- <!doctype people system "validator.dtd"> --> <people xmlns:xsi="http://www.w3c.org/200/10/xmlschema-instance" xsi:nonamespaceschemalocation="student.xsd"> <student> <name>john</name> <course>computer technology</course> <semester>6</semester> <scheme>e</scheme> </student> <student> <name>foo</name> <course>industrial electronics</course> <semester>6</semester> <scheme>e</scheme> </student> </people>
xsd
<?xml version="1.0"?> <xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema"> <xs:element name="people"> <xs:complextype> <xs:sequence> <xs:element name="student" maxoccurs="unbounded"> <xs:complextype> <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="course" type="xs:string" /> <xs:element name="semester"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:enumeration value="1" /> <xs:enumeration value="2" /> <xs:enumeration value="3" /> <xs:enumeration value="4" /> <xs:enumeration value="5" /> <xs:enumeration value="6" /> </xs:restriction> </xs:simpletype> </xs:element> <xs:element name="scheme"> <xs:simpletype> <xs:restriction base="xs:string"> <xs:pattern value = "e|c" /> </xs:restriction> </xs:simpletype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:sequence> </xs:complextype> </xs:element> </xs:schema>
what want add namespace - hypothetical university students belong - say, carnegie mellon.
i know how add namespaces xml document. follows:
xmlns:cmu = "http://www.carnegiemellon.com/ns/students"
, there associated prefixes in xml.
what want know is: how validate xml prefixes using xsd?
my answer here should answer question... still, have consider following:
are people , student in same namespace? if yes, add targetnamespace uri mentioned. otherwise, have add xsd:import, , create new xsd targetnamespace want defines student.
Comments
Post a Comment