on 11-22-2007 9:02 AM
Hi all,
can you tell me why we need to define attributes when creating data type instead we declared it as elements . specific reason behind defining field as attributes
Regards,
Komik Shah
Hi Komik,
you dont need, it is an option. The difference to elements is that they do NOT have a sequence (in the point of view of a parser) and they can contain only text nodes.
Regards,
Udo
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
if you had refered the link i had provided it clearly explains that it is beter to avoid using attributes in XML but they are handly in HTML.
Extract from the link:
<i>Use of Elements vs. Attributes
Data can be stored in child elements or in attributes.
Take a look at these examples:
<person sex="female">
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
<person>
<sex>female</sex>
<firstname>Anna</firstname>
<lastname>Smith</lastname>
</person>
In the first example sex is an attribute. In the last, sex is a child element. Both examples provide the same information.
There are no rules about when to use attributes, and when to use child elements. My experience is that attributes are handy in HTML, but in XML you should try to avoid them. Use child elements if the information feels like data.</i>
Attributes are used to provide additional information about elements.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Komik,
Suppose you have the element ContactNo, attributes of this element would be like Office,Home,Mobile It means you may get three values for the element ContactNo. Which elements are having more possible values in single occurence to those elements by defining the attributes u will get all the values.Similarly Address. Attributes are like Dr.No,Street,City,Pincode.
Hope this will useful to understand !!!
Cheers
Veera
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.