属性 'targetNamespace' 不允许出现在元素中

Attribute 'targetNamespace' is not allowed to appear in element

我写了这个 XML 文件,加上 XSD,我正在使用 XQuery 在 BaseX 中的数据库上添加信息。我正在使用 Postman 执行 POST 请求,但是当我 运行 Postman 时它给我这个错误消息:

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

导致此错误的原因是什么?

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") 
};

从 XML 文档的根元素中删除 targetNamespace="http://www.ipp.estg.pt/Dados_clientess"

targetNamespace属性属于XML实例文档的根元素;它属于 XSD 根元素.

的根元素

另见

  • How to link XML to XSD using schemaLocation or noNamespaceSchemaLocation?