max4ever
max4ever

Reputation: 12142

xml problem with <attribute ref="...">

i have an xml schema

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


<xs:attribute name="unaryOperator">

i try to use it in my xml file like this

  <inv_constraint unaryOperator="not">

The editor gives me this error:

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

the editor suggest i do it like this

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

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,

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

Upvotes: 2

Views: 1780

Answers (1)

Shcheklein
Shcheklein

Reputation: 6284

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>

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

So, if you still have this problem:

  1. Provide complete example - simplified schema file and XML file on which we can reproduce this problem.
  2. What editor do you use?

Upvotes: 1

Related Questions