0

I don´t have experience with validation with XSD file, I have to validate the xml file with XSD 1.1 but I getting the next error:

lineNumber: 10; columnNumber: 71; c-cta-xpath: The XPath expression '@tipoelemento = CABECERA' couldn't compile successfully in 'cta-subset' mode, during CTA evaluation.

file.xml

<datos>
<elemento tipoelemento="CABECERA">
    <atributo>
        <nombre>VERSION</nombre>
        <valor>1.0</valor>
    </atributo>
    <atributo>
        <nombre>BRIGADA</nombre>
        <valor>JADSJL</valor>
    </atributo>
    <atributo>
        <nombre>BUZON</nombre>
        <valor>ASDKLFJKA</valor>
    </atributo>
</elemento>

file.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
       xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
       elementFormDefault="qualified"
       vc:minVersion="1.1">
<xs:element name="datos">
    <xs:complexType>
        <xs:sequence>
            <xs:element name="elemento" minOccurs="1" maxOccurs="1">
                <xs:alternative test="@tipoelemento = 'CABECERA'" type="cabecera"/>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:complexType name="cabecera">
    <xs:sequence>
        <xs:element name="atributo" minOccurs="1" maxOccurs="1" type="VERSION" />
        <xs:element name="atributo" minOccurs="1" maxOccurs="1" type="BRIGADA" />
        <xs:element name="atributo" minOccurs="1" maxOccurs="1" type="BUZON" />
    </xs:sequence>
</xs:complexType>
<xs:complexType name="VERSION">
<xs:sequence>
    <xs:element name="nombre" type="xs:string" minOccurs="1" fixed="VERSION" />
    <xs:element name="valor" type="xs:string" minOccurs="1" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="BRIGADA">
    <xs:sequence>
        <xs:element name="nombre" type="xs:string" minOccurs="1" fixed="BRIGADA" />
        <xs:element name="valor" type="xs:string" minOccurs="1" />
    </xs:sequence>
</xs:complexType>
<xs:complexType name="BUZON">
    <xs:sequence>
        <xs:element name="nombre" type="xs:string" minOccurs="1" fixed="BUZON" />
        <xs:element name="valor" type="xs:string" minOccurs="1" />
    </xs:sequence>
</xs:complexType>
</xs:schema>

I haven´t experience in this materia, sorry!

I followed this link click here

I have seen in this link click here that I need use full XPath 2.0 but I don´t know how to do it.

How do I solve this issue?

Regards

tripossi
  • 166
  • 10

1 Answers1

0

XPath expressions used in conditional type assignment are restricted to accessing attributes, they can't access child elements.

Your mistake is that in your expression, @tipoelemento = CABECERA, CABACERA is interpreted as child::CABECERA, that is, a reference to a child element. I think you wanted a string literal here, which would be @tipoelemento = 'CABECERA' where the string is in quotes.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • now, I get the error: cos-element-consistent: Error for type 'cabecera'. Multiple elements with name 'atributo', with different types, appear in the model group. How can I know if I use xsd 1.1? – tripossi Jul 03 '20 at 11:47
  • 1
    That's a completely unrelated problem. Your schema violates the "element declarations consistent" rule, which is unchanged from 1.0 to 1.1. You can't have sibling elements with the same name and different types. The solution is to give them the same type, and impose the constraints using assertions. – Michael Kay Jul 03 '20 at 13:39