对以下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">
<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 定义额外属性(即&#39; second&#39;)?我想像这样创建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>
答案 0 :(得分:0)
试试这种方式......
<?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>
我希望我已经向你提供了有关你问题的所有答案。