uk.org.ogsadai.common
Class XMLSchemaUtilities

java.lang.Object
  |
  +--uk.org.ogsadai.common.XMLSchemaUtilities

public class XMLSchemaUtilities
extends java.lang.Object

Contains utility methods for working with XML schema documents.

Author:
The OGSA-DAI Project Team

Constructor Summary
XMLSchemaUtilities()
           
 
Method Summary
static void makeSchemaLocationsAbsolute(org.w3c.dom.Document doc, java.lang.String base)
          Converts the schemaLocation attributes of any import elements contained within the specified document to use absolute instead of relative paths.
static void makeSchemaLocationsAbsolute(org.w3c.dom.Document doc, java.net.URL base)
          Converts the schemaLocation attributes of any import elements contained within the specified document to use absolute instead of relative paths.
static void merge(org.w3c.dom.Document doc1, org.w3c.dom.Document doc2)
          Merges two XML document by importing the namespace attributes and child nodes of the root element of doc2 into doc1.
static void removeAllIncludes(org.w3c.dom.Document doc)
          Removes all the include elements from a document.
static void removeIncludes(org.w3c.dom.Document doc, java.lang.String schemaLocation)
          Removes all the include elements with the specified schemaLocation attribute from the specified document.
static void removeIncludes(org.w3c.dom.Document doc, java.net.URL schemaLocation)
          Removes all the include elements with the specified schemaLocation attribute from the specified document.
static void validate(org.w3c.dom.Document document, org.w3c.dom.Document schema)
          Validates an XML Document against a specified XML schema Document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLSchemaUtilities

public XMLSchemaUtilities()
Method Detail

merge

public static void merge(org.w3c.dom.Document doc1,
                         org.w3c.dom.Document doc2)
Merges two XML document by importing the namespace attributes and child nodes of the root element of doc2 into doc1.

Parameters:
doc1 - The document to import the nodes into.
doc2 - The document to import the nodes from.

makeSchemaLocationsAbsolute

public static void makeSchemaLocationsAbsolute(org.w3c.dom.Document doc,
                                               java.net.URL base)
                                        throws CommonSystemException
Converts the schemaLocation attributes of any import elements contained within the specified document to use absolute instead of relative paths.

Parameters:
doc - the XML schema Document
base - the base URL that paths are specified relative to
Throws:
CommonSystemException - if one of the schemaLocation attributes cannot be modified into a well formed absolute URL path

makeSchemaLocationsAbsolute

public static void makeSchemaLocationsAbsolute(org.w3c.dom.Document doc,
                                               java.lang.String base)
                                        throws CommonSystemException
Converts the schemaLocation attributes of any import elements contained within the specified document to use absolute instead of relative paths.

Parameters:
doc - the XML schema Document
base - the base URL String that paths are specified relative to
Throws:
CommonSystemException - if the base URL is not well-formed or one of the schemaLocation attributes cannot be modified into a well-formed absolute URL path

removeAllIncludes

public static void removeAllIncludes(org.w3c.dom.Document doc)
Removes all the include elements from a document.

Parameters:
doc - the document to remove the include elements from

removeIncludes

public static void removeIncludes(org.w3c.dom.Document doc,
                                  java.net.URL schemaLocation)
Removes all the include elements with the specified schemaLocation attribute from the specified document. Note that the schemaLocation attributes are expected to be absolute and not relative.

Parameters:
doc - the Document to remove the include elements from
schemaLocation - the URL value of the schemaLocation attribute
See Also:
makeSchemaLocationsAbsolute(org.w3c.dom.Document, java.net.URL)

removeIncludes

public static void removeIncludes(org.w3c.dom.Document doc,
                                  java.lang.String schemaLocation)
                           throws CommonSystemException
Removes all the include elements with the specified schemaLocation attribute from the specified document. Note that the schemaLocation attributes are expected to be absolute and not relative.

Parameters:
doc - the Document to remove the include elements from
schemaLocation - the URL String value of the schemaLocation attribute
CommonSystemException
See Also:
makeSchemaLocationsAbsolute(org.w3c.dom.Document, java.lang.String)

validate

public static void validate(org.w3c.dom.Document document,
                            org.w3c.dom.Document schema)
                     throws CommonSystemException,
                            CommonUserException
Validates an XML Document against a specified XML schema Document. This is achieved using a custom SchemaEntityResolver that bypasses the normal mechanism where a schema document would be loaded from a specified URL.

Parameters:
document - the Document to validate.
schema - the XML schema Document
Throws:
CommonSystemException - If a system problem prevents the validation.
CommonUserException - If the document does not validate against the schema