What are fixed format files and how is XML better than them?

时间:2021-08-04 20:54:12

I searched google for fixed format file (FFF) and got these to results:

我搜索谷歌的固定格式文件(FFF)并得到这些结果:

I am not sure which one is a fixed format file. Is the second one FFF or its something else ?

我不确定哪一个是固定格式文件。第二个是FFF还是别的什么?

What problems did FFF solve and how does XML solve them better than FFF ? Are there any disadvantages of XML format when compared to FFF ?

FFF解决了什么问题以及XML如何比FFF更好地解决它们?与FFF相比,XML格式有任何缺点吗?

Thanks in advance.

提前致谢。

2 个解决方案

#1


5  

The biggest advantage of a FFF over XML is built-in capability of index-based random-access. The contra-positive is obvious, the biggest disadvantage of XML compared to FFF is the linear fashion in which it must be parsed.

FFF优于XML的最大优势是基于索引的随机访问的内置功能。矛盾是显而易见的,与FFF相比,XML的最大缺点是必须解析它的线性方式。

Suppose you have a data file holding person records. The records can hold an id, name, address, and telephone number.

假设您有一个包含人员记录的数据文件。记录可以包含ID,姓名,地址和电话号码。

Fixed Format

ID          : 8 chars
Surname     : 36 chars
Firstname   : 36 chars
Address     : 100 chars
Phone       : 20 chars
-----------------------
Total Space: 200 chars

XML Format (contrived, could be a number of formats)

XML格式(设计,可以是多种格式)

<Person id="...">
   <Surname>...</>
   <Firstname>...</>
   <Address>...</>
   <Phone>...</>
</Person>

Total Space : Variant

Now, suppose this has 1000 "records" Lets see how difficult it is to get to the 600th person record with both forms.

现在,假设这有1000个“记录”让我们看看用两种形式获得第600个人的记录是多么困难。

Fixed Format

Offset = (600-1)*200 = 119800 bytes
fseek() + fread() = done

XML Format

Um..... 

XML's biggest forte is extensibility (that X didn't come from nothing). XML makes a fantastic data-snippet, RSS feed, configuration file, etc. It is easy to emit without special libraries and only basic knowhow, and can be reasonable in storage space (so long as you don't go <LoveThoseSuperDuperLongElementNames> nuts). It is easy to understand, backed by boatloads of standards, and just about everyone that's anyone has an XML parser in their toolkit. Universal "understanding" is just a schema document (DTD for the old-schoolers) away, as is validation, etc.

XML最大的优点是可扩展性(X并非来自任何东西)。 XML提供了一个非常棒的数据片段,RSS提要,配置文件等。它很容易在没有特殊库和基本知识的情况下发出,并且在存储空间中可以合理(只要你不去 坚果) 。它很容易理解,有大量标准支持,几乎每个人都有自己的工具包中的XML解析器。普遍的“理解”只是一个模式文档(老学者的DTD),以及验证等。

But XML's biggest downside has been, is now, and until quantum computing leaps a long way, always will be: speed. XML is a terrible throughput-mandated storage system.

但是,XML的最大缺点是,现在,直到量子计算*,总是会:速度。 XML是一种糟糕的吞吐量强制存储系统。

#2


3  

Since you're comparing with XML, I'm assuming you mean a fixed width text file (the latter of your examples). Saying which is "better" isn't easy, it very much depends on your use case.

由于您要与XML进行比较,我假设您的意思是固定宽度的文本文件(后面的示例)。说哪个“更好”并不容易,这在很大程度上取决于你的用例。

Some advantages of XML;

XML的一些优点;

  • Flexible (ie fields can be longer/shorter or may even be added without breaking existing code)
  • 灵活(即字段可以更长/更短,甚至可以在不破坏现有代码的情况下添加)

  • There are many implementations to choose from.
  • 有许多实现可供选择。

  • You can define it more or less fully using machine readable schemas.
    (that means a computer can generate code to read and validate the file to some extent if you just have a schema defining the file)
  • 您可以使用机器可读模式或多或少地完全定义它。 (这意味着如果您只有一个定义文件的模式,计算机可以生成在某种程度上读取和验证文件的代码)

Some advantages to fixed width files;

固定宽度文件的一些优点;

  • Much simpler, both reading and writing a file is more or less trivial.
  • 更简单的是,读取和写入文件或多或少都是微不足道的。

  • May take less space, XML is rather "chatty".
  • 可能占用更少的空间,XML相当“健谈”。

#1


5  

The biggest advantage of a FFF over XML is built-in capability of index-based random-access. The contra-positive is obvious, the biggest disadvantage of XML compared to FFF is the linear fashion in which it must be parsed.

FFF优于XML的最大优势是基于索引的随机访问的内置功能。矛盾是显而易见的,与FFF相比,XML的最大缺点是必须解析它的线性方式。

Suppose you have a data file holding person records. The records can hold an id, name, address, and telephone number.

假设您有一个包含人员记录的数据文件。记录可以包含ID,姓名,地址和电话号码。

Fixed Format

ID          : 8 chars
Surname     : 36 chars
Firstname   : 36 chars
Address     : 100 chars
Phone       : 20 chars
-----------------------
Total Space: 200 chars

XML Format (contrived, could be a number of formats)

XML格式(设计,可以是多种格式)

<Person id="...">
   <Surname>...</>
   <Firstname>...</>
   <Address>...</>
   <Phone>...</>
</Person>

Total Space : Variant

Now, suppose this has 1000 "records" Lets see how difficult it is to get to the 600th person record with both forms.

现在,假设这有1000个“记录”让我们看看用两种形式获得第600个人的记录是多么困难。

Fixed Format

Offset = (600-1)*200 = 119800 bytes
fseek() + fread() = done

XML Format

Um..... 

XML's biggest forte is extensibility (that X didn't come from nothing). XML makes a fantastic data-snippet, RSS feed, configuration file, etc. It is easy to emit without special libraries and only basic knowhow, and can be reasonable in storage space (so long as you don't go <LoveThoseSuperDuperLongElementNames> nuts). It is easy to understand, backed by boatloads of standards, and just about everyone that's anyone has an XML parser in their toolkit. Universal "understanding" is just a schema document (DTD for the old-schoolers) away, as is validation, etc.

XML最大的优点是可扩展性(X并非来自任何东西)。 XML提供了一个非常棒的数据片段,RSS提要,配置文件等。它很容易在没有特殊库和基本知识的情况下发出,并且在存储空间中可以合理(只要你不去 坚果) 。它很容易理解,有大量标准支持,几乎每个人都有自己的工具包中的XML解析器。普遍的“理解”只是一个模式文档(老学者的DTD),以及验证等。

But XML's biggest downside has been, is now, and until quantum computing leaps a long way, always will be: speed. XML is a terrible throughput-mandated storage system.

但是,XML的最大缺点是,现在,直到量子计算*,总是会:速度。 XML是一种糟糕的吞吐量强制存储系统。

#2


3  

Since you're comparing with XML, I'm assuming you mean a fixed width text file (the latter of your examples). Saying which is "better" isn't easy, it very much depends on your use case.

由于您要与XML进行比较,我假设您的意思是固定宽度的文本文件(后面的示例)。说哪个“更好”并不容易,这在很大程度上取决于你的用例。

Some advantages of XML;

XML的一些优点;

  • Flexible (ie fields can be longer/shorter or may even be added without breaking existing code)
  • 灵活(即字段可以更长/更短,甚至可以在不破坏现有代码的情况下添加)

  • There are many implementations to choose from.
  • 有许多实现可供选择。

  • You can define it more or less fully using machine readable schemas.
    (that means a computer can generate code to read and validate the file to some extent if you just have a schema defining the file)
  • 您可以使用机器可读模式或多或少地完全定义它。 (这意味着如果您只有一个定义文件的模式,计算机可以生成在某种程度上读取和验证文件的代码)

Some advantages to fixed width files;

固定宽度文件的一些优点;

  • Much simpler, both reading and writing a file is more or less trivial.
  • 更简单的是,读取和写入文件或多或少都是微不足道的。

  • May take less space, XML is rather "chatty".
  • 可能占用更少的空间,XML相当“健谈”。