xml学习中出现的错误

1、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>
原因:当一个元素包含属性和文本时不能这样写

正确写法
<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>

      

你可能感兴趣的:(xml学习中出现的错误)