xml - What does targetNamespace do ? Am I getting it right? -
here <schema> tag of xsd:
<xs:schema xmlns:xs="http://www.w3.org/2001/xmlschema" xmlns="http://www.cmu.edu/ns/blank" targetnamespace="http://www.cmu.edu/ns/blank" elementformdefault="qualified"> if understanding correct, here means:
http://www.w3.org/2001/xmlschema namespace http://www.cmu.edu/ns/blank namespace http://www.cmu.edu/ns/blank namespace elementformdefault qualified question1: understanding correct. if not, wrong ?
question2 @ undermentioned xml instance:
<people xmlns="http://www.cmu.edu/ns/blank" xmlns:xsi="http://www.w3c.org/2001/xmlschema-instance" xsi:schemalocation="http://www.cmu.edu/ns/blank student.xsd" > <student> <name>john</name> <course>computer technology</course> <semester>6</semester> <scheme>e</scheme> </student> </people> here everything belongs http://www.cmu.edu/ns/blank namespace including <student> , elements contained within because of elementformdefault. correct?
question3
now, want add <student> various universities. prefixes berk berkley, harv harvard, etc. each <student> has different set of elements within. , want validate that. how possible?
(1) first 2 points ok; third one:
all elements within xml instance not have prefix automatically belong http://www.cmu.edu/ns/blank namespace elementformdefault qualified
is incorrect.
declaring prefix in schema doesn't mean xml instance must use same prefixes. namespace declaration in xsd file, applies xml file xsd (xsd xml, therefore...)
in general, there no way assume prefixed or un-prefixed element name; i.e. below examples correct.
<some xmlns="" .../> <some xmlns="urn:tempuri-org:xsd:1" .../> <x:some xmlns:x="urn:tempuri-org:xsd:1" .../> the sure thing way represent unqualified name through name without prefix (i.e. 1 cannot prefix "empty" namespace).
elementformdefault controls form of element's name, when element declared within content model (i.e. not global).
(2) partially correct. part because of elementformdefault. incorrect. again, xsd 1 schema spec; xml exists , has own rules, irrespective of xsd, or other schema language. rule applies here of xml namespaces, scoping.
(3) have create xsd each namespace; within each namespace, declare student , it's content. xsd defines people import other xsds , reference students appropriately.
so basic setup:
berkeley.xsd
<?xml version="1.0" encoding="utf-8" ?> <!-- xml schema generated qtassistant/xsd module (http://www.paschidev.com) --> <xsd:schema targetnamespace="urn:berkeley-org" xmlns="urn:berkeley-org" elementformdefault="qualified" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <xsd:element name="student"/> </xsd:schema> harvard.xsd
<?xml version="1.0" encoding="utf-8" ?> <!-- xml schema generated qtassistant/xsd module (http://www.paschidev.com) --> <xsd:schema targetnamespace="urn:harvard-org" xmlns="urn:harvard-org" elementformdefault="qualified" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <xsd:element name="student"/> </xsd:schema> people.xsd
<?xml version="1.0" encoding="utf-8" ?> <!-- xml schema generated qtassistant/xsd module (http://www.paschidev.com) --> <xsd:schema targetnamespace="urn:people-org" xmlns="urn:people-org" xmlns:harv="urn:harvard-org" xmlns:berk="urn:berkeley-org" elementformdefault="qualified" xmlns:xsd="http://www.w3.org/2001/xmlschema"> <xsd:import namespace="urn:harvard-org" schemalocation="harvard.xsd"/> <xsd:import namespace="urn:berkeley-org" schemalocation="berkeley.xsd"/> <xsd:element name="people"> <xsd:complextype> <xsd:choice maxoccurs="unbounded"> <xsd:element ref="harv:student"/> <xsd:element ref="berk:student"/> </xsd:choice> </xsd:complextype> </xsd:element> </xsd:schema> the files graph:

a sample xml (shows use of namespaces):
<?xml version="1.0" encoding="utf-8" standalone="yes"?> <!-- sample xml generated qtassistant (http://www.paschidev.com) --> <people xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xmlns:harv="urn:harvard-org" xmlns:berk="urn:berkeley-org" xmlns="urn:people-org"> <harv:student/> <berk:student/> </people> 
Comments
Post a Comment