微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

XML 架构 - 根元素找不到元素声明

如何解决XML 架构 - 根元素找不到元素声明

概述

我从企业架构软件下载了一个 XML 模式。我想做的一件事是开始开发符合这些以 XML 模式表示的模型的 XML 文件

问题

在 XML 文件中,我链接到架构。但是我收到错误 cannot find the declaration of element。模式中的根元素是 <xs:complexType name="Product">,但是我注意到它有一个名为 annotation 的兄弟元素,但没有给它命名。我仍然尝试使用此注释作为根,但遇到了同样的问题。

我还尝试使用“产品类型”作为根元素作为架构中类型元素的第一个标签,但也遇到了同样的错误。好像知道的元素可以作为root使用。

问题

在这里做错了什么?我无法更改架构,因为这是软件的输出

架构

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://www.w3schools.com/product"
    elementFormDefault="qualified"
    xmlns="http://www.w3schools.com/product product.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:annotation>
        <xs:documentation>The Product defines the product(s) which are in focus for the Integrated Product Support (IPS) program. Once defined,a Product will then come in one or many Product variants. </xs:documentation>
    </xs:annotation>
    <xs:complexType name="Product">
        <xs:annotation>
            <xs:documentation>Product is &lt;&lt;class&gt;&gt; that represents a family of items which share the same underlying design purpose.</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="productIdentifier" minOccurs="1" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>productIdentifier is an identifier that establishes a unique designator for a Product and to differentiate it from other instances of Product.</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="productName" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>productName is a name by which the Product is kNown and can be easily referenced.</xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="Productvariant" minOccurs="1" maxOccurs="unbounded"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Productvariant">
        <xs:annotation>
            <xs:documentation>A productvariant is a &lt;&lt;class&gt;&gt; that defines a member of a Product family which is configured for a specific purpose and is made available to the market.</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="productvariantIdentifier" minOccurs="1" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>productvariantIdentifier is an identifier that establishes a unique designator for a Productvariant and to differentiate it from other instances of Productvariant. </xs:documentation>
                </xs:annotation>
            </xs:element>
            <xs:element name="productvariantName" minOccurs="0" maxOccurs="unbounded">
                <xs:annotation>
                    <xs:documentation>productvariantName is a name by which the Productvariant is kNown and can be easily referenced.</xs:documentation>
                </xs:annotation>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

XML

<?xml version="1.0" encoding="utf-8"?>
<Product xmlns="http://www.w3schools.com/product"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://www.w3schools.com/product product.xsd">
</Product>

注意

xml 和 .xsd 文件都在同一个文件夹中。

解决方法

您是说某些生产软件在生产架构中使用命名空间 http://www.w3schools.com/product 吗?这是一个非常令人震惊的设计选择。

这是一个非常奇怪的模式,因为它没有定义全局元素声明。因此,编写有效 XML 的唯一方法是让根元素包含一个 xsi:type 属性,该属性引用全局类型声明之一:例如

<Widget xsi:type="p:Product" xmlns:p="http://www.w3schools.com/product">  
  <p:productIdentifier>...

有一些众所周知的模式使用这种方法,例如 FPML,但它非常不寻常,在我看来是有问题的。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?