'Attribute not allowed to appear in element' error

Discussion in 'XML' started by matt hegarty, Jan 10, 2005.

  1. matt hegarty

    matt hegarty Guest

    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>
    matt hegarty, Jan 10, 2005
    #1
    1. Advertising

  2. 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/
    Martin Honnen, Jan 10, 2005
    #2
    1. Advertising

  3. /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
    Stanimir Stamenkov, Jan 11, 2005
    #3
  4. matt hegarty

    Guest

    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
    , Jan 11, 2005
    #4
  5. //:
    > 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
    Stanimir Stamenkov, Jan 11, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. anonymous
    Replies:
    1
    Views:
    5,951
  2. =?Utf-8?B?TWFyaw==?=
    Replies:
    4
    Views:
    632
    =?Utf-8?B?TWFyaw==?=
    Dec 14, 2006
  3. perspolis
    Replies:
    1
    Views:
    2,562
    Mark Rae
    Jan 23, 2007
  4. Joe Kovac
    Replies:
    2
    Views:
    950
    Joe Kovac
    May 2, 2007
  5. Iñaki Baz Castillo
    Replies:
    13
    Views:
    497
    Iñaki Baz Castillo
    May 1, 2011
Loading...

Share This Page