Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XML & XSD validation failed: Element has both a 'type' attribute and a 'anonymous type' child

I have an XML file and an XSD file to validate. When i validate , it shows following error.

org.xml.sax.SAXParseException: src-element.3: Element 'UC4' has both a 'type' attribute and a 'anonymous type' child. Only one of these is allowed for an element.

XML File:

<UC4Execution>
        <Script>JOB_NAME</Script>

        <UC4 Server="UC4.com" Client="123" UserId="123" Password="*****" >
        </UC4 >

</UC4Execution>

XSD File :

        <xs:element name="UC4Execution">
                <xs:complexType>
                <xs:sequence>

                    <xs:element name="Script" type="xs:string"/>
                    <xs:element name="UC4" type="xs:string" minOccurs="0">
                    <xs:complexType>
                        <xs:attribute name="Server" type="xs:string" use="required"/>
                        <xs:attribute name="Client" type="xs:string" use="required"/>
                        <xs:attribute name="UserId" type="xs:string" use="required"/>
                        <xs:attribute name="Password" type="xs:string" use="required"/>
                    </xs:complexType>
                    </xs:element>

                </xs:sequence>
                </xs:complexType>
            </xs:element>

What might be the issue?

like image 853
logan Avatar asked Jan 10 '14 11:01

logan


People also ask

What is XML vs HTML?

XML stands for eXtensible Markup Language and is used to transport and save data. The focus here is not on displaying or the appearance of the data. On the other hand, HTML stands for Hypertext Markup Language. This computer language helps to make the data more interactive with multiple formatting features.

Is Excel an XML?

XML tables are similar in appearance and functionality to Excel tables. An XML table is an Excel table that has been mapped to one or more XML repeating elements. Each column in the XML table represents an XML element.

Is XML like HTML?

XML (Extensible Markup Language) is a markup language similar to HTML, but without predefined tags to use. Instead, you define your own tags designed specifically for your needs. This is a powerful way to store data in a format that can be stored, searched, and shared.

What is XML and JSON?

JSON is a data interchange format and only provides a data encoding specification. XML is a language to specify custom markup languages, and provides a lot more than data interchange. With its strict semantics, XML defined a standard to assert data integrity of XML documents, of any XML sub-language.


1 Answers

The problem is exactly where the error message says it is:

<xs:element name="UC4" type="xs:string" minOccurs="0">
  <xs:complexType>
    <xs:attribute name="Server" type="xs:string" use="required"/>
    <xs:attribute name="Client" type="xs:string" use="required"/>
    <xs:attribute name="UserId" type="xs:string" use="required"/>
    <xs:attribute name="Password" type="xs:string" use="required"/>
  </xs:complexType>
</xs:element>

You can't have both type="xs:string" and a nested complexType for the same element.

If you want the UC4 element to have just attributes and no nested text content then remove the type attribute

<xs:element name="UC4" minOccurs="0">
  <xs:complexType>
    <xs:attribute name="Server" type="xs:string" use="required"/>
    <!-- ... -->

If you want it to have both attributes and string content

<UC4 Server="UC4.com" Client="123" UserId="123" Password="*****">content</UC4>

then you need a nested complexType with simpleContent that extends xs:string

<xs:element name="UC4" minOccurs="0">
  <xs:complexType>
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="Server" type="xs:string" use="required"/>
        <xs:attribute name="Client" type="xs:string" use="required"/>
        <xs:attribute name="UserId" type="xs:string" use="required"/>
        <xs:attribute name="Password" type="xs:string" use="required"/>
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>
</xs:element>
like image 143
Ian Roberts Avatar answered Sep 27 '22 20:09

Ian Roberts