XSD validation error

1

My XSD after some modifications by another team started giving the error:

Parse Error at line 33 column 14: s4s-elt-invalid-content.1: The content of '#AnonType_TxnHdrTransaction' is invalid.  Element 'any' is invalid, misplaced, or occurs too often.

My XSD code is as follows:

<xs:element name="TxnHdr">
            <xs:complexType>
                <xs:any>
                    <xs:element name="TxnID" type="x:NumericVar15" />
                    <xs:element name="LogTxnID" type="x:NumericVar15" />
                    <xs:element name="MediaBalance" type="x:NumericVar8" />
                    <xs:element name="TxnDate" type="x:NumericFixed14" />
                    <xs:element name="TxnExtRef" type="x:AlphaNumericVar50" minOccurs="0" />
                    <xs:element name="TxnTypeX" type="x:NumericVar2" />
                    <xs:element name="TxnMode" type="x:NumericFixed1" />
                    <xs:element name="VoidStatus" type="x:NumericFixed1" />
                    <xs:element name="FailedStatus" type="x:NumericFixed1" />
                    <xs:element name="TxnSourceX" type="x:NumericVar2" />
                    <xs:element name="PurchAmt" type="x:NegPositiveDecimalVar21_4" />
                    <xs:element name="DiscAmt" type="x:NegPositiveDecimalVar21_4" />
                    <xs:element name="RdmAmt" type="x:NegPositiveDecimalVar21_4" />
                    <xs:element name="AdjAmt" type="x:NegPositiveDecimalVar21_4" />
                    <xs:element name="MediaTxnSeq" type="x:NumericVar3" minOccurs="0" />
                </xs:any>
            </xs:complexType>
        </xs:element>
    
asked by anonymous 08.09.2014 / 18:32

1 answer

1

How does <any>

The problem in this case is that the tag <any> is being used incorrectly. In XSD it transpires the idea that the tag could be anything as long as it maintains the structure of the children, but that's not how it works.

The idea of <any> is to say that at some point the XML can be extended, but the structure is not defined there.

Example

In example , the pessoa tag is defined, including primeiroNome , ultimoNome and then the any tag allows adding any additional element:

<xs:element name="pessoa">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="primeiroNome" type="xs:string"/>
      <xs:element name="ultimoNome" type="xs:string"/>
      <xs:any minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

By continuing the example, you can define an XSD of an element filhos

<xs:element name="filhos">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="nome" type="xs:string"
      maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

So a valid XLS for this XSD could contain the following structure:

<pessoa>
  <primeiroNome>João</primeiroNome>
  <ultimoNome>Ferreira</ultimoNome>
  <filhos>
    <nome>Gabriel</nome>
  </filhos>
</pessoa>

Note that instead of filhos , we could have any other tag defined in this or another XSD.

Or just use <xs:sequence>

If the idea is not to have a generic element as described above, just change the tag <xs:any> to <xs:sequence> .

I did some testing using an online validator and improvised some missing information in the question's XSD. I have reached the following valid XSD:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3schools.com" xmlns="http://www.w3schools.com" xmlns:tns="http://www.w3schools.com" elementFormDefault="qualified">
   <xs:element name="TxnHdr">
            <xs:complexType>
                <xs:sequence>
                    <xs:element name="TxnID" type="x:NumericVar15" />
                    <xs:element name="LogTxnID" type="x:NumericVar15" />
                    <xs:element name="MediaBalance" type="x:NumericVar8" />
                    <xs:element name="TxnDate" type="x:NumericFixed14" />
                    <xs:element name="TxnExtRef" type="x:AlphaNumericVar50" minOccurs="0" />
                    <xs:element name="TxnTypeX" type="x:NumericVar2" />
                    <xs:element name="TxnMode" type="x:NumericFixed1" />
                    <xs:element name="VoidStatus" type="x:NumericFixed1" />
                    <xs:element name="FailedStatus" type="x:NumericFixed1" />
                    <xs:element name="TxnSourceX" type="x:NumericVar2" />
                    <xs:element name="PurchAmt" type="x:NegPositiveDecimalVar21_4" />
                    <xs:element name="DiscAmt" type="x:NegPositiveDecimalVar21_4" />
                    <xs:element name="RdmAmt" type="x:NegPositiveDecimalVar21_4" />
                    <xs:element name="AdjAmt" type="x:NegPositiveDecimalVar21_4" />
                    <xs:element name="MediaTxnSeq" type="x:NumericVar3" minOccurs="0" />
                </xs:sequence>
            </xs:complexType>
        </xs:element>
</xs:schema>
    
10.09.2014 / 15:30