Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML Schema any Element

XSD Element


The element gives us the ability to extend an XML document with elements not specified by the schema!


Element

The element gives us the ability to extend an XML document with elements not specified by the schema!

The following example is a snippet referenced from an XML schema named "family.xsd". It shows a declaration for the "person" element. By using the element, we can extend the content of "person" with any element (after ):

  xs:complexType

    xs:sequence

     

     

     

   

 

Now, we want to extend the "person" element with a "children" element. We can do this in this case even if the author of the above schema did not declare any "children" element.

Look at this schema file, named "children.xsd":

targetNamespace="http://www.w3schools.com"

xmlns="http://www.w3schools.com"

elementFormDefault="qualified">

  xs:complexType

    xs:sequence

     

      maxOccurs="unbounded"/>

   

 

The following XML file (named "Myfamily.xml") uses components from two different schemas, "family.xsd" and "children.xsd":

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.microsoft.com family.xsd

http://www.w3schools.com children.xsd">

  Hege

  Refsnes

 

    Cecilie

 

  Stale

  Refsnes

The XML file above is valid because the schema "family.xsd" allows us to extend the "person" element with optional elements after the "lastname" element.

and Both can be used to make extensible documents! They give documents the ability to contain additional elements not declared in the main XML schema.