Validating XML with XSDs … but still allow extensibility

前端 未结 5 1022
梦谈多话
梦谈多话 2020-12-13 06:38

Maybe it\'s me, but it appears that if you have an XSD




        
5条回答
  •  清歌不尽
    2020-12-13 07:35

    RelaxNG will solve this problem succinctly, if you can use it. Determinism isn't a requirement for schemas. You can translate an RNG or RNC schema into XSD, but it will approximate in this case. Whether that's good enough for your use is up to you.

    The RNC schema for this case is:

    start = User
    User = element User {
       attribute ID { xsd:unsignedByte },
       ( element GivenName { text } &
         element SurName { text } &
         element * - (SurName | GivenName) { any })
    }
    
    any = element * { (attribute * { text } | text | any)* }
    

    The any rule matches any well-formed XML fragment. So this will require the User element to contain GivenName and SurName elements containing text in any order, and allow any other elements containing pretty much anything.

提交回复
热议问题