急!急!xsd中union类型个格式问题. ( 积分: 100 )

  • 主题发起人 fishding
  • 开始时间
F

fishding

Unregistered / Unconfirmed
GUEST, unregistred user!
以下是我的程序代码:
*******************************************************
procedure TForm1.Button5Click(Sender: TObject);
var
xmlobj:TDOMDocument40;
xmlsch:TXMLSchemaCache40;
namespace,xsdname,xmlname:string;
begin
namespace:='urn:records';
xsdname:='XLQ.xsd';
xmlname:='XLQ.xml';
xmlobj := TDOMDocument40.Create(nil);
xmlsch := TXMLSchemaCache40.Create(nil);
xmlsch.DefaultInterface.add(namespace,xsdname);
xmlobj.DefaultInterface.schemas := xmlsch.DefaultInterface;
xmlobj.DefaultInterface.async := False;
xmlobj.DefaultInterface.validateOnParse := True;
xmlobj.DefaultInterface.resolveExternals:=True;
xmlobj.DefaultInterface.load(xmlname);
if xmlobj.DefaultInterface.parseError.errorCode = 0 then
showmessage('格式正确')
else
begin
showmessage('格式错误');
showmessage(xmlobj.DefaultInterface.parseError.reason
+xmlobj.DefaultInterface.parseError.srcText
+' line:'+IntToStr(xmlobj.DefaultInterface.parseError.line)
+' char:'+IntToStr(xmlobj.DefaultInterface.parseError.linepos));
end;
end;

*******************************************************
我在程序运行后出现以下错误:
“sstzclass”/union/ undeclared XSD type:'noneclass'
*******************************************************
我分析是我定义的xsd文件中的联合类型出现问题,但是我仔细检查我的xsd文件,对照
MSXML4.0的文档,我始终无法找到问题所在.请各位高手多多指点。如果可能的话,给我一个使用了union类型定义的xsd文件的示例。谢谢。
我的xsd的内容是:
******************************************************
<?xml version=&quot;1.0&quot;
encoding=&quot;GB2312&quot;?>
<xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;>
<xsd:element name=&quot;records&quot;
type=&quot;recordlist&quot;/>

<!-- Defines the complex type for the &quot;recording&quot;
element.-->
<xsd:complexType name=&quot;onerecord&quot;>
<xsd:attribute name=&quot;zymc&quot;
type=&quot;string1to20&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;flbsm&quot;
type=&quot;long10&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;ssbddw&quot;
type=&quot;long15&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;sstz&quot;
type=&quot;sstzclass&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;sswx&quot;
type=&quot;sswxclass&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;zybh&quot;
type=&quot;long1to15&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;xlqlx&quot;
type=&quot;xlqclass&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;xlqbh&quot;
type=&quot;long1to15&quot;
use=&quot;required&quot;/>
</xsd:complexType>
<!-- Defines the root element for the XML file.-->
<xsd:complexType name=&quot;recordlist&quot;>
<xsd:sequence>
<xsd:element name=&quot;record&quot;
type=&quot;onerecord&quot;
minOccurs=&quot;1&quot;
maxOccurs=&quot;unbounded&quot;/>
</xsd:sequence>
</xsd:complexType>
<!--定义所属台站类型-->
<xsd:simpleType name=&quot;sstzclass&quot;>
<xsd:union memberTypes=&quot;noneclass long15&quot;/>
</xsd:simpleType>
<!--定义所属网系类型-->
<xsd:simpleType name=&quot;sswxclass&quot;>
<xsd:union memberTypes=&quot;noneclass long1to10&quot;/>
</xsd:simpleType>
<!--定义信令区类型-->
<xsd:simpleType name=&quot;xlqclass&quot;>
<xsd:restriction base=&quot;xsd:string&quot;>
<xsd:enumeration value=&quot;主信令区&quot;/>
<xsd:enumeration value=&quot;分信令区&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度小于20的字符串类型-->
<xsd:simpleType name=&quot;string1to20&quot;>
<xsd:restriction base=&quot;xsd:string&quot;>
<xsd:minLength value=&quot;1&quot;/>
<xsd:maxLength value=&quot;20&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度为10的整数类型-->
<xsd:simpleType name=&quot;long10&quot;>
<xsd:restriction base=&quot;xsd:unsigneLong&quot;>
<xsd:minInclusive value=&quot;1000000000&quot;/>
<xsd:maxInclusive value=&quot;9999999999&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度为15的整数类型-->
<xsd:simpleType name=&quot;long15&quot;>
<xsd:restriction base=&quot;xsd:unsigneLong&quot;>
<xsd:minInclusive value=&quot;100000000000000&quot;/>
<xsd:maxInclusive value=&quot;999999999999999&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度小于10的整数类型-->
<xsd:simpleType name=&quot;long1to10&quot;>
<xsd:restriction base=&quot;xsd:unsigneLong&quot;>
<xsd:minInclusive value=&quot;1&quot;/>
<xsd:maxInclusive value=&quot;9999999999&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度小于15的整数类型-->
<xsd:simpleType name=&quot;long1to15&quot;>
<xsd:restriction base=&quot;xsd:unsigneLong&quot;>
<xsd:minInclusive value=&quot;1&quot;/>
<xsd:maxInclusive value=&quot;999999999999999&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义none类型-->
<xsd:simpleType name=&quot;noneclass&quot;>
<xsd:restriction base=&quot;xsd:string&quot;>
<xsd:enumeration value=&quot;none&quot;/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
************************************************************
 
以下是我的程序代码:
*******************************************************
procedure TForm1.Button5Click(Sender: TObject);
var
xmlobj:TDOMDocument40;
xmlsch:TXMLSchemaCache40;
namespace,xsdname,xmlname:string;
begin
namespace:='urn:records';
xsdname:='XLQ.xsd';
xmlname:='XLQ.xml';
xmlobj := TDOMDocument40.Create(nil);
xmlsch := TXMLSchemaCache40.Create(nil);
xmlsch.DefaultInterface.add(namespace,xsdname);
xmlobj.DefaultInterface.schemas := xmlsch.DefaultInterface;
xmlobj.DefaultInterface.async := False;
xmlobj.DefaultInterface.validateOnParse := True;
xmlobj.DefaultInterface.resolveExternals:=True;
xmlobj.DefaultInterface.load(xmlname);
if xmlobj.DefaultInterface.parseError.errorCode = 0 then
showmessage('格式正确')
else
begin
showmessage('格式错误');
showmessage(xmlobj.DefaultInterface.parseError.reason
+xmlobj.DefaultInterface.parseError.srcText
+' line:'+IntToStr(xmlobj.DefaultInterface.parseError.line)
+' char:'+IntToStr(xmlobj.DefaultInterface.parseError.linepos));
end;
end;

*******************************************************
我在程序运行后出现以下错误:
“sstzclass”/union/ undeclared XSD type:'noneclass'
*******************************************************
我分析是我定义的xsd文件中的联合类型出现问题,但是我仔细检查我的xsd文件,对照
MSXML4.0的文档,我始终无法找到问题所在.请各位高手多多指点。如果可能的话,给我一个使用了union类型定义的xsd文件的示例。谢谢。
我的xsd的内容是:
******************************************************
<?xml version=&quot;1.0&quot;
encoding=&quot;GB2312&quot;?>
<xsd:schema xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;>
<xsd:element name=&quot;records&quot;
type=&quot;recordlist&quot;/>

<!-- Defines the complex type for the &quot;recording&quot;
element.-->
<xsd:complexType name=&quot;onerecord&quot;>
<xsd:attribute name=&quot;zymc&quot;
type=&quot;string1to20&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;flbsm&quot;
type=&quot;long10&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;ssbddw&quot;
type=&quot;long15&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;sstz&quot;
type=&quot;sstzclass&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;sswx&quot;
type=&quot;sswxclass&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;zybh&quot;
type=&quot;long1to15&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;xlqlx&quot;
type=&quot;xlqclass&quot;
use=&quot;required&quot;/>
<xsd:attribute name=&quot;xlqbh&quot;
type=&quot;long1to15&quot;
use=&quot;required&quot;/>
</xsd:complexType>
<!-- Defines the root element for the XML file.-->
<xsd:complexType name=&quot;recordlist&quot;>
<xsd:sequence>
<xsd:element name=&quot;record&quot;
type=&quot;onerecord&quot;
minOccurs=&quot;1&quot;
maxOccurs=&quot;unbounded&quot;/>
</xsd:sequence>
</xsd:complexType>
<!--定义所属台站类型-->
<xsd:simpleType name=&quot;sstzclass&quot;>
<xsd:union memberTypes=&quot;noneclass long15&quot;/>
</xsd:simpleType>
<!--定义所属网系类型-->
<xsd:simpleType name=&quot;sswxclass&quot;>
<xsd:union memberTypes=&quot;noneclass long1to10&quot;/>
</xsd:simpleType>
<!--定义信令区类型-->
<xsd:simpleType name=&quot;xlqclass&quot;>
<xsd:restriction base=&quot;xsd:string&quot;>
<xsd:enumeration value=&quot;主信令区&quot;/>
<xsd:enumeration value=&quot;分信令区&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度小于20的字符串类型-->
<xsd:simpleType name=&quot;string1to20&quot;>
<xsd:restriction base=&quot;xsd:string&quot;>
<xsd:minLength value=&quot;1&quot;/>
<xsd:maxLength value=&quot;20&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度为10的整数类型-->
<xsd:simpleType name=&quot;long10&quot;>
<xsd:restriction base=&quot;xsd:unsigneLong&quot;>
<xsd:minInclusive value=&quot;1000000000&quot;/>
<xsd:maxInclusive value=&quot;9999999999&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度为15的整数类型-->
<xsd:simpleType name=&quot;long15&quot;>
<xsd:restriction base=&quot;xsd:unsigneLong&quot;>
<xsd:minInclusive value=&quot;100000000000000&quot;/>
<xsd:maxInclusive value=&quot;999999999999999&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度小于10的整数类型-->
<xsd:simpleType name=&quot;long1to10&quot;>
<xsd:restriction base=&quot;xsd:unsigneLong&quot;>
<xsd:minInclusive value=&quot;1&quot;/>
<xsd:maxInclusive value=&quot;9999999999&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义长度小于15的整数类型-->
<xsd:simpleType name=&quot;long1to15&quot;>
<xsd:restriction base=&quot;xsd:unsigneLong&quot;>
<xsd:minInclusive value=&quot;1&quot;/>
<xsd:maxInclusive value=&quot;999999999999999&quot;/>
</xsd:restriction>
</xsd:simpleType>
<!--定义none类型-->
<xsd:simpleType name=&quot;noneclass&quot;>
<xsd:restriction base=&quot;xsd:string&quot;>
<xsd:enumeration value=&quot;none&quot;/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
************************************************************
 
为什么没有人回答,我也很想知道原因。请各位大侠多多指点。
 
楼主,我在网上找到你发的另外一个帖子,也是没人回答,不过我很感兴趣,但是对这个东西不熟悉,我特意导入了XML40的控件,你上面贴的是xsd的文件,还需要另外一个xml的文件,贴全了一定有很多人关注的
------------------------------------

现在的问题是你的XSD的定义问题
我查到的资料是http://www.ddvip.net/web/xml/index2/34.htm
------------------------------
union(联合)类型表示在XML实例文档中的元素实例符合union类型定义的成员类型中的一种就可以了(合法),这一点和C++中的联合类型有类似的概念,如:
<xsd:simpleType name=&quot;addrUnion&quot;>
<xsd:union memberTypes=&quot;xsd:string integer&quot;/>
</xsd:simpleType>
---------------------------
和官方文档
http://www.w3.org/TR/xmlschema-2/ ,这里有介绍数据类型的,我想楼主是想自定义数据类型,其实自带的基本上都能满足要求了。另外没有发现noneclass,不知道楼主是想定义什么类型,
http://www.w3.org/TR/xmlschema-2/#union-datatypes
其中http://www.w3.org/TR/xmlschema-2/type-hierarchy.gif
是xml数据类型的继承图,供参考
-------------------
希望对楼主有参考价值,下面是我修改的内容
<!--定义所属台站类型-->
<xsd:simpleType name=&quot;sstzclass&quot;>
<xsd:union memberTypes=&quot;xsd: long&quot;/>
</xsd:simpleType>
<!--定义所属网系类型-->
<xsd:simpleType name=&quot;sswxclass&quot;>
<xsd:union memberTypes=&quot;xsd: long&quot;/>
</xsd:simpleType>
 
顶部