Hi Brian,
Since the "experts" have not given their opinion on this, I will give you my own
explanation which I hope may help you to understand what's going on.
Let us start with clarifying your question:
1) good.xml uses an explicit prefix "ex" for namespace "http://www.someone.com/example".
2) bad.xml uses namespace defaulting for the unprefixed elements in the scope of the namespace
declaration for "http://www.someone.com/example".
In case 1, "AnElement" element is unqualified, meaning that there is no default namespace defined for it.
In case 2, "AnElement" element is qualified, meaning that you defined a default namespace for un-prefixed elements, since "AnElement" element is un-prefixed it belongs to namespace "http://www.someone.com/example".
Having qualified names then your schema should have the schema element definition form attribute set to "qualified" ( remember that the default is unqualified).
So with a minor change to your schema:
<xsd:element name="AnElement" form="qualified" type="xsd:string"/>
now bad is a valid document instance ( but good.xml is bad because it is not qualified.)
So I hope it is clear that in you example good.xml does not define a namespace for element
"AnElement" therefore it is unqualified, and in bad.xml it defines a default namespace for
"AnElement".
The Schema by default defines "AnElement" as unqualified.
Cheers,
Jeffrey Rodriguez
IBM Silicon ValleyFrom: Brian Atkins <[EMAIL PROTECTED]> Reply-To: [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Validation fails with targetNamespace == default namespace? Date: Mon, 04 Aug 2003 15:37:46 -0600
Help me understand what I am doing wrong. Here's a small example of two document which, as far as I can tell, conform to the given schema. One (good.xml) uses a default namespace (no prefix), while the other (bad.xml) uses an explicit namespace (prefix='ex').
example.xsd =========== <?xml version="1.0" encoding="UTF-8"?> <xsd:schema targetNamespace='http://www.someone.com/example' xmlns='http://www.someone.com/example' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-Instance' xml:lang="en">
<xsd:element name="Root"> <xsd:complexType> <xsd:sequence> <xsd:element name="AnElement" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
good.xml - target namespace with prefix 'ex' ============================================ <?xml version="1.0" encoding="UTF-8"?> <ex:Root xmlns:ex="http://www.someone.com/example" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.someone.com/example example.xsd"> <AnElement/> </ex:Root>
bad.xml - target namespace as default namespace =============================================== <?xml version="1.0" encoding="UTF-8"?> <Root xmlns="http://www.someone.com/example" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.someone.com/example example.xsd"> <AnElement/> </Root>
Running both document and schema using SAX with schema and validation turned on, I get no errors on "good.xml", but get the following on "bad.xml":
cvc-complex-type.2.4.a: Invalid content starting with element 'AnElement'. One of '{"":AnElement}' is expected.
Any help would be most welcome.
Thanks Brian Atkins -- Brian Atkins [EMAIL PROTECTED] (970) 288-2114 Agilent Technologies 4380 Ziegler Road - MS ISP Ft. Collins, CO 80525
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
