【问题标题】:What is the best way to represent image nodes in a product (item) XML schema?在产品(项目)XML 模式中表示图像节点的最佳方式是什么?
【发布时间】:2010-09-21 16:19:32
【问题描述】:

我有一个表示数据库中产品的 XML 模式,我正在尝试找出将产品图像引用存储为 XML 节点的最佳方法。将有一个主图像,然后是备用图像,每个图像都有序列(显示顺序)。这是一种合适的格式,还是有更好的方法:

<item>
    <id></id>
    <images>
        <image width="" height="" href="" alt="" sequence="1" />
        <image width="" height="" href="" alt="" sequence="2" />
        <image width="" height="" href="" alt="" sequence="3" />
        <image width="" height="" href="" alt="" sequence="4" />
    </images>
</item>

显然会有比这更多的节点,但我不会全部显示。我想我的主图像将永远是序列中的第一个。我遇到的问题是这些图像中的每一个都有一个缩略图、中型和大型图像,所以我认为这需要进一步分解。

【问题讨论】:

    标签: xml schema


    【解决方案1】:

    稍微扩展 Greg 的设计:将图像大小设置为元素名称而不是将size 设置为属性可能是合适的,即:

    <imageset>
       <thumbnail width=""... />
       <medium width="".../>
       <large width="".../>
    </imageset>
    

    这有两个原因。

    首先,名称imageset 已经告诉您它的子元素将是图像,因此将子元素命名为image 是多余的。使用imageset/* 的XPath 模式与使用imageset/image 一样容易,编写imageset/medium 比编写imageset/image[@size='medium'] 稍微容易一些。

    更重要的原因是这种设计允许您的架构指定imageset 元素必须包含每种类型的图像中的一种。 (或者指定一种或多种图像类型是可选的。)

    【讨论】:

      【解决方案2】:

      由于 XML 元素具有自然顺序(即它们在 XML 文件中出现的顺序),因此包含 sequence 属性可能是多余的。您仍然可以谈论元素的顺序,并且主要产品图片仍然有一个“第一个”。

      也许:

      <images>
          <imageset>
              <image size="thumbnail" width="" height="" href="" alt="" />
              <image size="medium" width="" height="" href="" alt="" />
              <image size="large" width="" height="" href="" alt="" />
          </imageset>
          <imageset>
              <image size="thumbnail" width="" height="" href="" alt="" />
              <image size="medium" width="" height="" href="" alt="" />
              <image size="large" width="" height="" href="" alt="" />
          </imageset>
      </images>
      

      【讨论】:

        猜你喜欢
        • 2013-10-25
        • 2014-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多