XML attribute vs XML element

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

    "XML" stands for "eXtensible Markup Language". A markup language implies that the data is text, marked up with metadata about structure or formatting.

    XHTML is an example of XML used the way it was intended:

    <p><span lang="es">El Jefe</span> insists that you
        <em class="urgent">MUST</em> complete your project by Friday.</p>
    

    Here, the distinction between elements and attributes is clear. Text elements are displayed in the browser, and attributes are instructions about how to display them (although there are a few tags that don't work that way).

    Confusion arises when XML is used not as a markup language, but as a data serialization language, in which the distinction between "data" and "metadata" is more vague. So the choice between elements and attributes is more-or-less arbitrary except for things that can't be represented with attributes (see feenster's answer).

    0 讨论(0)
  • 2020-11-22 02:21

    When in doubt, KISS -- why mix attributes and elements when you don't have a clear reason to use attributes. If you later decide to define an XSD, that will end up being cleaner as well. Then if you even later decide to generate a class structure from your XSD, that will be simpler as well.

    0 讨论(0)
提交回复
热议问题