Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > In xml schema, what's the difference between attribute "final" and "block" in element "element"

Reply
Thread Tools

In xml schema, what's the difference between attribute "final" and "block" in element "element"

 
 
tankbattle
Guest
Posts: n/a
 
      07-20-2006
That is, what's the difference between
<complexType name="Address" final="restriction">
<sequence>
<element name="name" type="string"/>
<element name="street" type="string"/>
<element name="city" type="string"/>
</sequence>
</complexType>
and
<complexType name="Address" block="restriction">
<sequence>
<element name="name" type="string"/>
<element name="street" type="string"/>
<element name="city" type="string"/>
</sequence>
</complexType>
in xml schema?

 
Reply With Quote
 
 
 
 
George Bina
Guest
Posts: n/a
 
      07-21-2006
Hi,

You can think of final as a development time restriction (applies to
schema itself) and of block as a runtime restriction (applies to schema
usage from the instance documents).

If you have final="restriction" (note that I made city optional to have
something to restrict)

<xs:complexType name="Address" final="restriction">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

then trying to create a type like below will fail with an error:

<xs:complexType name="RestrictedAddress">
<xs:complexContent>
<xs:restriction base="Address">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>

But if you block restriction

<xs:complexType name="Address" block="restriction">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="street" type="xs:string"/>
<xs:element name="city" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

then you can derive the RestrictedAddress type from it.

Let's assume further that you use block="restriction" and you have also
two element declarations in your schema as below:

<xs:element name="test1" type="Address"/>
<xs:element name="test2" type="RestrictedAddress"/>

Then, when you create instance documents you can have a valid instance
like:

<test1 xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<name></name>
<street></street>
<city></city>
</test1>

But if you want to use xsi:type to specify that test1 is actually of
the RestrictedAddress type:

<test1 xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd" xsi:type="RestrictedAddress">
<name></name>
<street></street>
</test1>

Then you will get an error as RestrictedAddress type cannot be used
instead of Address type because you blocked restriction for the Address
type. If you remove block="restriction" from the schema you can see
that the above instance becames valid.

But if you use test2 has RestrictedAddress as type then you get a valid
instance:

<test2 xmlnssi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test.xsd">
<name></name>
<street></street>
</test2>

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

tankbattle wrote:
> That is, what's the difference between
> <complexType name="Address" final="restriction">
> <sequence>
> <element name="name" type="string"/>
> <element name="street" type="string"/>
> <element name="city" type="string"/>
> </sequence>
> </complexType>
> and
> <complexType name="Address" block="restriction">
> <sequence>
> <element name="name" type="string"/>
> <element name="street" type="string"/>
> <element name="city" type="string"/>
> </sequence>
> </complexType>
> in xml schema?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
Difference between empty attribute and undefined attribute jpdogg@gmail.com Javascript 4 04-24-2007 02:52 PM
what's the difference between a normal form element and a web control element? Masudur ASP .Net 12 03-26-2007 05:33 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
XSLT: Confusion over adding attributes with xml:element and xml:attribute Jordan Willms XML 2 11-09-2004 12:25 AM



Advertisments