XML文件将无法验证

时间:2012-04-12 21:06:44

标签: xml validation xsd dtd

给出以下xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Clients SYSTEM "bank.dtd">
<Clients>
    <account>
        <number>323</number>

        <client>
            <address>
                <street>Sliders</street>
                <city>Tokyo</city>
            </address>
            <identity>1212</identity>
        </client>

        <client>           // HERE IS THE PROBLEM
            <address>
                <street>Jason</street>
                <city>Paris</city>
            </address>
            <identity>1313</identity>
        </client>

        <totoalSum>43333</totoalSum>
    </account>
</Clients>

及其DTD文件:

<?xml version="1.0" encoding="utf-8"?>
<!ELEMENT Clients (account+)>
<!ELEMENT account (number,client,totoalSum)>
<!ELEMENT client (address,identity)>
<!ELEMENT address (street,city)>
<!ELEMENT number (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT identity (#PCDATA)>
<!ELEMENT totoalSum (#PCDATA)>

我无法验证它。 XMLspy说:

Content model of element 'account' disallows element 'client' at this position.

其中,有问题的行在上面用“HERE”标记。

知道可能导致这种情况的原因是什么?

问候

1 个答案:

答案 0 :(得分:2)

client个元素中有2个account个元素。那就是问题!

尝试使用以下内容更改DTD

<!ELEMENT account (number,client+,totoalSum)>