<person sex="female">
  <firstname>Anna</firstname>
  <lastname>Smith</lastname>
</person>

 

<person>
  <sex>female</sex>
  <firstname>Anna</firstname>
  <lastname>Smith</lastname>
</person>

第一段的female是 attribute  第二段的female是 element

W3school的筆者建議用Element  這樣的辨識度比較高

還有三大重點

  • attributes cannot contain multiple values (elements can)
  • attributes cannot contain tree structures (elements can)
  • attributes are not easily expandable (for future changes) 
  • 啥時用到Attibutes?

    metadata (data about data) should be stored as attributes, and the data itself should be stored as elements

    也就是資料的ID 或是序號

    比方說

    <messages>
      <note id="501">
        <to>Tove</to>
        <from>Jani</from>
        <heading>Reminder</heading>
        <body>Don't forget me this weekend!</body>
      </note>

     

     

    arrow
    arrow
      全站熱搜

      找女人 發表在 痞客邦 留言(0) 人氣()