cancel
Showing results for 
Search instead for 
Did you mean: 

Attributes

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

udo_martens
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Udo,

it is an option as you are saying so can we define it as constants all the time ?

give me reason with one example .

Regards,

Komik Shah

udo_martens
Active Contributor
0 Kudos

Hi komik,

it is your decision to design a datatype only with element or to use as well attributes, as constants or not.

You can have


<name>
<first>Udo</first>
<family>Martens</family>
</name>

or

<name first="Udo" family="Martens"></name>

Regards,

Udo

Former Member
0 Kudos

hi ,

so whenever we define attributes we have to use constants node in mapping that's what you are telling .

Regards,

Komik Shah

udo_martens
Active Contributor
0 Kudos

Hi Komik,

no, you CAN define an attribute as constant, it is an option.

Regards,

Udo

Shabarish_Nair
Active Contributor
0 Kudos

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>

Answers (2)

Answers (2)

Shabarish_Nair
Active Contributor
0 Kudos

Attributes are used to provide additional information about elements.

Ref: http://www.w3schools.com/xml/xml_attributes.asp

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi veera,

if third party has no attributes in contact no like office,home,mobile then we can define it as constants when we do mapping ?

Regards,

Komik Shah