469,362 Members | 2,548 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,362 developers. It's quick & easy.

'Attribute not allowed to appear in element' error

Hi
I am relatively new to XML, but am having problems with a validation
issue.

When the XML is parsed and validated using Xerces, the following error
is seen:

cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is
not allowed to appear in element 'questionFeed'.

This error does not appear when the file is validated against the
schema using the XMLSpy tool. The file passes validation when the
'noNamespaceSchemaLocation' entry in the XML is removed. So I guess
the question is: how can I structure my schema so that this error is
not seen? Incidentally, the 'noNamespaceSchemaLocation' is
irrelevant in the XML - I validate programmatically.

Snippets of both schema and XML are attached:

== SCHEMA FILE ===

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:simpleType name="nonEmptyString">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:whiteSpace value="collapse"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="questionFeed">
<!-- snipped -->
</xs:element>
</xs:schema>
== XML FILE ===

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XMLSPY v5 rel. 4 U
(http://www.xmlspy.com)-->
<questionFeed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="blah.xsd">
<pq>
<!-- snipped -->
</pq>
</questionFeed>
Jul 20 '05 #1
4 20258


matt hegarty wrote:

When the XML is parsed and validated using Xerces, the following error
is seen:

cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is
not allowed to appear in element 'questionFeed'. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">


Maybe Xerces complains as you have elementFormDefault="qualified", try with
elementFormDefault="unqualified"
which seems to be what you want anyway as you do not use a target
namespace and your XML instance doesn't have a namespace on the elements.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #2
/matt hegarty/:
cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is
not allowed to appear in element 'questionFeed'.


Make sure you turn namespaces support of your parser on. If you
obtain your parser instance through JAXP you should call
setNamespaceAware(true) on the parser factory instance.

--
Stanimir
Jul 20 '05 #3
Thanks for the responses.
I followed Stanimir's suggestion and this seems to have solved the
problem.

Matt

Stanimir Stamenkov wrote:
/matt hegarty/:
cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation' is not allowed to appear in element 'questionFeed'.


Make sure you turn namespaces support of your parser on. If you
obtain your parser instance through JAXP you should call
setNamespaceAware(true) on the parser factory instance.

--
Stanimir


Jul 20 '05 #4
/ma*****@talk21.com/:
Stanimir Stamenkov wrote:
/matt hegarty/:
cvc-complex-type.3.2.2: Attribute 'xsi:noNamespaceSchemaLocation'
is not allowed to appear in element 'questionFeed'.


Make sure you turn namespaces support of your parser on. If you
obtain your parser instance through JAXP you should call
setNamespaceAware(true) on the parser factory instance.


I followed Stanimir's suggestion and this seems to have solved the
problem.


Alternatively (I haven't tested it though), if you're going to
validate documents which elements doesn't have namespace, using such
XML Schema that doesn't specify 'targetNamespace', you could not
include the 'noNamespaceSchemaLocation' attribute and set the schema
location through the parser factory properties:

"Properties for enabling schema validation" in the JAXP 1.2
specification <http://java.sun.com/xml/downloads/jaxp.html>.

You could get immediate online information from:

http://java.sun.com/xml/jaxp/change-requests-12.html

--
Stanimir
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Lénaïc Huard | last post: by
2 posts views Thread by piraticman | last post: by
4 posts views Thread by Martin Lucas-Smith | last post: by
4 posts views Thread by Manuel Faux | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.