15.2.15. XSD < any > element

发布时间 :2025-10-25 12:23:25 UTC      

The < any > element gives us the ability to expand XML documents through elements that are not specified by schema!

< any > element

The < any > element gives us the ability to expand XML documents through elements that are not specified by schema!

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

<xs:element name="person">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="firstname" type="xs:string"/>
      <xs:element name="lastname" type="xs:string"/>
      <xs:any minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

Now we want to use the “children” element to extend the “person” element. We can do this in this case, even if the author of the above schema does not declare any “children” elements.

Please look at this schema file, named “children.xsd”:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="children">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="childname" type="xs:string"
      maxOccurs="unbounded"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>
</xs:schema>

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

<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns="http://www.microsoft.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.microsoft.com family.xsd
http://www.w3schools.com children.xsd">
<person>
  <firstname>Hege</firstname>
  <lastname>Refsnes</lastname>
  <children>
    <childname>Cecilie</childname>
  </children>
</person>
<person>
  <firstname>Stale</firstname>
  <lastname>Refsnes</lastname>
</person>
</persons>

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

Both < any > and < anyAttribute > can be used to make extensible documents! They give the document the ability to contain additional elements that are not declared in the main XML schema.

Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.