- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在学习 XML 和 XSD,但遇到了问题。我想使用以下 XSD 文档验证以下 XML 文档。因为属性“id”用于两个不同的元素。我想将他的定义与 store 和 client 的定义分开,然后在其上使用 ref 。不幸的是,Netbeans 似乎忽略了属性上的引用,或者我做错了,因为当我检查文件 store.xml 时,出现以下错误:
XML validation started.
Checking file:/Users/toto/NetBeansProjects/Cookbook/src/java/store.xml...
Referenced entity at "file:/Users/strokyl/NetBeansProjects/Cookbook/src/java/store.xsd".
cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'client'. [14]
cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'client'. [19]
cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'client'. [24]
cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'product'. [32]
cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'product'. [39]
cvc-complex-type.3.2.2: Attribute 'id' is not allowed to appear in element 'product'. [46]
<xs:attribute ref="id"/>
通过client和store上id属性的定义,xml正确有效!
<?xml version="1.0" encoding="UTF-8"?>
<!--
Document : store.xml.xml
Created on : 12 novembre 2013, 22:09
Author : strokyl
Description:
Purpose of the document follows.
-->
<store xmlns="http://etud.insa-toulouse.fr/~duzan/store"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation='http://etud.insa-toulouse.fr/~duzan/store store.xsd'>
<clients>
<client id="1">
<first_name>Luc</first_name>
<last_name>Duzan</last_name>
<age>22</age>
</client>
<client id="2">
<first_name>Adrien</first_name>
<last_name>Gareau</last_name>
<age>22</age>
</client>
<client id="3">
<first_name>Gilles</first_name>
<last_name>Roudière</last_name>
<age>22</age>
</client>
</clients>
<products>
<product id="1">
<name>Poster de Maxime Médard</name>
<!-- You don’t have to use same convention that you use for relational database -->
<categorie>Poster</categorie>
<price>10</price>
<number_in_stock>100</number_in_stock>
</product>
<product id="2">
<name>Poster de Yannick Jauzion</name>
<categorie>Poster</categorie>
<price>10</price>
<number_in_stock>200</number_in_stock>
</product>
<product id="3">
<name>Drapeau du stade toulousain</name>
<categorie>drapeau</categorie>
<price>5</price>
<number_in_stock>500</number_in_stock>
</product>
</products>
</store>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://etud.insa-toulouse.fr/~duzan/store"
xmlns="http://etud.insa-toulouse.fr/~duzan/store"
elementFormDefault="qualified">
<xs:element name="store">
<xs:complexType>
<xs:sequence>
<xs:element ref="clients"/>
<xs:element ref="products"/>
<xs:any/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- Definition très exposé de clients -->
<xs:element name="first_name" type="xs:string"/>
<xs:element name="last_name" type="xs:string"/>
<xs:element name="age">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="120"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:attribute name="id" type="xs:integer"/>
<xs:complexType name="client_type">
<xs:sequence>
<xs:element ref="first_name"/>
<xs:element ref="last_name"/>
<xs:element ref="age"/>
</xs:sequence>
<xs:attribute ref="id"/>
</xs:complexType>
<xs:element name="client" type="client_type"/>
<xs:complexType name="clients_type">
<xs:sequence>
<xs:element ref="client" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:element name="clients" type="clients_type"/>
<!-- Definition très condensé de product à part qu'on réutilise l'attribut id définit plus tôt -->
<xs:element name="products">
<xs:complexType>
<xs:sequence>
<xs:element name="product" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="categorie" type="xs:string"/>
<xs:element name="price">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="number_in_stock">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute ref="id"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
最佳答案
问题是顶级属性声明采用targetNamespace
。的架构。因此验证器正在寻找一个名为 id
的属性。那是在http://etud.insa-toulouse.fr/~duzan/store
命名空间,但您的文档包含一个名为 id
的属性不在命名空间中(因为默认的 xmlns 声明不适用于属性)。
要对现有架构有效,您需要将前缀绑定(bind)到命名空间并将该前缀用于属性
<store xmlns="http://etud.insa-toulouse.fr/~duzan/store"
xmlns:store="http://etud.insa-toulouse.fr/~duzan/store">
<!-- ... -->
<client store:id="1">
attributeFormDefault
或在特定声明上指定
form
)。因此,另一种选择可能是声明一个带有属性的基类型,然后让您的其他类型扩展它。
<xs:complexType name="identifiedType">
<xs:attribute name="id" type="xs:integer"/>
</xs:complexType>
<xs:complexType name="client_type">
<xs:complexContent>
<xs:extension base="identifiedType">
<xs:sequence>
<xs:element ref="first_name"/>
<xs:element ref="last_name"/>
<xs:element ref="age"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
关于xml - 属性的 ref 不适用于 netbeans 下的复杂类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19966077/
我想读取帖子的数据并获取用户 key ,然后通过它进行搜索并同时获取用户数据,我尝试过,但它后退了一步,直到它才显示用户名我执行任何其他操作 这是帖子和经过身份验证的用户的 Firebase 实时数据
您知道是否有办法将 js ref 和 css ref 作为单个 ref 包含在 html 中?通常这些 ref 单独包含在 html head 中,但我的经理想知道下游消费者是否有一种简化的方法将这些
我正在使用 Swing+Clojure 开发一个 GUI 应用程序,它需要各种可变数据(例如滚动位置、用户数据、文件名、选定的工具选项等)。 我至少可以看到三种不同的处理这组数据的方式: 创建对所有数
我正在尝试通过 React 使用 ref 属性。我的浏览器出现奇怪的错误,但我无法弄清楚问题出在哪里。谁能向我解释一下为什么我会收到此错误: Error: Invariant Violation: a
在我的程序中,我有模板类,这些模板类主要是用于特殊目的 std::function 的包装器。最小的例子是: template class Foo { public: exp
如果被引用为参数的对象在函数中被修改,是否使用 ref 有关系吗?下面两个函数有区别吗? void DisposeObject(ClassThing c) { c.Dispose(); } vo
尝试将大型但线性的 svn 存储库迁移到 git。 svn 存储库没有标准布局(主干、分支、标签)...只有主干的一个目录。 Ubuntu 12.4 LTS,git 1.7.9.5。 $ git sv
您现在如何设置动态引用? 我收到一个错误 cannot set property of 'test' undefined ,如果我使用 this.someRef['test'] = ref;}/>
试图理解 gerrit 中的 refs/for/refs/* 功能。这个问题与 refs/for/master 无关。 我们什么时候可以使用这个 refs/for/refs/* 功能。 有人可以为此解
我以不同的方式调用 4 种方法时得到不同的结果: static void Main(string[] args) { var emp = new Employee { Name = "ABC"
假设我有以下内容: var t = typeof(Foo).MakeByRefType(); 有没有办法将结果转换回typeof(Foo)? 老实说,我发现的唯一方法是: var t = typeof
我以下列方式使用 ref。那么当在第 5 种方法中创建一个新对象时,是否会一直访问 main 方法中的原始 emp 并在那里创建一个新对象? 如果是,有没有一种方法可以实现相同的功能而无需多次迭代,即
我在文档的 html 标签内有一些文本。文字看起来像这样 I need this text <ref> Some unwanted text </ref> I need thi
一些背景: 前几天我遇到了一些事情,这让我开始思考嵌套函数调用中的重载解析。考虑以下代码: #include void printer(const int &a) { std::cout <<
如果直接从 this.refs 获取元素对象,那么为什么要使用 ReactDOM.findDOMNode? var HelloMessage = React.createClass({ click:f
我在这里做错了什么,或者从 C# 7.2 开始,不支持通过 ref 返回并允许设置的索引器? 作品: public ref byte this[int index] { get { r
看来我现在几乎每天都在这里问问题。我不确定这是好事还是坏事... 今天的“WTF flavor ”涉及我在使用来自 NI Measurement Studio 对象的函数时完全和完全无能为力。与我之前
这个问题在这里已经有了答案: Does foreach() iterate by reference? (10 个答案) Alternative to using ref in foreach? (
给定一个函数声明 dynamic DoSomething(dynamic inputObject) 我可以用枚举调用它作为inputObject: MyEnum myEnum; myEnum = Do
如果我将数组传递给函数并在函数内对数组进行更改,则函数外部存在的数组会反射(reflect)这些效果。例如: var myArr = [1, 2, 3]; function popAll(arr) {
我是一名优秀的程序员,十分优秀!