写入XML格式2D点 [英] Writing 2D points in XML format

查看:253
本文介绍了写入XML格式2D点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然XML编写2D点的数组我得到以下的输出:

While writing an array of 2D points in XML I get the following output:

<Vertices count="42">
  <V>
    <X>110</X>
    <Y>0</Y>
  </V>
  <V>
    <X>109.5105</X>
    <Y>3.0901</Y>
  </V>
  <V>
    <X>108.0901</X>
    <Y>5.8778</Y>
  </V>
  ...



在内部,我们正在讨论什么是最好的布局/标签命名写他们。下面是其他几个选项:

Internally we are discussing on what is the best layout/tag naming for writing them. Here are other few options:

<Vertices>
  <Point>110, 0</Point>
  <Point>109.5105, 3.0901</Point>
  <Point>108.0901, 5.8778</Point>
  ...

<Vertices>
  <item>110, 0</item>
  <item>109.5105, 3.0901</item>
  <item>108.0901, 5.8778</item>
  ...



假设你需要解析这个XML文件:

Suppose you'll need to parse this XML file:


  • 您想吃点什么布局最?

  • 根据XML规范什么布局更正确的?

感谢。

推荐答案

这是高度意见为主,所以这里是我的:

This is highly opinion-based, so here's mine:

我会去的第一种方法有以下几个原因:

I'd go for the first approach for several reasons:


  1. 这种数据格式可能是在内部只使用,因此也无所谓是否它是相当与否,只要它是机器可读的。

  2. 它是容易扩展。希望有一个Z坐标?那么,添加另一个元素。这是可能的而不会破坏现有的功能的!这意味着你的应用程序的版本,需要一个Z坐标仍然可以读取不包含它,并承担ž为0。您的应用程序的一个版本,不能处理Z坐标将完全忽略它的XML文件。

  3. 这是很容易可验证。你可以假设每一个坐标包含浮点值,可以使用标准方法如 XSD 。其他格式要求每个元素,这可能不包括在标准工具的内容更多的知识。

  1. This data format is probably used internally only, so it doesn't matter whether it is pretty or not, as long as it is machine readable.
  2. It is easily extensible. Want a Z-Coordinate? Well, add another element. This is possible without breaking existing functionality! This means that a version of your application that requires a Z-Coordinate can still read an XML file that does not contain it and assume Z as 0. A version of your application that can not handle a Z-Coordinate will simply ignore it.
  3. It is easily validatable. You can assume every coordinate to contain a float value, which can be validated using standard means like XSD. The other formats require more knowledge about the content of each element, which may not be included in standard tools.

在格式化的另一个选项是这样的:

Another option in formatting could be this:

<vertices>
    <vertex x="0.123" y="1.443" />
    <vertex x="1.321" y="0.334" />
</vertices>



的优点相同的列表为真此格式,只知道它更容易阅读为人类。

The same list of advantages is true for this format, only that it is easier to read for humans.

编辑:我忘了,对于解析它与你的第一个建议,要容易得多(这也是我上面给出),比你建议其他两种格式,这需要另一个字符串分割/剪裁操作每个点。

I forgot that for parsing it is much easier with your first suggestion (and the one I gave above) than the other two formats you suggested, which require another string splitting/trimming operation for each point.

这篇关于写入XML格式2D点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆