哪个更好的XML:嵌套元素或属性?

时间:2014-12-07 01:41:02

标签: xml coding-style format

传统上,我使用过这样的XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "example.dtd">
<log>
    <record>
        <date>2014-05-16T17:58:52</date>
        <level>INFO</level>
        <message>This is the English stuff to present to humans.</message>
    </record>
    <record>
        <date>2014-05-16T17:59:00</date>
        <level>FINE</level>
        <message>Core crashed. Attempting smooth restart...</message>
        <exception>
            <message>Concurrent Modification Exception</message>
            <frame>
                <class>java.util.ArrayList$Itr</class>
                <method>checkForComodification</method>
                <line>859</line>
            </frame>
            <frame>
                <class>java.util.ArrayList$Itr</class>
                <method>next</method>
                <line>831</line>
            </frame>
            <frame>
                <class>com.name.app.Main$3</class>
                <method>run</method>
                <line>120</line>
            </frame>
            <frame>
                <class>java.lang.Thread</class>
                <method>run</method>
                <line>744</line>
            </frame>
        </exception>
    </record>
</log>

但是最近我学会了Android以及他们如何做XML,并爱上了这种格式:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE log SYSTEM "example2.dtd">
<log>
    <record
        date="2014-05-16T17:58:52"
        level="INFO"
        message="This is the English stuff to present to humans."/>
    <record
        date="2014-05-16T17:59:00"
        level="FINE"
        message="Core crashed. Attempting smooth restart...">
        <exception
            message="Concurrent Modification Exception">
            <frame
                class="java.util.ArrayList$Itr"
                method="checkForComodification"
                line="859"/>
            <frame
                class="java.util.ArrayList$Itr"
                method="next"
                line="831"/>
            <frame
                class="com.name.app.Main$3"
                method="run"
                line="120"/>
            <frame
                class="java.lang.Thread"
                method="run"
                line="744"/>
        </exception>
    </record>
</log>

其中任何一个都比另一个好吗?是一个鼓励,还是另一个更快解析?有什么优点或缺点,或者只是偏好?

0 个答案:

没有答案
相关问题