O'Reilly logo

Effective XML: 50 Specific Ways to Improve Your XML by Elliotte Rusty Harold

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Java, C#, Python, and Perl

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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required