我試圖從XSD擴展複雜類型面臨的一個問題擴展XML複雜類型。關鍵是這 - 複合型我想實現是一個命名空間,這同一個命名空間設置爲父母的targetNamespace
。無法與父類型命名空間中的
這裏是父XSD(相關部分)
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:tns="http://schemas.mandiant.com/2010/ioc"
elementFormDefault="qualified"
targetNamespace="http://schemas.mandiant.com/2010/ioc"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="ioc" nillable="true"
type="tns:IndicatorOfCompromise" />
<xs:complexType name="IndicatorOfCompromise">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1"
name="short_description" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1"
name="description" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1"
name="keywords" type="xs:string" />
<xs:element minOccurs="0" maxOccurs="1"
name="authored_by" type="xs:string" />
<xs:element minOccurs="1" maxOccurs="1"
name="authored_date" nillable="true"
type="xs:dateTime" />
<xs:element minOccurs="0" maxOccurs="1"
name="links" type="tns:ArrayOfLink" />
<xs:element minOccurs="0" maxOccurs="1"
name="definition" type="tns:ArrayOfIocIndicator" />
</xs:sequence>
<xs:attribute name="id" type="xs:string" />
<xs:attribute name="last-modified" type="xs:dateTime"
use="required" />
</xs:complexType>
</xs:schema>
這是我正在努力擴大(主要添加一些更多的元素),它
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://schemas.mandiant.com/2010/ioc" >
<xs:import namespace="urn:tns"
schemaLocation="openioc_schema_v10.xsd" />
<xs:redefine schemaLocation="openioc_schema_v10.xsd">
<xs:complexType name="IndicatorOfCompromise">
<xs:complexContent>
<xs:extension base="tns:IndicatorOfCompromise">
<xs:sequence>
<xs:element name="category" type="xs:string" />
<xs:element name="family" type="xs:string" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:redefine>
</xs:schema>
當我試圖驗證下面的XML根據該模式,
<?xml version='1.0' encoding='UTF-8'?>
<ioc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.mandiant.com/2010/ioc"
id="2555192b-186b-441d-bbdd-1d2fb41f462f"
last-modified="2016-05-12T12:14:50"
xmlns:qioc_v10="ioc_qualys_v10.xsd"
xsi:schemaLocation="ioc_qualys_v10.xsd">
<short_description>Bagsu!rfn</short_description>
<description>This is a placeholder for description of the Bagsu!rfn malware family.</description>
<keywords/>
<authored_by>IOC_api</authored_by>
<authored_date>2016-05-12T12:14:50</authored_date>
<qioc_v10:category>XYZ</qioc_v10:category>
<qioc_v10:family>XYZ 2</qioc_v10:family>
<links/>
</ioc>
它提供了一個錯誤「的命名空間屬性,:一個電子的「甕TNS的, lement信息項必須與導入文檔的targetNamespace屬性'http://schemas.mandiant.com/2010/ioc'相同。「
如何去呢?我已經通過了幾個Stackoverflow的帖子,但似乎沒有解決我的難題。我已經理解了我需要擴展的元素駐留在命名空間中,但沒有得到解決的辦法。
請注意,我不能觸到父XSD以任何方式。這是OpenIOC標準。