Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Attribute 'targetNamespace' is not allowed to appear in element

I wrote this XML file, plus the XSD, and I’m using XQuery to add information on a db in BaseX. I’m using Postman to do the POST requests, but when I run Postman it is giving me this error message:

[validate:error] Validation failed: 1:242: cvc-complex-type.3.2.2:
Attribute ‘targetNamespace’ is not allowed to appear in element
‘Reservas’

What is causing this error?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

XML:

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


  <Reservas 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema_Instance"
     targetNamespace="http://www.ipp.estg.pt/Dados_clientess"
     xsi:schemaLocation="http://www.ipp.estg.pt/Dados_clientes CommonTypes.xsd"
     xmlns="http://www.ipp.estg.pt/Dados_clientes"
  >

    <num_familia>1</num_familia>
    <num_elementos>1</num_elementos>
    <preferencia_dias>
        <data>22-12-2021</data>
        <data>23-12-2021</data>
        <data>24-12-2021</data>
    </preferencia_dias>
      
    <cliente>
      <nome>Nicolas</nome>
      <data_nascimento>22-08-1999</data_nascimento>
      <pais>Portugal</pais>
      <cidade_origem>Amarante</cidade_origem> 
    </cliente>
      
  </Reservas>

XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  targetNamespace="http://www.ipp.estg.pt/Dados_clientes" 
  xmlns="http://www.ipp.estg.pt/Dados_clientes" 
  xmlns:xsi="http://www.ipp.estg.pt/Dados_clientes"
>


  <!-- Elemento completo -->

  <xs:element name="Reservas">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="num_familia" type="FamiliaType"></xs:element>
        <xs:element name="num_elementos" type="xs:int"></xs:element>
        <xs:element name="preferencia_dias" type="PreferenciasType"></xs:element>
        <xs:element name="cliente" type="ClientesType"></xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>

  <!-- COMPLEX TYPE RELATIVO AOS ELEMENTOS DA FAMILIA  -->

  <xs:complexType name="ElementosType">
    <xs:sequence>
      <xs:element name="nome" type="xs:string" />
      <xs:element name="data_nascimento" type="xs:date" />
      <xs:element name="pais" type="xs:string" />
      <xs:element name="cidade_origem" type="xs:string" />
    </xs:sequence>
  </xs:complexType>

  <!-- TYPE USADA SOBRE OS CLIENTES MINIMO E MAXIMO -->


  <xs:complexType name="ClientesType">
    <xs:sequence minOccurs="0" maxOccurs="7">
      <xs:element name="clientes" type="ElementosType" />
    </xs:sequence>
  </xs:complexType>

  <!-- TYPE USADA SOBRE AS DATAS DE PREFERENCIA -->

  <xs:complexType name="PreferenciasType">
    <xs:sequence minOccurs="1" maxOccurs="5"></xs:sequence>
  </xs:complexType>

  <!-- NÚMERO DE FAMILIAS MAXIMAS PERMITIDOS -->

  <xs:simpleType name="FamiliaType">
    <xs:restriction base="xs:int">
      <xs:minInclusive value="1" />
      <xs:maxInclusive value="50000" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

XQUERY:

xquery version "3.0"; 

module namespace page = 'http://basex.org/examples/web-page';

declare %updating %rest:path("addAgendamento")
  %rest:POST("{$xml}")
  %rest:consumes('application/xml')
function page:add($xml as item())
{
  let $xsd := "CommonTypes.xsd"
  return validate:xsd($xml, $xsd),
   update:output("Insert successful."), db:add("Dados_clientes", $xml, "Dados_clientes.xml") 
};

>Solution :

Remove targetNamespace="http://www.ipp.estg.pt/Dados_clientess" from the root element of your XML document.

A targetNamespace attribute does not belong on the root element of an XML instance document; it belongs on the root element of an XSD root element.

See also

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading