"Elements ... does not resolve to a(n) type definition" in validation
Asked Answered
S

1

6

I am trying to create an XSD file to work as a filter to validate some XML files that will have to be processed further.

Here is the XSL file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<acknowledgement xmlns="http://sungardams.com/Validation.xsd" xmlns:common="http://sungardams.com/common.xsd">
    <type>POSITIVE</type> <!-- must have value POSITIVE -->
    <originReference>
        <externalMessageId>12345678-010</externalMessageId>
    </originReference>
    <requestMessageId>000000000000000000000000001</requestMessageId>
    <senderInfo>
        <common:messageId>000000000000000000000000000001</common:messageId>
        <common:externalMessageType>securityAddRequest</common:externalMessageType> <!-- must have value securityAddRequest -->
        <common:applicationHistory>
            <common:originatorReference>
                <common:originator>GLOBAL PLUS</common:originator> <!-- must have value GLOBAL PLUS -->
                <common:reference>ABCDE001</common:reference>
                <common:primaryReferenceType>GREF</common:primaryReferenceType> <!-- must have value GREF -->
            </common:originatorReference>
        </common:applicationHistory>
    </senderInfo>
</acknowledgement>

The file I receive is validated using another XSD file, and uses the namespace common (to explain why some elements are prefixed common:).

So I created the following XSD files:

Validation.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:common="http://sungardams.com/common.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://sungardams.com/common.xsd" schemaLocation="http://sungardams.com/common.xsd antCommon001.xsd"/>

    <xs:element name="acknowledgement">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="type" type="xs:string" fixed="POSITIVE" />
                <xs:element name="originReference">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="externalMessageId" type="xs:string" />
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
                <xs:element name="requestMessageId" type="xs:string" />
                <xs:element name="senderInfo" type="CType_SenderInfo_ant" />
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

At first, the element senderInfo was defined in this file. But when I tried it like that, I would get the error message that I the elements weren't valid (I would prefixe the name with the namespace common:, so would get the message that they were not valid xs:NCName).

So I moved the sender info into another file: antCommon001.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="CType_SenderInfo_ant">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="messageId" type="xs:string" />
                <xs:element name="externalMessageType" type="xs:string" fixed="securityAddRequest" />
                <xs:element name="applicationHistory">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="originatorReference">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="originator" type="xs:string" fixed="GLOBAL PLUS" />
                                        <xs:element name="reference" type="xs:string" />
                                        <xs:element name="primaryReferenceType" type="xs:string" fixed="GREF" />
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

Now, when I run the validation of the XML file, I get the message (using Notepad++ XML Tools validation plugin):

Unable to parse schema file ... element decl. 'senderInfo', attribute 'type': The QName value 'CType_SenderInfo_ant' does not resolve to a(n) type definition.

What am I doing wrong?

Snipe answered 26/1, 2017 at 17:39 Comment(0)
C
2

There are multiple changes you'll have to make, including:

  • xs:import/@schemaLocation should not be a namespace-XSDurl pair as it is for xs:schema/@schemaLocation -- it should just be the URL to the XSD.
  • To reference a type in another namespace, prefix it with a namespace prefix declared to that namespace.
  • antCommon.XSD is declaring an element when you seem to wish to reference a type instead.

Altogether, with some additional fixes, the following updates to your XML and XSD files will validate your XML successfully:

validation.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<acknowledgement xmlns="http://sungardams.com/Validation.xsd" 
                 xmlns:common="http://sungardams.com/common.xsd"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://sungardams.com/Validation.xsd Validation.xsd">
  <type>POSITIVE</type> <!-- must have value POSITIVE -->
  <originReference>
    <externalMessageId>12345678-010</externalMessageId>
  </originReference>
  <requestMessageId>000000000000000000000000001</requestMessageId>
  <senderInfo>
    <common:messageId>000000000000000000000000000001</common:messageId>
    <common:externalMessageType>securityAddRequest</common:externalMessageType> <!-- must have value securityAddRequest -->
    <common:applicationHistory>
      <common:originatorReference>
        <common:originator>GLOBAL PLUS</common:originator> <!-- must have value GLOBAL PLUS -->
        <common:reference>ABCDE001</common:reference>
        <common:primaryReferenceType>GREF</common:primaryReferenceType> <!-- must have value GREF -->
      </common:originatorReference>
    </common:applicationHistory>
  </senderInfo>
</acknowledgement>

Validation.xsd

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:common="http://sungardams.com/common.xsd"
           targetNamespace="http://sungardams.com/Validation.xsd"
           elementFormDefault="qualified">
  <xs:import namespace="http://sungardams.com/common.xsd"
             schemaLocation="antCommon.xsd"/>

  <xs:element name="acknowledgement">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="type" type="xs:string" fixed="POSITIVE" />
        <xs:element name="originReference">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="externalMessageId" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="requestMessageId" type="xs:string" />
        <xs:element name="senderInfo" type="common:CType_SenderInfo_ant" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

</xs:schema>

antCommon.XSD

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://sungardams.com/common.xsd"
           elementFormDefault="qualified">

  <xs:complexType name="CType_SenderInfo_ant">
    <xs:sequence>
      <xs:element name="messageId" type="xs:string" />
      <xs:element name="externalMessageType" type="xs:string" 
                  fixed="securityAddRequest" />
      <xs:element name="applicationHistory">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="originatorReference">
              <xs:complexType>
                <xs:sequence>
                  <xs:element name="originator" type="xs:string"
                              fixed="GLOBAL PLUS" />
                  <xs:element name="reference" type="xs:string" />
                  <xs:element name="primaryReferenceType" 
                              type="xs:string" fixed="GREF" />
                </xs:sequence>
              </xs:complexType>
            </xs:element>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>

</xs:schema>
Cushitic answered 26/1, 2017 at 18:28 Comment(6)
Hi @kjhughes. Thanks for answering. I tried changing my files for yours, but it gives me the same error message ("The QName value '{sungardams.com/common.xsd}CType_SenderInfo_ant' does not resolve to a(n) type definition."), for the same line.Snipe
Is it possibly due to having a different version of something?Snipe
Depending upon where your XSDs are relative to each other, you may need to adjust the xs:import/@schemaLocation value. As I have it, it's relative to the main XSD. Try using an absolute path if a relative one is giving you trouble. Also, see the tips I provide in How to reference a local XML Schema file correctlyCushitic
All the files are in the same folder. Okay, now the message it gives is "ERROR: Element '{sungardams.com/Validation.xsd}acknowledgement': No matching global declaration available for the validation root.".Snipe
I also tried adding the <xs:complexType name="CType_SenderInfo_ant"> ... </xs:complexType> into the Validation.xsd file, and removing the <xs:import ... />, but it gives me ths same No matching global declaration error message.Snipe
{sungardams.com/Validation.xsd}acknowledgement': indicates that acknowledgement is in a namespace, contrary to the assumption I stated in my answer. If you could post the XML...actually, I see you did post XML. I will adjust my answer to account for your root element being in a namespace...Cushitic

© 2022 - 2024 — McMap. All rights reserved.