XML, DTD: how to make the order not important

后端 未结 5 429
难免孤独
难免孤独 2020-12-06 05:27

I started off using an XML file and a parser as a convenient way to store my data

I want to use DTD to check the structure of the xml files when they arrive.

5条回答
  •  佛祖请我去吃肉
    2020-12-06 06:04

    With a DTD the child nodes have to appear in the order listed in the element definition. There is no way to allow for alternative orderings, unless you want to upgrade to an XSD schema.

    Addendum: Per @Gaim, you can offer alternative orders using the (a,b,c...)|(b,a,c...) syntax, but this is not really practical for more than, say, 3 nested elements, since an arbitrary order allows for a factorial number of orderings -- 6 for 3 elements, 24 for 4 elements, 120 for 5 elements -- and clever use of ? operators is sure to result in false validation for strange cases.

提交回复
热议问题