我尝试了解如何将扩展(“扩展”)XML模式元素转换为原始元素的形式。该示例场景如下:使用XQuery从XML模式类型转换为其他使用
<?xml version="1.0" encoding="UTF-8"?>
<schema targetNamespace="http://www.example.com/address"
xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:add="http://www.example.com/address"
elementFormDefault="qualified">
<complexType name="Address">
<sequence>
<element name="name" type="string"/>
<element name="street" type="string"/>
<element name="city" type="string"/>
</sequence>
</complexType>
<complexType name="UKAddress">
<complexContent>
<extension base="add:Address">
<sequence>
<element name="postcode" type="ipo:UKPostcode"/>
</sequence>
<attribute name="exportCode" type="positiveInteger" fixed="1"/>
</extension>
</complexContent>
</complexType>
<simpleType name="UKPostcode">
<restriction base="string">
<pattern value="[A-Z]{1,2}[0-9R][0-9A-Z]? [0-9][A-Z]{2}"/>
</restriction>
</simpleType>
<element name="UKAddress" type="add:UKAddress" />
<element name="Address" type="add:Address" />
</schema>
这是架构,我尝试transfrom此:
<UKAddress xmlns="http://www.example.com/address" exportCode="1">
<name>Address1</name>
<street>Example street</street>
<city>London</city>
<postcode>AA00 0AA</postcode>
</UKAddress>
进入这个:
<UKAddress xmlns="http://www.example.com/address">
<name>Address1</name>
<street>Example street</street>
<city>London</city>
</UKAddress>
不宜与改造所有的孩子元素一个接一个(这个效果很好),但是使用了一些通用的方法,比如cast。重点是以某种方式使用地址元素的继承类结构,并避免地图(Xquery)和叶元素之间的高度耦合。我试图找到一些强制转换功能,但这些是针对基元的,我尝试使用xsi:type,并试图询问所有的子元素,并对它们进行过滤。我发现没有工作方式。有人遇到过吗?谢谢!