开发者

XML Schema design decision

开发者 https://www.devze.com 2022-12-22 03:34 出处:网络
I am designing an XML schema to ho开发者_运维问答ld the output of my program. However, I am hesitating concerning a design decision, and I would like the input of more experienced programmers.

I am designing an XML schema to ho开发者_运维问答ld the output of my program. However, I am hesitating concerning a design decision, and I would like the input of more experienced programmers.

If I have a complex element

<list>

<elmt>1</elmt>

<elmt>2</elmt>

</list>

However, the nested elements in <list> are optional. My question is how should the file look like when no <elmt> exist?

Option 1:

<list/> or <list></list>

Option 2: <list size="0" />

Option 3: Remove the element <list> altogether.

I know that these 3 options may not have any difference, but does someone have any preference for some reason (I care more about faster reading of the XML file and easier programming than size)?


Definitely not option 2. I would prefer option 1 as programmer (the less flexible the schema is, the easier is parsing it) and option 3 as human being writing or reading the XML (fewer characters to type, less clutter). It depends on who is more important for you.


Depends if there are any attributes on <list>

If not <list> would not be present if there where no <elmt> members

If there are attributes on <list> e.g. <list thing="value"> then <list> would exist even though there where no <elmt> members

0

精彩评论

暂无评论...
验证码 换一张
取 消