在XSD中,为另一个XSD中定义的类型定义一个属性
对以下xsd进行成像:在XSD中,为另一个XSD中定义的类型定义一个属性,xsd,Xsd,对以下xsd进行成像: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Something" xmlns="http://www.example.org/Something" elementFormDefault="qualified">
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Something" xmlns="http://www.example.org/Something"
elementFormDefault="qualified">
<xs:complexType name="SomethingType">
<xs:attribute name="first" type="xs:string" />
</xs:complexType>
<xs:element name="Something" type="SomethingType"/>
...
</xs:schema>
...
。。。而且
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Extension" xmlns="http://www.example.org/Extension"
xmlns:sth="http://www.example.org/Something" elementFormDefault="qualified">
<xs:import namespace="http://www.example.org/Something"
schemaLocation="Something.xsd" />
</xs:schema>
如何在扩展模式中为SomethingType定义额外的属性(即“second”)?我想创建如下xml:
<?xml version="1.0" encoding="UTF-8"?>
<sth:Root xmlns:sth="http://www.example.org/Something" xmlns:ext="http://www.example.org/Extension">
<sth:Something
sth:first="foo"
ext:second="bar"/>
</sth:Root>
试试这个方法
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/Something" xmlns="http://www.example.org/Something"
elementFormDefault="qualified">
<xs:complexType name="SomethingType">
<xs:attribute name="first" type="xs:string" />
</xs:complexType>
</xs:schema>
和
我希望我已经给了你关于你的问题的所有答案。你解决这个问题了吗?
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/Extension" xmlns="http://www.example.org/Extension"
xmlns:sth="http://www.example.org/Something" elementFormDefault="qualified">
<xs:import namespace="http://www.example.org/Something" schemaLocation="Something.xsd" />
<xs:complexType name="SomethingTypeSecond">
<xs:complexContent>
<xs:extension base="sth:SomethingType">
<xs:attribute name="second" type="xs:string" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>