XML attribute vs XML element

前端 未结 20 2587
暖寄归人
暖寄归人 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:13

    I am always surprised by the results of these kinds of discussions. To me there is a very simple rule for deciding whether data belongs in an attribute or as content and that is whether the data has navigable sub-structure.

    So for example, non-markup text always belongs in attributes. Always.

    Lists belong in sub-structure or content. Text which may over time include embedded structured sub-content belong in content. (In my experience there is relatively little of this - text with markup - when using XML for data storage or exchange.)

    XML schema written this way is concise.

    Whenever I see cases like FordRed, I think to myself "gee did the author think that there were going to be sub-elements within the make element?" is significantly more readable, there's no question about how whitespace would be handled etc.

    Given just but the whitespace handling rules, I believe this was the clear intent of the XML designers.

提交回复
热议问题