0

I just wanna an XSD for any xml elements with as many roots as possible. The restriction is that there shouldn't be any self closing tag and no attributes allowed. Any level of nesting allowed. For example,

<a>A<b>BB</b><c></c></a><d>aa</d>

Note there are multiple roots and no attribute and no self closing.

Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322

1 Answers1

2

(1) If a document isn't well-formed, then it won't validate against any schema. A document will multiple root elements isn't well-formed.

(2) You can't use XSD to impose purely lexical constraints on your XML, for example to restrict the amount of whitespace between attributes, or the choice of single-or-double quotes, or the use of decimal-versus-hexadecimal character references, or the choice between <a></a> versus <a/> to represent an empty element. Receiving applications aren't supposed to care about these differences, and if they use a conforming XML parser they will never know about the differences anyway. XSD is for validating the logical structure, the stuff that applications do care about.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • So whats the proper way to validate this. – Imran Qadir Baksh - Baloch Jun 16 '16 at 13:14
  • @user960567: You've received a thorough answer explaining that your textual data is not XML and is therefore not able to be validated using XML standards such as XSD. You would probably benefit from reading more about the [difference between well-formed vs valid XML](http://stackoverflow.com/a/25830482/290085). The "proper" way forward is to make your data well-formed XML. Otherwise, you're on your own to define a new language (not XML) and build new parsing and validating tools for that language. – kjhughes Jun 16 '16 at 13:48
  • You can of course validate this by turning it into well-formed XML and validating the result of the conversion. This might be as simple as adding `` at the beginning and `` at the end. But there are still further problems ahead. You can't prevent self-closing tags, because that's a lexical restriction rather than a structural constraint. You can allow elements with any name using wildcards, but you can't constrain the structure of such elements (e.g. to have no attributes): if you want to allow elements with arbitrary names, you also have to allow them to have arbitrary content. – Michael Kay Jun 16 '16 at 14:48