None of the common schema languages are Turing complete. Thus none of them can state and verify every possible constraint on an XML document. For example, none of them can verify that the content of a `Prime `element is in fact a prime number. However, this verification is straightforward in any reasonably powerful programming language. For example, here's a very naïve algorithm implemented in Java that accomplishes this task by dividing the number by every integer between 2 and its square root until it finds a divisor.

public void isPrime(String text) { int test; try { test = Integer.parseInt(text); } catch (NumberFormatException ex) { return false; } if (test < 2) return false; for (int i = 2; i < Math.sqrt(test); ...

Start Free Trial

No credit card required