XML,DTD:如何使顺序不重要 [英] XML, DTD: how to make the order not important

查看:65
本文介绍了XML,DTD:如何使顺序不重要的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用XML文件和解析器作为存储数据的便捷方式

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

我想使用DTD在以下情况下检查xml文件的结构:

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

这是我的DTD文件

< ?xml version="1.0" encoding="UTF-8"?>
< !ELEMENT document (level*)>
< !ELEMENT level (file,filelName?,fileNumber?)>
< !ELEMENT file (#PCDATA)>
< !ELEMENT filelName (#PCDATA)>
< !ELEMENT fileNumber (#PCDATA)>

(请注意,fileName和fileNumber实际上完全是可选的)

(note that fileName and fileNumber are actually purely optional)

<document>
 <level>
  <file>group1file01</file>
 </level>
 <level>
  <file>group1file02</file>
  <fileName>file 2</fileName>
  <fileNumber>0</fileNumber>
 </level>
...

这样,所有这些工作正常。 (我现在使用eclipse的 validate选项进行测试)

as such all this works fine. (I use eclipse "validate" option to test it for now)

但是在测试时我得到了我认为是一个奇怪的错误

however while testing I got what I think is a wierd error

如果我愿意

 <level>
  <levelName>Level 2</levelName>
  <levelNumber>0</levelNumber>
        <file>group1level02</file>
 </level>

更改行的顺序,Eclipse拒绝对其进行验证...

changing the order of the lines, Eclipse refuses to validate it ...

我想知道这是否是Eclipse的问题,或者订单是否确实重要。

I was wondering if this was a problem with Eclipse or if the order is actually important.

如果订单很重要,我该怎么办?更改DTD使其无论其元素的顺序如何都能起作用?

If the order is important how can I change the DTD to make it work no matter the ordering of he elements?

我真的不能更改XML,因为我已经编写了所有XML文件和解析器(我知道我做错了大声笑)。

I can't really change the XML because I already have all the XML files and the parser written (I know I did it the wrong way round lol).

推荐答案

正如罗杰所说,只有有序列表,但是您可以使用运算符OR | 定义所有可接受的组合

As Roger said, there are only ordered lists, but you can use operator OR | to define all accepted combinations

<!ELEMENT level ((file,filelName?,fileNumber?)|(filelName?,fileNumber?,file))>

查看此处,在选择

这篇关于XML,DTD:如何使顺序不重要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆