'Attribute not allowed to appear in element' error

M

matt hegarty

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>
 
M

Martin Honnen

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.
 
S

Stanimir Stamenkov

/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.
 
M

mash101

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

Matt
 
S

Stanimir Stamenkov

/[email protected]/:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,237
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top