473,662 Members | 2,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

complexTypes versus elements

Hi all,

I'm fairly new to the world of schemas, but I have a question that I
hope someone can help answer for me. I'm curious as to what the
difference is between an element and a complexType?

I know an element can be a complexType, so I guess what my issue is
when I should define a complexType that's not contained in an element
block, and when I should define a top-level element (what I mean by
that is when I should define an element block right under the
xs:schema node).

I know I can define schemas in any of the following ways and that
they're more or less the same schema:

Schema1:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace ="http://my.company.org/SampleSchema1"
elementFormDefa ult="qualified"
xmlns:my="http://my.company.org/SampleSchema1"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="StringFie ld" type="xs:string "/>
<xs:element name="IntegerFi eld" nillable="true" type="xs:intege r"/>
<xs:element name="DoubleFie ld" nillable="true" type="xs:double "/>
<xs:element name="BooleanFi eld" nillable="true" type="xs:boolea n"/>

<xs:element name="RootEleme nt">
<xs:complexType >
<xs:sequence>
<xs:element ref="my:StringF ield" />
<xs:element ref="my:Integer Field" />
<xs:element ref="my:DoubleF ield" />
<xs:element ref="my:Boolean Field" />
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Schema 2:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace ="http://my.company.org/SampleSchema2"
elementFormDefa ult="qualified"
xmlns:my="http://my.company.org/SampleSchema2"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="RootEleme nt">
<xs:complexType >
<xs:sequence>
<xs:element name="StringFie ld" type="xs:string "/>
<xs:element name="IntegerFi eld" type="xs:intege r"/>
<xs:element name="DoubleFie ld" type="xs:double "/>
<xs:element name="BooleanFi eld" type="xs:boolea n"/>
</xs:sequence>
</xs:complexType>
</xs:element>

</xs:schema>

Schema 3:
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace ="http://my.company.org/SampleSchema3"
elementFormDefa ult="qualified"
xmlns:my="http://my.company.org/SampleSchema3"
xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:complexTy pe name="RootEleme ntType">
<xs:sequence>
<xs:element name="StringFie ld" type="xs:string "/>
<xs:element name="IntegerFi eld" type="xs:intege r"/>
<xs:element name="DoubleFie ld" type="xs:double "/>
<xs:element name="BooleanFi eld" type="xs:boolea n"/>
</xs:sequence>
</xs:complexType>

<xs:element name="RootEleme nt" type="my:RootEl ementType" />

</xs:schema>

But which way is the most "correct"? My gut tells me to specify
everything as complexType independent of any particular element, and
only define top-level elements where I absolutely need them, but it
seems most tools like to define everything as top-level elements.

I hope this makes sense. It seems like there are lots of tutorials on
how to create schemas, but I can't seem to find much on best practices
in terms of how those schemas should be defined. Any help would be
appreciated!

Thank you,

John LaRusic
Developer, Atlantic Canada Opportunities Agency

Mar 21 '07 #1
2 1701
An element is the thing made up of a start-tag and an end-tag, which
contains attributes and children. An element's value may have a type;
that type may be a complex type which specifies those attributes and
children.

In your example, <RootElement... . </RootElementis an element which
has a complex type that says it contains a specific sequence of other
elements.
Mar 21 '07 #2
John LaRusic wrote:
I know an element can be a complexType
No. An element is an element. It can have a type assigned by the schema;
that type may either be a simple type or a complex type.
when I should define a complexType that's not contained in an element
block
Do this when there will be several references to the same complex type,
or when it's just clearer to describe it that way.

If you've worked in C, this is the same question as when to use typedef
versus when to just define the struct in-line. Or, in Java, when to use
a stand-alone class definition versus when to use an anonymous class.
There are times when you must give the type a name, there are times when
you don't have to but want to, and there are times when it really is
simplest to just do it where it's being used and not worry about it.
Picking between these is a matter of style and judgement, and that comes
with practice.

If you really can't decide, give the type a name. That may not be the
cleanest answer but it preserves all your options.
But which way is the most "correct"?
Wrong question. Which is clearest, and which allows you to do what you
intend to do later with this document type... and sometimes it honestly
makes no difference.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
Mar 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
13726
by: franky.backeljauw | last post by:
Hello, I am wondering which of these two methods is the fastest: std::copy, which is included in the standard library, or a manually written pointer copy? Do any of you have any experience with this? I would think that the library function std::copy would perform optimally, as it is a library function, and therefore the writers of this function would know best how to optimize it ... but some tests seem to indicate that my pointer copy...
12
6022
by: Alan J. Flavell | last post by:
OK, today's email brought a comment from a reader, pointing out something that I'd long since noticed myself but hadn't done anything about it. On my pages, I've got a first-letter style on paragraphs. So far, so good: some of the paragraphs begin with a link, and there are styles in the stylesheet for link, hover etc. The first letter is still displayed as styled for the paragraph's first-letter.
9
1854
by: Michel | last post by:
I'm renewing my interest in CSS and downloaded some stylesheets. However, the .css uses both an ID and class. It looks like something like this. ..class1 { /* CSS code */ } #styleID1 { /* CSS code */
0
1564
by: Paula DiTallo | last post by:
Hello Techies-- I am reading an XML document with many nested elements. Many of these elements go to such a variety of tables, that I am trying to simply the read of the document by dumping the data into a single table using SQLXML/BulkXMLLoad. I have triggers set on an insert of this table to cascade inserts to the appropriate myriad of other tables. Originally I tried to use simpleType, then I tried to use: complexType, mixed="true"...
4
497
by: Larry | last post by:
I believe the .Net XmlValidatingReader should fail when validating XML that contains a ComplexType element with white space when the ComplexType element has the mixed attribute set to false in the XSD used for validation. XSD fragment: <xs:element name="TRSellerBuyerData"> <xs:complexType mixed="false"> <xs:sequence>
5
6905
by: Paul | last post by:
Off the cuff, does anyone know if arraylist is more efficeint at adding items to an array than redim preserve? Paul <begin loop> Dim c As Integer = SomeArray.GetUpperBound(0) + 1 ReDim Preserve SomeArray(c) SomeArray(c) = SomeObject <end loop>
5
1664
by: bclark76 | last post by:
I am getting a strange error, maybe someone knows why it is occurring.. I get the following error when I try to validate Untitled8.xml in Altova XMLSPY: Validation error in another file: Untitled3.xsd The message in XMLSPY in Untitled3.xsd is: The file is not valid: The content model of complex type { no name } is not a valid restriction of the content model of complex type 'Condiment_Type'
11
4067
by: David Stone | last post by:
I'm trying to figure out how to avoid tables when presenting a sidebar on an html 4 strict page, by using div instead. I've run into a situation where I get different rendering of the elements within the main div, depending on whether it is contained within a <td> or a <div> - http://www.chem.utoronto.ca/~dstone/test1.html http://www.chem.utoronto.ca/~dstone/test2.html I've been trying to understand why, particularly, the <ul>
0
1749
by: Andrew 2006 | last post by:
I have a wsdl definition that includes the following definition for the element <Preferencesinside the request createFooBar: <xs:element minOccurs="1" name="Preferences" nillable="true" type="java1:List" xmlns:java1="java:java.util"/> .... <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="java:java.util" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:import...
0
8768
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8547
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1754
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.