2

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?

max4ever
  • 11,909
  • 13
  • 77
  • 115

1 Answers1

1

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?
Shcheklein
  • 5,979
  • 7
  • 44
  • 53
  • 2
    yes i agree it works, i think i didn't explain myself well, i want your schema.xsd and this file.xml not this one: why do i have to put these weird tags (xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema.xsd") to make file.xml work? thank you – max4ever Aug 15 '10 at 09:35
  • 2
    Without this attribute it'll not be able to validate it automatically, I think. Though you may use external validation or validation scenario in oXygen Editor (I don't have plugin to test). Here is what oXygen says if try to validate document without schema declaration attribute: "There is no schema or DTD associated with the document. You can create an association either with the Associate Schema action or configuring in the Options the Preferences/Document Type Association list, or by creating a Validation Scenario" – Shcheklein Aug 15 '10 at 18:54
  • BTW, why don't you like schema location attribute? If you want to perform validation automatically by different tools - the common and the best way is to use schemaLocation ... – Shcheklein Aug 15 '10 at 18:56
  • thank you for time, i got my solution here http://stackoverflow.com/questions/3469997/xml-schema-attribute-ref – max4ever Aug 22 '10 at 10:35
  • Reason, why the example in the question didn't work but similar code in this answer did work, lies behind the targetNamespace attribute. If the schema defines a language for a certain namespace i.e. it has a target namespace, all global definitions are in this namespace. If target namespace has not been defined, the namespace is null and globally defined attribute (or element) doesn't need to have a namespace prefix in the schema implementing document. – jasso Aug 22 '10 at 19:14