我正在为一个使用这种XML结构的客户工作,为他的网站内容:
<section title="title1" layoutType="VideoViewer" xmlPath="xml/ita/title1.xml" pageTitle="extended title" previewImg=""/>
<section title="another title" layoutType="TimeLine" xmlPath="xml/ita/timeline.xml" textFile="" pageTitle="extended title for timeline"></section>
Run Code Online (Sandbox Code Playgroud)
我对XML很陌生,但这对我来说并不好看.除了关闭标签的不同方式(自动关闭/>或显式关闭</section>)我会认为XML应该更像
<section>
<title>title1</title>
<layoutType>"VideoViewer" </layoutType>
<xmlPath>xml/ita/title1.xml </xmlPath>
<pageTitle>extended title</pageTitle>
<previewImg/>
</section>
<section>
...etc etc..
</section>
Run Code Online (Sandbox Code Playgroud)
你怎么看?
如果他们都没问题,是否有"最佳实践"?
只要所有元素都包含在单个根元素中,就没有任何实际的错误.
任何一种结束标记都是可以接受的,尽管我建议所有没有其他标记的元素的自闭标记.
至于结构(标签与属性),这是一个意见问题,根据定义,两种选择都不是更好.