[英]XML Design - Performance and Efficiency
我正在为类别创建XML映射文件。 我想知道正确的方法将考虑我所考虑的两个选项。
我的主要问题是可能不得不读取XML文件的php代码的速度/效率。 所以这是我的第一种方法
<?xml version="1.0" encoding="utf-8"?>
<category-map lang="en_US" reader="Candor Framework">
<for-her url="/content/syl/tags/for-her">
<women-tops url="/content/syl/category/15/women-tops">
<women-longsleeve-tops url="/content/syl/tags/women-longsleeve-tops">Longsleeve Tops</women-longsleeve-tops>
<women-shortsleeve-tops url="/content/syl/tags/women-shortsleeve-tops">Shortsleeve Tops</women-shortsleeve-tops>
</women-tops>
<women-gowns url="/content/syl/category/18/women-gowns/">
<short-gowns url="/content/syl/tags/short-gowns">Short Gowns</short-gowns>
<evening-gowns url="/content/syl/tags/evening-gowns">Evening Gowns</evening-gowns>
</women-gowns>
<women-shoes url="/content/syl/category/19/women-shoes/">
<women-highheel-shoes url="/content/syl/tags/women-highheel-shoes">High Heel Shoes</women-highheel-shoes>
<women-wedge-shoes url="/content/syl/tags/women-wedge-shoes">Wedge Shoes</women-wedge-shoes>
</women-shoes>
</for-her>
<for-him url="/content/syl/tags/for-him">
<men-shirt url="/content/syl/category/20/men-shirt">
<men-lonsleeve-shirt url="/content/syl/tags/men-longsleeve-shirt">Longsleeve Shirt</women-longsleeve-tops>
</men-shirt>
</for-him>
</category-map>
通过这种方法,所有XML标签都有唯一的名称。 现在与第二种方法进行比较。
<?xml version="1.0" encoding="utf-8"?>
<category-map lang="en_US" reader="Candor Framework">
<target name="for-her" url="/content/syl/tags/for-her">
<category name="women-tops" url="/content/syl/category/15/women-tops">
<tag name="women-longsleeve-tops" url="/content/syl/tags/women-longsleeve-tops">Longsleeve Tops</tag>
<tag name="women-shortsleeve-tops" url="/content/syl/tags/women-shortsleeve-tops">Shortsleeve Tops</tag>
</category>
<category name="women-gowns" url="/content/syl/category/18/women-gowns/">
<tag name="short-gowns" url="/content/syl/tags/short-gowns">Short Gowns</tag>
<tag name="evening-gowns" url="/content/syl/tags/evening-gowns">Evening Gowns</tag>
</category>
<category name="women-shoes" url="/content/syl/category/19/women-shoes/">
<tag name="women-highheel-shoes" url="/content/syl/tags/women-highheel-shoes">High Heel Shoes</tag>
<tag name="women-wedge-shoes" url="/content/syl/tags/women-wedge-shoes">Wedge Shoes</tag>
</category>
</target>
<target name="for-him" url="/content/syl/tags/for-him">
<category name="men-shirt" url="/content/syl/category/20/men-shirt">
<tag name="men-lonsleeve-shirt" url="/content/syl/tags/men-longsleeve-shirt">Longsleeve Shirt</tag>
</category>
</target>
</category-map>
这是XML文件的简短版本。 整个内容很多。 这些设计方法中哪一种更快?需要较少的循环和条件? 建议遵循哪个,为什么?
非常感激!
我认为第二个是最好的,纯粹是因为它更通用,因此无需任何更新即可扩展。
我将XML视为代码与其他代码块进行通信的一种机制,因此该结构应反映出最适合代码的内容,而不必具有任何使人类易于阅读的结构。 对我来说,第一个XML看起来像是为人类而不是计算机编写的,而第二个XML更符合数据库存储信息的方式:即,选择target == for-him和catagory == men的行-衬衫。
在性能方面,我想它们是等效的,因为您可能会发现两个代码都相同,因为第一个XML实际上使用的是元素名称而不是名称属性。 如果您的代码可以扩展以准备在第一种情况下添加新元素,则情况尤其如此。
如果您有大量数据,请考虑使用反映第二个XML的模式将其存储在数据库中,而不是像sqlite这样存储在数据库中。 然后,您可以将任何查询结果导出到XML或JSON。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.