XML 文件是否应包含可以导出哪些节点?

发布于 2024-09-25 10:42:08 字数 1102 浏览 7 评论 0原文

我目前正在处理一个大型 XML 文件,其中某些元素包含 123 ,而其他元素则不包含它们。例如:

<Animals>
  <Pigs>
    <Pig ...>
      ...
    </Pig>
    <Pig ...>
      ...
    </Pig>
    <PricePerPound>13<PricePerPound>
    <Count>2</Count>
  </Pigs>
  <Chikens>
    <Chicken ...>
      ...
    </Chicken>
    <Chicken ...>
      ...
    </Chicken>
    <PricePerPound>12<PricePerPound>
    <!-- No Count -->
  </Chickens>
  ...
</Animals>

所以,实际的文件要复杂得多,并且与动物无关。我只是不会透露所有细节。该文件在启动时加载一次,退出时保存一次,文件大小约为 2 到 5 MB,具体取决于内容。

一方面,使用 可能会稍微加快加载时间,但也可能不会。另一方面,这个值不是必然的,它是衍生出来的,上帝禁止它偏离它应有的样子。计算/检索具有特定名称的节点的计数可能不需要太多工作(请注意 节点 - 如果忽略节点的名称,它可能会搞砸计数)。我在重新设计 XML 方面没有太大的灵活性,而且工作量太大。在任何地方添加或删除 都会需要大量工作(所有读取和写入 XML 部分的庞大逻辑......),但我想选择一种方法未来现在,这样我就可以逐步做到这一点。

那么,哪种方式似乎更好 - 在任何地方添加或删除 ,或者将其设为可选,然后将其写入“保存”,并最终将其设为强制,或者其他什么?

I am currently working with a large XML file which includes <Count>123</Count> for some elements and does not have them for others. For instance:

<Animals>
  <Pigs>
    <Pig ...>
      ...
    </Pig>
    <Pig ...>
      ...
    </Pig>
    <PricePerPound>13<PricePerPound>
    <Count>2</Count>
  </Pigs>
  <Chikens>
    <Chicken ...>
      ...
    </Chicken>
    <Chicken ...>
      ...
    </Chicken>
    <PricePerPound>12<PricePerPound>
    <!-- No Count -->
  </Chickens>
  ...
</Animals>

So, the actual file is a lot more complicated, and has nothing to do with animals. I just will not reveal all of the details. The file is loaded once at start and saved once on exit, it weighs about 2 to 5 Megabytes, depending on the content.

On one hand, having <Count> could potentially speed up loading time a bit, but maybe not. On the other, this value is not necessary, it is derived, and God forbid it deviates from what it should have been. It might not be that much work to compute/retrieve the count of nodes with particular name (note the <PricePerPound> node - it can screw up the count if one were to ignore the names of the nodes). I do not have too much flexibility in redesigning the XML, plus it would be too much work. Either adding or removing <Count> everywhere would be a lot of work (all of that bulky logic which reads and writes portions of the XML ...), but I want to pick an approach for the future now, so that I can do this in increments.

So, which way seems better - add or remove <Count> everywhere, or perhaps make it optional, and write it on Save, and eventually make it mandatory, or something else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赠佳期 2024-10-02 10:42:08

除非有良好的性能原因将其放置在那里,否则我同意这不是一个好的设计决策,并且会投票赞成将其从结构中删除 - 它很容易计算并且可能会损坏。

Unless there is a good performance reason for having it there, I'd agree that it is not a good design decision and would vote for removing it from the structure - it can be easily calculated and can become corrupt.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文