我有一个我无法改变的现有命名空间.我需要将元素添加到复杂类型,以便生成的XML如下所示:
原始XML:
<?xml version="1.0"?>
<Book xmlns="http://bookshop.com">
<Author>Frank Herbert</Author>
<Title>Dune</Title>
</Book>
Run Code Online (Sandbox Code Playgroud)
新XML:
<?xml version="1.0"?>
<Book xmlns="http://bookshop.com"
xlmns:custom="http://custombookshop.com>
<Author>Frank Herbert</Author>
<Title>Dune</Title>
<custom:Publisher>Ace</custom:Publisher>
</Book>
Run Code Online (Sandbox Code Playgroud)
我要求自定义元素必须如上所示显示名称空间前缀,并且复杂类型名称不得更改.
这是原始的XSD和我尝试使用重新定义的新XSD.这会有效,还是有更好的方法来实现这一目标?提前感谢您的建议.
原XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://bookshop.com"
targetNamespace="bookshop.com">
<xs:complexType name="Book">
<xs:complexContent>
<xs:sequence>
<xs:element name="Author" type="String32"
minOccurs="1" maxOccurs="1" />
<xs:element name="Title" type="String32"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
我尝试过新的XSD:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://custombookshop.com"
targetNamespace="custombookshop.com">
<xs:redefine schemaLocation="http://bookshop.com">
<xs:complexType name="Book">
<xs:complexContent>
<xs:extension base="Book">
<xs:sequence>
<xs:element name="Publisher" type="String32"
minOccurs="1" maxOccurs="1" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)