uk.org.ogsadai.common.xml
Class XMLSchemaUtilities

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

public class XMLSchemaUtilities
extends java.lang.Object

Contains utility methods for working with XML schema documents.

Author:
The OGSA-DAI Project Team

Field Summary
private static java.lang.String COPYRIGHT_NOTICE
           
private static DAILogger LOG
           
 
Constructor Summary
XMLSchemaUtilities()
           
 
Method Summary
static void makeSchemaLocationsAbsolute(org.w3c.dom.Document doc, java.lang.String base)
          Converts the schemaLocation attributes of any include 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 include elements contained within the specified document to use absolute instead of relative paths.
static void merge(org.w3c.dom.Document dest, org.w3c.dom.Document src)
          Merges two XML documents by importing the namespace attributes and child nodes of the root elements of each document.
static void removeAllIncludes(org.w3c.dom.Document doc)
          Removes all the include elements from an XML 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT_NOTICE

private static final java.lang.String COPYRIGHT_NOTICE
See Also:
Constant Field Values

LOG

private static final DAILogger LOG
Constructor Detail

XMLSchemaUtilities

public XMLSchemaUtilities()
Method Detail

merge

public static void merge(org.w3c.dom.Document dest,
                         org.w3c.dom.Document src)
Merges two XML documents by importing the namespace attributes and child nodes of the root elements of each document.

Parameters:
dest - The document to import the nodes into.
src - The document to import the nodes from.

makeSchemaLocationsAbsolute

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

Parameters:
doc - XML code>Document.
base - Base URL that paths are specified relative to.
Throws:
DAIMalformedURLException - if the URL formed from base plus any schemaLocation is malformed.

makeSchemaLocationsAbsolute

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

Parameters:
doc - XML code>Document.
base - Base URL that paths are specified relative to.
Throws:
DAIMalformedURLException - if the URL formed from base plus any schemaLocation is malformed or if base itself is malformed.
See Also:
makeSchemaLocationsAbsolute(org.w3c.dom.Document, java.net.URL)

removeAllIncludes

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

Parameters:
doc - The XML document to remove the 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.

The schemaLocation attributes are expected to be absolute and not relative.

Parameters:
doc - The XML document to remove the elements from.
schemaLocation - The 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 DAIMalformedURLException
Removes all the include elements with the specified schemaLocation attribute from the specified document.

The schemaLocation attributes are expected to be absolute and not relative.

Parameters:
doc - The XML document to remove the elements from.
schemaLocation - The value of the schemaLocation attribute.
Throws:
DAIMalformedURLException - if schemaLocation is malformed.
See Also:
makeSchemaLocationsAbsolute(org.w3c.dom.Document, java.net.URL)

validate

public static void validate(org.w3c.dom.Document document,
                            org.w3c.dom.Document schema)
                     throws XMLDocumentException,
                            XMLParseException
Validates an XML document against a specified XML Schema.

This is achieved using a custom SchemaEntityResolver that bypasses the normal mechanism where an XML Schema document would be loaded from a specified URL.

Parameters:
document - The XML document to validate.
schema - The XML Schema.
Throws:
XMLDocumentException - if the document does not validate against the XML Schema.
XMLParseException - if there is a problem with the parser setup or execution.
ExternalModuleException - if there is an internal problem within Xerces when creating the Document.