Re: Using XML Schema in local directory

Hi Carter,

> I would like to ask if I have a XML schema (let say put in
> c:\schema\schema.xsd), can I set the above path in the namespace of
> the XML file I would like to validate and then parse the file?

To link from the instance XML document to the schema document, you
need to use the xsi:schemaLocation or xsi:noNamespaceSchemaLocation
attributes (depending on whether or not your markup language uses a
namespace).  The xsi:* attributes are all in the namespace
http://www.w3.org/2001/XMLSchema-instance.

So your instance document should look like:

<foo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:noNamespaceSchemaLocation="file:///C:/schema/schema.xsd">
...
</foo>

Or something like:

<foo xmlns="http://www.example.com/"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://www.example.com/
                         file:///C:/schema/schema.xsd">
...
</foo>

And if the latter then the xs:schema element in the schema at
schema.xsd should have a targetNamespace attribute equal to
'http://www.example.com/' (the namespace of the foo element).

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/

Received on Wednesday, 12 December 2001 14:20:46 UTC