Meaningless Drivel is fun!*
The moose likes XML and Related Technologies and the fly likes question regarding XML Namespaces/Schema Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "question regarding XML Namespaces/Schema" Watch "question regarding XML Namespaces/Schema" New topic
Author

question regarding XML Namespaces/Schema

m faruqui
Greenhorn

Joined: Dec 06, 2001
Posts: 9
Hi Folks,
I have a question regarding XML Namespaces/Schema.
I saw a SOAP message containing a response. (The message fragment is given below). The puzzling thing about it was that the response represented a Java HashMap, whose schema was at "http://idoox.com/containers". My Question is
Does the parser need to download the schema from the Web Site?
If so, it seems terribly expensive to keep making so many additional HTTP connections. If not, how is it obtained? I also understand that not all the Namespace URIs point to actual documents, making it all the more confusing!
Please help if possible,
Thanks!
m faruqui

<response xsi:type="ns1:HashMap" xmlns:ns1="http://idoox.com/containers">
<item>
<key xsi:type="xsd:long">1006209071080</key>
<value
....
</value>
</item>
</response>
YanNaing WTint
Ranch Hand

Joined: Oct 30, 2001
Posts: 40
Hi m faruqui,
The puzzling thing about it was that the response represented a Java HashMap, whose schema was at "http://idoox.com/containers".<response xsi:type="ns1:HashMap" xmlns:ns1="http://idoox.com/containers">
As far as I know namespace/schema doesn't really concern with XML parser but validator.
"xmlns:" means the decleration of namespace, not schema.
To specify the schema location for XML validator, at the root node of the instance document, use "xsi:schemaLocation" where xsi is the name space to other URL (for unique namespace) like xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance".
This schemaLocation is just a hint to the XML parser.
The namespace specification is only for uniqueness. At the mean time, schemaLocation needs to specify exact schema file Location.
<RootElement xmlns="http://www.mySvr.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mySvr.com
mySchemaFile.xsd">
<!-- elements -->
</RootElement>
Hope it helps!!


Yan Naing Wynn Tint (SCJP2, SCWCD)
YanNaing WTint
Ranch Hand

Joined: Oct 30, 2001
Posts: 40
One thing left.
For XML Schema compliant parser, what I was said,"schema doesn't really concern with XML parser ", is not right.
m faruqui
Greenhorn

Joined: Dec 06, 2001
Posts: 9
Thanks Yan Naing!
I understand the schemaLocation attribute now. But I am still confused about this - Consider any schema that defines a target namespace. Now consider an instance documant that defines an element of a type found in the target namespace mentioned earlier.
I understand that if schemaLocation is not used, there is no relation between the schema and the instance even though the instance uses the namespace that was the target of the schema.
My Question - Is is possible then, for an application to look up a schema and validate an instance document against it (in the absence of the schemaLocation attribute). I suspect that this is done in SOAP where I see WSDL documents with schemas but the actual SOAP messages do not have and schemaLocation attributes.
Thanks
m faruqui
YanNaing WTint
Ranch Hand

Joined: Oct 30, 2001
Posts: 40
m faruqui,
You may be right for the applicate that doesn't aware of namespace.
I understand that if schemaLocation is not used, there is no relation between the schema and the instance even though the instance uses the namespace that was the target of the schema
Yes, it is definitely possible for an application that validate the XML document.
Consider this, it is possible to validate the XML schema defination file which does not specify any schemaLocation (schemas for schemas) or DTD. I think it is depend on the parser/validator and the schema or DTD that is used by the parser/validator. There are many validators that can validate XML document against with specified XML schema.
My Question - Is is possible then, for an application to look up a schema and validate an instance document against it (in the absence of the schemaLocation attribute). I suspect that this is done in SOAP where I see WSDL documents with schemas but the actual SOAP messages do not have and schemaLocation attributes.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: question regarding XML Namespaces/Schema