views:

45

answers:

1

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?

A: 

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"&gt;
<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
yes i agree it works, i think i didn't explain myself well,i want your schema.xsdand this file.xml <inv_constraint unaryOperator="not">not this one:<?xml version="1.0"?><inv_constraint unaryOperator="non" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema.xsd"></inv_constraint>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
reanimax
as an editor i'm using oXygenl XML plugin for Eclipse
reanimax
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
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
thank you for time, i got my solution here http://stackoverflow.com/questions/3469997/xml-schema-attribute-ref
reanimax
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