aboutsummaryrefslogtreecommitdiff
path: root/scripts/rpki/relaxng.py
blob: 072d77982eac18bd53ef6a868a3bc3c61460f5be (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# $Id$

import os

def relaxng(xml, rng):
  """
  Validate a chunk of xml against a RelaxNG schema.
  """

  # We could use either xmllint or jing here, but xmllint is easier.
  # How to invoke jing, just in case:
  #
  # java -jar /usr/local/share/java/classes/jing.jar schema.rng foo.xml
  #
  # If error messages from xmllint are incomprehensible, try jing too.

  i, o = os.popen4(("xmllint", "--noout", "--relaxng", rng, "-"))
  i.write(xml)
  i.close()
  v = o.read()
  o.close()
  if v != "- validates\n":
    raise RuntimeError, "RelaxNG validation failure:\n" + v