Class JsonXmlValidator

java.lang.Object
uk.blankaspect.common.jsonxml.JsonXmlValidator

public class JsonXmlValidator extends Object
This class provides some static methods for validating a tree of JSON-XML elements against an XML Schema (XSD).
  • A method that validates a JSON-XML tree against one of two predefined schemas according to a flag that is an argument of the method. One schema has a target namespace; the other does not have a target namespace.
  • A method that validates a JSON-XML tree against a schema that is created from a resource at a specified location.
  • A method that validates a JSON-XML tree against a schema that is created from a file at a specified file-system location.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The name of the namespace in the XML Schema for JSON-XML that has a target namespace.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    validate(Class<?> cls, String xsdPathname, Element element)
    Validates a tree of JSON-XML elements whose root is the specified element against an XML Schema (XSD) that is created from a resource at the specified location.
    static void
    validate(Path xsdFile, Element element)
    Validates a tree of JSON-XML elements whose root is the specified element against an XML Schema (XSD) that is created from a file at the specified file-system location.
    static void
    validate(Element element, boolean hasTargetNamespace)
    Validates a tree of JSON-XML elements whose root is the specified element against one of two predefined XML Schemas (XSD) according to the specified flag.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • NAMESPACE_NAME

      public static final String NAMESPACE_NAME
      The name of the namespace in the XML Schema for JSON-XML that has a target namespace.
      See Also:
  • Method Details

    • validate

      public static void validate(Element element, boolean hasTargetNamespace) throws BaseException
      Validates a tree of JSON-XML elements whose root is the specified element against one of two predefined XML Schemas (XSD) according to the specified flag. One schema has a target namespace; the other does not have a target namespace.
      Parameters:
      element - the root of the tree of JSON-XML elements that will be validated against one of two predefined schemas according to hasTargetNamespace.
      hasTargetNamespace - if true, the JSON-XML tree will be validated against a schema that has a target namespace; if false, the JSON-XML tree will be validated against a schema that does not have a target namespace.
      Throws:
      BaseException - if an error occurs when validating the tree of JSON-XML elements.
    • validate

      public static void validate(Class<?> cls, String xsdPathname, Element element) throws BaseException
      Validates a tree of JSON-XML elements whose root is the specified element against an XML Schema (XSD) that is created from a resource at the specified location.
      Parameters:
      cls - the class with which the schema-file resource is associated. If it is null, the system class loader will be used to find the resource.
      xsdPathname - the pathname of the schema-file resource.
      element - the root of the tree of JSON-XML elements that will be validated.
      Throws:
      BaseException - if an error occurs when
      • loading the schema-file resource,
      • creating an XML Schema from the resource, or
      • validating the tree of JSON-XML elements.
    • validate

      public static void validate(Path xsdFile, Element element) throws BaseException
      Validates a tree of JSON-XML elements whose root is the specified element against an XML Schema (XSD) that is created from a file at the specified file-system location.
      Parameters:
      xsdFile - the file-system location of the schema file.
      element - the root of the tree of JSON-XML elements that will be validated.
      Throws:
      BaseException - if an error occurs when
      • reading the schema file,
      • creating an XML Schema from the contents of the file, or
      • validating the tree of JSON-XML elements.