Package org.mycore.common.xml
Class MCRXMLHelper
java.lang.Object
org.mycore.common.xml.MCRXMLHelper
This class provides some static utility methods to deal with XML/DOM
elements, nodes etc.
- Author:
- Detlev Degenhardt, Frank Lützenkirchen, Thomas Scheffler (yagee)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
checks whether two documents are equal.static boolean
checks whether two elements are equal.static com.google.gson.JsonElement
jsonSerialize
(Content content) static com.google.gson.JsonObject
jsonSerialize
(Element element) static String
removeIllegalChars
(String text) Removes characters that are illegal in XML text nodes or attribute values.static Schema
resolveSchema
(String schemaURI, boolean disableSchemaFullCheckingFeature) Resolve the schema from the schemaURI honoring the catalog.xmlstatic Source
resolveSource
(String schemaURI) Resolves XML Source against the suppliedschemaURI
.static void
validatesdoc
using XML Schema definedschemaURI
-
Constructor Details
-
MCRXMLHelper
public MCRXMLHelper()
-
-
Method Details
-
removeIllegalChars
Removes characters that are illegal in XML text nodes or attribute values.- Parameters:
text
- the String that should be used in XML elements or attributes- Returns:
- the String with all illegal characters removed
-
validate
validatesdoc
using XML Schema definedschemaURI
- Parameters:
doc
- document to be validatedschemaURI
- URI of XML Schema document- Throws:
SAXException
- if validation failsIOException
- if resolving resources fails
-
resolveSchema
public static Schema resolveSchema(String schemaURI, boolean disableSchemaFullCheckingFeature) throws IOException, SAXException Resolve the schema from the schemaURI honoring the catalog.xml- Parameters:
schemaURI
- URI of XML Schema documentdisableSchemaFullCheckingFeature
- if true disable the feature http://apache.org/xml/features/validation/schema-full-checking- Returns:
- the schema
- Throws:
IOException
SAXException
-
resolveSource
Resolves XML Source against the suppliedschemaURI
. FirstMCREntityResolver.resolveEntity(String, String)
is tried to resolve against XMLCatalog and if noInputSource
is returned finallyMCRURIResolver.resolve(String, String)
is called as a fallback.- Parameters:
schemaURI
- uri to the XML document, e.g. XSD file- Returns:
- a resolved XML document as Source or null
- Throws:
IOException
SAXException
-
jsonSerialize
- Parameters:
content
- the jdom element to serialize- Returns:
- a gson element
- See Also:
-
MCRXMLHelper.JDOMtoGSONSerializer
-
jsonSerialize
- Parameters:
element
- the jdom element to serialize- Returns:
- a gson object
- See Also:
-
MCRXMLHelper.JDOMtoGSONSerializer.serializeElement(Element)
-
deepEqual
checks whether two documents are equal. This test performs a deep check across all child components of a Document.- Parameters:
d1
- first Document to compared2
- second Document to compare- Returns:
- true, if d1 and d2 are deep equal
- See Also:
-
deepEqual
checks whether two elements are equal. This test performs a deep check across all child components of a element.- Parameters:
e1
- first Element to comparee2
- second Element to compare- Returns:
- true, if e1 and e2 are deep equal
- See Also:
-