【发布时间】:2016-08-23 11:59:08
【问题描述】:
我在尝试从 XSD 扩展复杂类型时遇到问题。症结在于——我试图实现的复杂类型在一个命名空间中,并且这个相同的命名空间被设置为父级的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>
它给出错误“元素信息项的命名空间属性'urn:tns'必须与导入文档的目标名称空间属性'http://schemas.mandiant.com/2010/ioc'相同。”
该怎么做呢?我已经阅读了几篇关于此的 Stackoverflow 帖子,但似乎没有一个可以解决我的难题。我已经理解我需要扩展的元素驻留在命名空间中但不知道如何修复它的问题。
请注意,我不能以任何方式触摸父 xsd。这是OpenIOC 标准。
【问题讨论】: