简体   繁体   English

哪个DTD会使第一个XML文档有效而第二个无效?

[英]Which DTD would make the first XML document valid and the second invalid?

I'm looking for a DTD which would make the first XML document valid and the second invalid, if it's possible. 我正在寻找一种DTD,如果可能的话,它将使第一个XML文档有效,而第二个无效。

First XML: 第一个XML:

<A>
    <B>
        <C>bla</C>
        <D>bla</D>
        <C>bla</C>
        <D>bla</D>
        <D>bla</D>
    </B>
    <B>
        <C>bla</C>
        <D>bla</D>
        <C>bla</C>
        <D>bla</D>
    </B>
</A>

Second XML: 第二个XML:

<A>
    <B>
        <C>bla</C>
        <D>bla</D>
        <C>bla</C>
        <C>bla</C>
        <D>bla</D>
        <D>bla</D>
    </B>
    <B>
        <C>bla</C>
        <D>bla</D>
        <C>bla</C>
        <D>bla</D>
    </B>
</A>

I've got this one, but it does not exclude the second: 我已经有了这个,但是它并不排除第二个:

<!DOCTYPE A [
<!ELEMENT A (B+)>
<!ELEMENT B (C|D)+>
<!ELEMENT C (#PCDATA)>
<!ELEMENT D (#PCDATA)>
]}

It depends on what you want to accomplish semantically. 这取决于您要在语义上完成什么。 Often, thinking in terms of the application domain - rather than completely opaque As Bs and Cs - clarifies requirements. 通常,从应用程序域的角度考虑-而不是像Bs和Cs那样完全不透明-可以明确要求。 Here, one can only guess at the real pattern to be captured. 在这里,人们只能猜测要捕获的真实模式。 For instance, this would answer your question, but would it address what you really need? 例如,这可以回答您的问题,但是可以解决您的真正需求吗?

<!ELEMENT A (B+)>
<!ELEMENT B (C,D+)+>
<!ELEMENT C (#PCDATA)>
<!ELEMENT D (#PCDATA)>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM