XSD: How do I import a data type from another XSD?
I have the following start of an XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:no="http://www.sychophants.com">
<xs:import namespace="http://www.sychophants.com" s开发者_如何学GochemaLocation="current_obs.xsd"/>
...and then some other definitions...
<xs:element name="noInDatPletd" ref="no:in_dat"/>
Where in_dat exists in a schema written by another organization. What I essentially want to do us create a schema that will contain an element of the in_dat type that is defined in the other ogranization's XSD.
Am I even close to having this correct? I'm pretty new to XML.
I keep getting
http://location_of_my_xsd/temp.xsd:79:9: Invalid: Undefined element
no{http://www.sychophants.com}:in_dat referenced from content model
from http://www.w3.org/2001/03/webdata/xsv, which is a schema validator.
Thanks.
edit: Thanks to the two of you who replied. The problem appears to be that the other organization did not define a targetNamespace attribute in their schema. The result is that I cannot import the namespace into my schema, which means I cannot use the type provided.
I had to copy/paste the code, which is what I wanted to avoid... but you can't have everything you want, I guess.
I see only one obvious error: you use ref="no:in_dat"
for referencing a type. You should use type="no:in_dat"
there. ref
would reference a global element (and should not be used together with the
name
attribute).
Apart from that, have you passed the external schema to the validator beside your own schema? It is of course needed to validate with your schema.
Besides changing ref= to type=, your schema definition looks correct. From the error message, I'm guessing that the schema validator is not able to load the current_obs.xsd from the schemaLocation provided, which would make sense. The validator would have no way of verifying whether there is a type called in_dat since it could not import the schema.
精彩评论