| Refresh | Home EGTry.com

define xml schema for an simple xml element that has attributes as well as text content


element example

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="test.xsd"
  name="John">
   	<element1 a1="attribute1">Text inside element</element1>
</root>

schema

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs = "http://www.w3.org/2001/XMLSchema">
   <xs:element name = "root">
      <xs:complexType>
        <xs:sequence>

          <xs:element name="element1" >
             <xs:complexType>
               <xs:simpleContent>
                 <xs:extension base="xs:string">
	                 <xs:attribute name="a1" type="xs:string" use="required"/>
                 </xs:extension>
               </xs:simpleContent>
             </xs:complexType>
          </xs:element>


        </xs:sequence>
	       <xs:attribute name="name" type="xs:string" use="required"/>
      </xs:complexType>
   </xs:element>


</xs:schema>