Elementformdefault in Schema

Source: Internet
Author: User
Elementformdefault = "? "This attribute is used to indicate the namespace in which the XML schema handler places the elements or types defined in the XML schema.

The elements or types declared in a schema can only belong to one of the two namespaces. These two are the Unnamed namespaces and the target namespaces specified by the targetschema attribute.
The targetschema attribute can only be declared in the Xs: schema definition. Therefore, the elements or types defined in a schema can only belong to a famous namespace (
It may also belong to an unnamed namespace ).

When elementformdefault = "qualified", the child elements of all global elements are put in the target namespace by default, but the global elements or types are
Put it in the target namespace. When elementformdefault = "unqualified", child elements of all global elements are put in the namespace by default.
The attribute namespace is similar to attributeformdefault = "? .

You need to understand that elementformdefault = "? "Is scoped and inherited, unless the parent definition is overwritten in the sub-definition.

The following three examples illustrate how elementformdefault works. Red indicates the elements in the namespace, and blue indicates the elements in the namespace.

1. Define the target namespace. The Global elementformdefault = "unqualified ". In this case, apart from the global element or type attribute to the target namespace, the local element will be attributed to the unknown namespace.

Unqualified. XSD

<? XML version = "1.0" encoding = "UTF-8"?>
<Xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema" targetnamespace = "aaaa" elementformdefault = "unqualified" attributeformdefault = "unqualified">
<Xs: element name = "C">
<Xs: complextype>
<Xs: sequence>
<Xs: element name = "C1" type = "XS: Double"/>
<Xs: element name = "C2" type = "XS: string"/>
</Xs: sequence>
</Xs: complextype>
</Xs: Element>
</Xs: schema>

Unqualified. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<N: C xmlns: N = "aaaa" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "AAAA unqualified. XSD">
<C1> 3.141593e0 </C1>
<C2> string </c2>
</N: C>

2. Define the target namespace. The Global elementformdefault = "qualified ". At this time, global elements or types will be attributed to the target namespace, and local elements will be attributed to the target namespace by default.

Qualified. XSD

<? XML version = "1.0" encoding = "UTF-8"?>
<Xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema" targetnamespace = "aaaa" elementformdefault = "qualified" attributeformdefault = "unqualified">
<Xs: element name = "C">
<Xs: complextype>
<Xs: sequence>
<Xs: element name = "C1" type = "XS: Double"/>
<Xs: element name = "C2" type = "XS: string"/>
</Xs: sequence>
</Xs: complextype>
</Xs: Element>
</Xs: schema>

Qualified. xml

<? XML version = "1.0" encoding = "UTF-8"?>
<C xmlns = "aaaa" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "AAAA qualified. XSD">
<C1> 3.141593e0 </C1>
<C2> string </c2>
</C>

3. Define the target namespace. The Global elementformdefault = "unqualified ". At this time, the global element (C) or type will be attributed to the target namespace.
The local element (C1, C2) is assigned to the namespace by default. Partial Element (C3) uses form = "qualified" to overwrite the globally set
Unqualified, which makes C3 belong to the target namespace (if it has child elements, child elements will be attributed to the target namespace by default ).

Qualified2.xsd

<? XML version = "1.0" encoding = "UTF-8"?>
<Xs: schema xmlns: xs = "http://www.w3.org/2001/XMLSchema" targetnamespace = "aaaa" elementformdefault = "unqualified" attributeformdefault = "unqualified">
<Xs: element name = "C">
<Xs: complextype>
<Xs: sequence>
<Xs: element name = "C1" type = "XS: Double"/>
<Xs: element name = "C2" type = "XS: string"/>
<Xs: element name = "C3" type = "XS: integer" form = "qualified"/>
</Xs: sequence>
</Xs: complextype>
</Xs: Element>
</Xs: schema>

Qualified2.xml

<? XML version = "1.0" encoding = "UTF-8"?>
<N: C xmlns: N = "aaaa" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "AAAA qualified2.xsd">
<C1> 3.141593e0 </C1>
<C2> string </c2>
<N: C3> 0 </N: C3>
</N: C>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.