xml与<;属性ref="&引用&燃气轮机;

xml与<;属性ref="&引用&燃气轮机;,xml,reference,xsd,Xml,Reference,Xsd,我有一个xml模式 <xs:complexType> ... <xs:attribute ref="unaryOperator"></xs:attribute> </xs:complexType> <xs:attribute name="unaryOperator"> ... 我尝试在xml文件中使用它 像这样 <inv_constraint unaryOperator="not"> <inv_co

我有一个xml模式

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


<xs:attribute name="unaryOperator">

...

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

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

编辑给了我这个错误:

说明资源路径位置类型 [Xerces]cvc复杂类型。3.2.2:属性“unaryOperator”不允许出现在元素“inv_constraint”中。 @请参阅:abc.xml/prova第28行xml问题

编辑建议我这样做

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

如果我没有在xml模式中使用ref,只是复制粘贴属性而不是引用它,那么我的xml文件可以工作


因此,我的问题是,如何在没有奇怪标记的情况下使xml有效,并将ref保留在xml模式中?

我看不出有任何问题。以下对我来说很好:

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

file.xml:

<?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>
<?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和其他一些验证器上进行了测试

因此,如果您仍然存在此问题:

  • 提供完整的示例-简化的模式文件和XML文件,我们可以在其上重现此问题
  • 你用什么编辑器

  • 是的,我同意它是有效的,我想我没有很好地解释我自己,我想要你的schema.xsd和这个file.xml而不是这个:为什么我必须放置这些奇怪的标记(xmlns:xsi=”“xsi:noNamespaceSchemaLocation=“schema.xsd”)来让file.xml工作?谢谢,如果没有这个属性,我想它将无法自动验证。虽然您可以在oXygen Editor中使用外部验证或验证场景(我没有要测试的插件)。如果尝试在没有模式声明属性的情况下验证文档,oXygen会这样说:“没有与文档关联的模式或DTD。您可以通过关联模式操作或在首选项/文档类型关联列表的选项中进行配置,或者通过创建验证场景”BTW,为什么不喜欢模式位置属性?如果您想通过不同的工具自动执行验证,最常见也是最好的方法是使用schemaLocation…感谢您的时间,我在这里找到了解决方案。原因在于,为什么问题中的示例不起作用,但此答案中的类似代码确实起作用,原因在于targetNamespace属性后面。如果模式为某个名称空间定义了一种语言,即它有一个目标名称空间,则所有全局定义都在此名称空间中。如果尚未定义目标命名空间,则命名空间为null,全局定义的属性(或元素)不需要在架构实现文档中具有命名空间前缀。