Mike
Mike

Reputation: 47

XML is not schema compliant

It seems to not matter how I form my XML, I'm getting the following error:

Schema Violation in message: Element 'message': No matching global declaration available for the validation root.

The first two lines of the XSD look like this:

<xsd:schema targetNamespace="urn:gtig:/stuff/gunk/v7.9 xmlns:Geek="urn:gtig:/stuff/gunk/7.9 xmlns:xsd="http://www.w3.org/2001/XMLSchema elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xsd:element name="message" type="Geek:Message"/>

The first line of my XML looks like this:

<message xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance" xmlns:v7.9="urn:gtig:/stuff/gunk/v7.9 xsi:type="Geek:Message" xsi:schemaLocation="v7.9 /path/to/the/schema">

How should the first line of the message look?

Upvotes: 2

Views: 858

Answers (1)

kjhughes
kjhughes

Reputation: 111491

Fix two issues:

  • xmlns:v7.9="urn:gtig:/stuff/gunk/v7.9 is missing terminating double quote.
  • xsi:schemaLocation is supposed to be namespace URI - schema location pairs, not namespace prefix - schema pairs.

Specifically, change your not-well-formed message element from

<message xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
         xmlns:v7.9="urn:gtig:/stuff/gunk/v7.9 
         xsi:type="Geek:Message" 
         xsi:schemaLocation="v7.9 /path/to/the/schema">

to

<message xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
         xmlns:v7.9="urn:gtig:/stuff/gunk/v7.9"
         xsi:type="Geek:Message" 
         xsi:schemaLocation="urn:gtig:/stuff/gunk/v7.9 /path/to/the/schema">

Update: As Michael Kay points out in the comments, there's more to correct here because message currently isn't in a namespace and therefore xsi:schemaLocation won't help associated this XML with an XSD.

One fix would be to add message to the namespace targeted by the XSD:

<v7.9:message xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
              xmlns:v7.9="urn:gtig:/stuff/gunk/v7.9"
              xsi:type="Geek:Message" 
              xsi:schemaLocation="urn:gtig:/stuff/gunk/v7.9 /path/to/the/schema">

Upvotes: 2

Related Questions