<attribute ref="...">的xml问题 [英] xml problem with <attribute ref="...">

查看:31
本文介绍了<attribute ref="...">的xml问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 xml 架构

i have an xml schema

<xs:complexType>
...
<xs:attribute ref="unaryOperator"></xs:attribute>
</xs:complexType>


<xs:attribute name="unaryOperator">

我尝试在我的 xml 文件中使用它像这样

i try to use it in my xml file like this

  <inv_constraint unaryOperator="not">

编辑器给了我这个错误:

The editor gives me this error:

描述资源路径位置类型[Xerces] cvc-complex-type.3.2.2:属性unaryOperator"不允许出现在元素inv_constraint"中.@see:http://www.w3.org/TR/xmlschema-1/#cvc-complex-type abc.xml/prova line 28 XML 问题

Description Resource Path Location Type [Xerces] cvc-complex-type.3.2.2: Attribute 'unaryOperator' is not allowed to appear in element 'inv_constraint'. @see: http://www.w3.org/TR/xmlschema-1/#cvc-complex-type abc.xml /prova line 28 XML Problem

编辑建议我这样做

<inv_constraint xmlns:ns1="http://abc/abcd" ns1:unaryOperator="not" >

如果我不在 xml 架构中使用 ref 并且只是复制粘贴属性而不是引用它,那么我的 xml 文件就可以工作了,

if i don't use the ref in the xml schema and just copy paste the attribute instead of referencing it, then my xml file works,

所以我的问题是如何在没有那个奇怪标签的情况下使我的 xml 有效并将 ref 保留在 xml 架构中?

so my question is how can i make valid my xml without that weird tag and keep the ref in the xml schema?

推荐答案

我看不出这里有任何问题.以下对我来说很好用:

I don't see any problem here. The following works fine for me:

schema.xsd:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="ct">
    <xs:attribute ref="unaryOperator"/>
</xs:complexType>

<xs:attribute name="unaryOperator"/>

<xs:element name="inv_constraint" type="ct"/>

</xs:schema>

file.xml:

<?xml version="1.0"?>
<inv_constraint unaryOperator="non" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema.xsd"></inv_constraint>

我已经在 Xerces、Saxon、XSV 和其他一些验证器上对其进行了测试.

I've tested it on: Xerces, Saxon, XSV and some other validators.

因此,如果您仍然遇到此问题:

So, if you still have this problem:

  1. 提供完整的示例 - 我们可以在其上重现此问题的简化架构文件和 XML 文件.
  2. 您使用什么编辑器?

这篇关于&lt;attribute ref="..."&gt;的xml问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆