Home > OS >  global declaration error in XML XSD validation
global declaration error in XML XSD validation

Time:12-06

I am brand new to XML and XSD creation. I am in the very basic stages of trying to form validating schema. However, I have spent a lot of time going in circles on this. If someone could review and please give me a better understanding of what is happening with the code? It is saying there is no global declaration for the root reports.

The error code reads as

Cvc-elt.1.a: Cannot Find The Declaration Of Element 'xs:reports'., Line '1', Column '134'.

 <?xml version="1.0" encoding="UTF-8"?>

<xs:reports xmlns:xs="https://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="user.xsd">

    user(
    userID SERIAL,
    username varchar(255),
    password varchar(255),
    firstname varchar(255),
    middlename varchar(255),
    lastname varchar(255),
    email varchar(255),
  dob date,
    gender varchar(10)
  profile_photo bytea,
  home_phone varchar(50),
    cell_phone varchar(50),
    created_date timestamp default current_timestamp
  );
</xs:reports>
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
  <xs:element name="reports">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="user">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="userID" type="xs:string"/>
              <xs:element name="username" type="xs:string"/>
              <xs:element name="password" type="xs:string"/>
              <xs:element name="firstname" type="xs:string"/>
              <xs:element name="middlename" type="xs:string"/>
              <xs:element name="lastname" type="xs:string"/>
              <xs:element name="email" type="xs:string"/>
              <xs:element name="dob" type="xs:date"/>
              <xs:element name="gender" type="xs:string"/>
              <xs:element name="profile_photo" type="xs:string"/>
              <xs:element name="cell_phone" type="xs:string"/>
              <xs:element name="created_date" type="xs:dateTime"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

CodePudding user response:

To remedy your immediate error of failing to associate the XML with an XSD, read How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?

Then, actually follow the XSD when writing your XML:

<reports>
  <user>
    <userID>123</userID>
    <username>John Smith</username>
    ...
  </user>
</reports>

There's also a question of why the XSD would have user being a child of reports, but you can get your existing XSD working as is with new XML as a first step.

  • Related