reference element : Reference « XML Schema « XML






reference element



<?xml version="1.0"?>
<name xmlns="http://www.java2s.com/name"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://www.java2s.com/name Schema.xsd"
  title="Mr.">
  <first>first</first>
  <middle>middle</middle>
  <last>last</last>
</name>

File: Schema.xsd

<?xml version="1.0"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:target="http://www.java2s.com/name"
  targetNamespace="http://www.java2s.com/name"
  elementFormDefault="qualified">
  <element name="first" type="string" />
  <element name="middle" type="string" />
  <element name="last" type="string" />
  <complexType name="NameType">
    <sequence>
      <element ref="target:first" />
      <element ref="target:middle" />
      <element ref="target:last" />
    </sequence>
    <attribute name="title" type="string" />
  </complexType>
  <element name="name" type="target:NameType" />
</schema>

 








Related examples in the same category

1.Reference defined data type with target namespace
2.Set minOccurs, maxOccurs for referenced types
3.Reference your type with namespace
4.Refernece anonymous complexType
5.Nexted reference
6.reference with maxOccurs
7.Use ref to remove the nested definition