Home >Backend Development >XML/RSS Tutorial >A brief introduction to the elementFormDefault attribute in XML Schema

A brief introduction to the elementFormDefault attribute in XML Schema

怪我咯
怪我咯Original
2017-04-05 17:03:241678browse

The following editor will bring you a brief discussionXMLThe elementFormDefault attribute in Schema. The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor to take a look.

elementFormDefault attribute is related to namespace, its value can be set to qualified or unqualified

If set to qualified:

When using local elements in XML documents, you must use a qualified short name as a prefix

##sean.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:sean="http://sean.com"
 targetNamespace="http://sean.com"
 elementFormDefault="qualified">
 <xs:element name="book_list">
 <xs:complexType>
 <xs:sequence>
 <xs:element name="book" type="xs:string"/>
 </xs:sequence>
 </xs:complexType>
 </xs:element>
</xs:schema>

sean.xml:

<?xml version="1.0" encoding="UTF-8"?>
<sean:book_list xmlns:sean="http://sean.com" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://sean.com sean.xsd">
 <sean:book>test</sean:book>
</sean:book_list>

If set to unqualified:

When using local elements in XML documents, the qualified short can be omitted Name

sean.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
 xmlns:sean="http://sean.com"
 targetNamespace="http://sean.com"
 elementFormDefault="unqualified">
 <xs:element name="book_list">
 <xs:complexType>
 <xs:sequence>
 <xs:element name="book" type="xs:string"/>
 </xs:sequence>
 </xs:complexType>
 </xs:element>
</xs:schema>

sean.xml:

<?xml version="1.0" encoding="UTF-8"?>
<sean:book_list xmlns:sean="http://sean.com" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://sean.com sean.xsd">
 <book>test</book>
</sean:book_list>

Although there will be a lot of indirection, it is not easy to understand because the namespace is removed.

Similar attributes include attributeFormDefault, whose rules are the same as elementFormDefault



The above is the detailed content of A brief introduction to the elementFormDefault attribute in XML Schema. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn