Skip to Content
avatar image
Former Member

Attributes

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Nov 22, 2007 at 09:13 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • 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>

  • Nov 22, 2007 at 09:23 AM

    Attributes are used to provide additional information about elements.

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 22, 2007 at 09:21 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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