设计XML模式的最佳实践是什么?[英] What are best practices for designing XML schemas?

本文是小编为大家收集整理的关于设计XML模式的最佳实践是什么?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

作为一名业余软件开发人员(我还在学术界),我为 XML 文档编写了一些模式.我经常遇到导致 XML 文档难看的设计错误,因为我不完全确定 XML 的语义到底是什么.

我的假设:

<property> value </property>

属性 = 价值

<property attribute="attval"> value </property>

具有特殊描述符的属性,即属性.

<parent>
  <child> value </child>
</parent>

父母有一个特征"孩子",其值为"价值".

<tag />

"标签"是一个标志或直接翻译成文本.这个我不确定.

<parent>
  <child />
</parent>

"孩子"描述"父母"."child"是一个标志或布尔值.这个我也不确定.

如果您想做诸如表示笛卡尔坐标之类的事情,就会出现歧义:

<coordinate x="0" y="1 />

<coordinate> 0,1 </coordinate>

<coordinate> <x> 0 </x> <y> 1 </y> </coordinate>

其中哪一个是最正确的?根据我目前对 XML 模式设计的概念,我会倾向于第三种,但我真的不知道.

有哪些资源可以简洁地描述如何有效地设计 xml 模式?

推荐答案

看教程:

我也推荐:

本文地址:https://www.itbaoku.cn/post/627359.html

问题描述

As an amateur software developer (I'm still in academia) I've written a few schemas for XML documents. I routinely run into design flubs that cause ugly-looking XML documents because I'm not entirely certain what the semantics of XML exactly are.

My assumptions:

<property> value </property>

property = value

<property attribute="attval"> value </property>

A property with a special descriptor, the attribute.

<parent>
  <child> value </child>
</parent>

The parent has a characteristic "child" which has the value "value."

<tag />

"Tag" is a flag or it directly translates to text. I'm not sure on this one.

<parent>
  <child />
</parent>

"child" describes "parent." "child" is a flag or boolean. I'm not sure on this one, either.

Ambiguity arises if you want to do something like representing cartesian coordinates:

<coordinate x="0" y="1 />

<coordinate> 0,1 </coordinate>

<coordinate> <x> 0 </x> <y> 1 </y> </coordinate>

Which one of those is most correct? I would lean towards the third based upon my current conception of XML schema design, but I really don't know.

What are some resources that succinctly describe how to effectively design xml schemas?

推荐答案

See the tutorial:

I also recommend: