我应该将 XML 节点放入容器元素中吗?

发布于 2024-09-25 18:49:52 字数 781 浏览 2 评论 0原文

我正在创建一个看起来像这样的 XML 层次结构:

element A
  0+ element B
    0+ element C (has PCDATA)
      (more complex hierarchy below this one, not really relevant)
  0+ element D
  0+ element E
  0+ element F
  0-1 element G (has PCDATA)
  0-1 element H (has PCDATA)

因此,它在元素 A 下开始看起来有点“拥挤”。我是否应该添加容器元素来组织一些内容,如下所示

element A
  0-1 B-container
    0+ element B
      0-1 C-container
        0+ element C (has PCDATA)
          (more complex hierarchy below this one, not really relevant)
  0-1 D-container
    0+ element D
  0-1 E-container
    0+ element E
  0-1 F-container
    0+ element F
  0-1 element G (has PCDATA)
  0-1 element H (has PCDATA)

:元素 A 下面有一堆不同的元素?

该 XML 需要由主要由用户编写的 XSL 样式表使用,因此我试图找出什么使用户最容易与之交互。

I'm creating an XML hierarchy that looks something like this:

element A
  0+ element B
    0+ element C (has PCDATA)
      (more complex hierarchy below this one, not really relevant)
  0+ element D
  0+ element E
  0+ element F
  0-1 element G (has PCDATA)
  0-1 element H (has PCDATA)

As a result, it's starting to look a little "crowded" under element A. Should I add container elements to organize things a bit, like so:

element A
  0-1 B-container
    0+ element B
      0-1 C-container
        0+ element C (has PCDATA)
          (more complex hierarchy below this one, not really relevant)
  0-1 D-container
    0+ element D
  0-1 E-container
    0+ element E
  0-1 F-container
    0+ element F
  0-1 element G (has PCDATA)
  0-1 element H (has PCDATA)

Or is it fine to have a bunch of different elements underneath element A?

This XML needs to be consumed by XSL stylesheets mostly written by users, so I'm trying to figure out what makes it easiest for users to interact with.

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

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

发布评论

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

评论(1

奢欲 2024-10-02 18:49:52

我不认为这会对创建样式表的用户产生太大的影响,任何节点都可以使用选择器来选择,无论哪种方式 - 它只是不同,不一定更容易或更难。

我想说更重要的是确保您的数据结构提供数据的直观表示。如果您所代表的内容自然是分层的,请选择以这种方式表示它的结构。然后,该结构将更容易处理,因为它更容易记住和可视化,并且通常一起处理的节点将在树中彼此靠近。

哦,也不要忘记属性。在处理 XML 时,有时让我烦恼的一件事是,数据自然地感觉像属性(例如元素)。

I don't imagine it'll make that much of a difference to users who are creating stylesheets, any node can be selected using selectors either way - it'd just be different, not necessarily easier or harder.

I'd say it's more important to ensure that your data structure provides an intuitive representation of your data. If what you are representing is naturally hierarchical, go for a structure that represents it that way. Then, the structure will be easier to handle as it will be easier to remember and visualise, and nodes that would commonly be handled together will be close to each other in the tree.

Oh, and don't forget about attributes, either. One thing that bugs me sometimes when handling XML is data that feels naturally like an attribute - elements, for example.

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