XML attribute vs XML element

前端 未结 20 2230
暖寄归人
暖寄归人 2020-11-22 01:34

At work we are being asked to create XML files to pass data to another offline application that will then create a second XML file to pass back in order to update some of ou

20条回答
  •  名媛妹妹
    2020-11-22 02:09

    Some of the problems with attributes are:

    • attributes cannot contain multiple values (child elements can)
    • attributes are not easily expandable (for future changes)
    • attributes cannot describe structures (child elements can)
    • attributes are more difficult to manipulate by program code
    • attribute values are not easy to test against a DTD

    If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use elements to describe data. Use attributes only to provide information that is not relevant to the data.

    Don't end up like this (this is not how XML should be used):

     
    
    

    Source: http://www.w3schools.com/xml/xml_dtd_el_vs_attr.asp

提交回复
热议问题