gpt4 book ai didi

java xml SchemaFactory - 使用不同命名空间的导入加载模式

转载 作者:行者123 更新时间:2023-11-30 04:54:23 26 4
gpt4 key购买 nike

我有一个带有以下 header 定义的 xsd 架构

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
targetNamespace="vdv453ger"
xmlns="vdv453ger"
xmlns:siri="http://www.siri.org.uk/siri"
elementFormDefault="unqualified"
attributeFormDefault="unqualified"
version="2.3e">

此文件导入另一个 xsd 文件:

<xsd:import namespace="http://www.siri.org.uk/siri" 
schemaLocation="siri-1.3/siri/siri_all-v1.2.xsd"/>

导入的 xsd 架构具有不同的命名空间:

<xsd:schema xmlns="http://www.siri.org.uk/siri" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:acsb="http://www.ifopt.org.uk/acsb"
xmlns:ns1="http://datex2.eu/schema/1_0/1_0"
targetNamespace="http://www.siri.org.uk/siri"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.2"
id="siri_all">

当我尝试加载架构时:

SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI);
mySchema = sf.newSchema( fileUrla );

抛出异常:

org.xml.sax.SAXParseException: src-include.2.1: The targetNamespace of the referenced schema, currently http://www.siri.org.uk/siri, must be identical to that of the including schema, currently vdv453ger.

它提示 namespace 不同。如何解决这个问题?

最佳答案

错误消息向我表明存在一个您尚未告诉我们的 xsd:include 元素。使用 xsd:import 导入不同命名空间的架构文档,使用 xsd:include 导入同一命名空间的架构文档。

关于java xml SchemaFactory - 使用不同命名空间的导入加载模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9000895/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com