Package org.harctoolbox.xml
Class XmlUtils
java.lang.Object
org.harctoolbox.xml.XmlUtils
This class consists of a collection of useful static constants and functions.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final String -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddAttributeIfNonNull(Element element, String attName, Object value) static voidaddBooleanAttributeIfFalse(Element element, String attName, boolean value) static voidaddBooleanAttributeIfTrue(Element element, String attName, boolean value) static voidaddDoubleAttributeAsInteger(Element element, String attName, double value) buildIndex(Element element, String tagName, String idName) static booleancreateIndex(Element root, String tagName, String idName) static InputSourcegetInputSource(String filename) Opens a Url, an input file, or returns stdin.static booleanhasSpacePreserve(Node node) Returns true if the node given as argument has the attribute xml:space, equal to "preserve"static InputStreamReadermkReaderXml(String docu, String xslt, String encoding) static InputStreamReadermkReaderXml(String docu, Document stylesheet, String encoding) static Documentstatic DocumentnewDocument(boolean isNamespaceAware) static DocumentopenXmlFile(File file) static DocumentopenXmlFile(File file, File schemaFile, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentopenXmlFile(File file, String schemaString, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentopenXmlFile(File file, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentopenXmlFile(String string, String schemaString, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentopenXmlReader(Reader reader, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentopenXmlSource(InputSource inputSource, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentopenXmlStream(InputStream stream, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentopenXmlThing(String thing) static DocumentopenXmlThing(String thing, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentopenXmlUrl(URL url, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentopenXmlUrlOrFile(String thing, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static DocumentparseStringToXmlDocument(String string, boolean isNamespaceAware, boolean isXIncludeAware) static voidstatic voidstatic voidprintDOM(OutputStream ostr, Document doc) static voidprintDOM(OutputStream ostr, Document doc, String encoding) static voidprintDOM(OutputStream ostr, Document doc, String encoding, String cdataElements) static voidprintDOM(OutputStream ostr, Document document, String encoding, Document xslt, Map<String, String> parameters, boolean binary) Version with XSLT support.static voidstatic voidstatic voidprintHtmlDOM(OutputStream ostr, Document doc, String encoding) static SchemareadSchema(File schemaFile) static SchemareadSchema(InputStream inputStream) static SchemareadSchema(String schemaString) static SchemareadSchema(URL schemaUrl) static SchemareadSchema(Source source) static ByteArrayInputStreamstatic voidsetDebug(boolean dbg) static DocumentFragmentExpensive to use many times.static DocumentwrapDocumentFragment(DocumentFragment fragment, String namespaceURI, String tagName, String attName, String attValue)
-
Field Details
-
DEFAULT_CHARSETNAME
- See Also:
-
W3C_SCHEMA_NAMESPACE_ATTRIBUTE_NAME
- See Also:
-
HTML_NAMESPACE_ATTRIBUTE_NAME
- See Also:
-
XML_NAMESPACE_ATTRIBUTE_NAME
- See Also:
-
XINCLUDE_NAMESPACE_ATTRIBUTE_NAME
- See Also:
-
IRP_NAMESPACE_ATTRIBUTE_NAME
- See Also:
-
HTML_NAMESPACE_URI
- See Also:
-
XSLT_NAMESPACE_URI
- See Also:
-
SCHEMA_LOCATION_ATTRIBUTE_NAME
- See Also:
-
XML_LANG_ATTRIBUTE_NAME
- See Also:
-
XML_SPACE_ATTRIBUTE_NAME
- See Also:
-
XML_BASE_ATTRIBUTE_NAME
- See Also:
-
ENCODING_ATTRIBUTE_NAME
- See Also:
-
PRESERVE
- See Also:
-
ENGLISH
- See Also:
-
YES
- See Also:
-
NO
- See Also:
-
TRUE
- See Also:
-
FALSE
- See Also:
-
XML
- See Also:
-
TEXT
- See Also:
-
HTML
- See Also:
-
GIRR_NAMESPACE_URI
- See Also:
-
IRP_NAMESPACE_URI
- See Also:
-
XINCLUDE_NAMESPACE_URI
- See Also:
-
IRP_SCHEMA_LOCATION
- See Also:
-
IRP_PREFIX
- See Also:
-
GIRR_PREFIX
- See Also:
-
GIRR_COMMENT
- See Also:
-
GIRR_VERSION_NAME
- See Also:
-
GIRR_VERSION
- See Also:
-
GIRR_SCHEMA_LOCATION
- See Also:
-
-
Method Details
-
canValidate
public static boolean canValidate() -
setDebug
public static void setDebug(boolean dbg) -
parseStringToXmlDocument
public static Document parseStringToXmlDocument(String string, boolean isNamespaceAware, boolean isXIncludeAware) throws SAXException - Throws:
SAXException
-
openXmlFile
public static Document openXmlFile(File file, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws SAXException, IOException - Throws:
SAXExceptionIOException
-
openXmlFile
public static Document openXmlFile(File file, File schemaFile, boolean isNamespaceAware, boolean isXIncludeAware) throws SAXException, IOException - Throws:
SAXExceptionIOException
-
openXmlFile
public static Document openXmlFile(File file, String schemaString, boolean isNamespaceAware, boolean isXIncludeAware) throws SAXException, IOException - Throws:
SAXExceptionIOException
-
openXmlFile
public static Document openXmlFile(String string, String schemaString, boolean isNamespaceAware, boolean isXIncludeAware) throws SAXException, IOException - Throws:
SAXExceptionIOException
-
openXmlFile
- Throws:
IOExceptionSAXException
-
openXmlReader
public static Document openXmlReader(Reader reader, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOExceptionSAXException
-
openXmlStream
public static Document openXmlStream(InputStream stream, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOExceptionSAXException
-
openXmlSource
public static Document openXmlSource(InputSource inputSource, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOExceptionSAXException
-
openXmlThing
public static Document openXmlThing(String thing, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOExceptionSAXException
-
openXmlThing
- Throws:
IOExceptionSAXException
-
openXmlUrlOrFile
public static Document openXmlUrlOrFile(String thing, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOExceptionSAXException
-
openXmlUrl
public static Document openXmlUrl(URL url, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOExceptionSAXException
-
getInputSource
Opens a Url, an input file, or returns stdin.- Parameters:
filename- : file name, empty, null or "-"- Returns:
- InputSource
-
newDocument
-
newDocument
-
hasSpacePreserve
Returns true if the node given as argument has the attribute xml:space, equal to "preserve"- Parameters:
node- Node (Element) to investigate.- Returns:
- true iff xml:space="preserve".
-
createIndex
-
renderDOM
public static ByteArrayInputStream renderDOM(Document document, Document xslt, String encoding) throws UnsupportedEncodingException, TransformerException, IOException -
mkReaderXml
public static InputStreamReader mkReaderXml(String docu, String xslt, String encoding) throws SAXException, UnsupportedEncodingException, TransformerException, IOException -
mkReaderXml
public static InputStreamReader mkReaderXml(String docu, Document stylesheet, String encoding) throws SAXException, UnsupportedEncodingException, TransformerException, IOException -
printHtmlDOM
public static void printHtmlDOM(OutputStream ostr, Document doc, String encoding) throws UnsupportedEncodingException - Throws:
UnsupportedEncodingException
-
printDOM
public static void printDOM(OutputStream ostr, Document doc, String encoding, String cdataElements) throws UnsupportedEncodingException - Throws:
UnsupportedEncodingException
-
printDOM
public static void printDOM(OutputStream ostr, Document doc, String encoding) throws UnsupportedEncodingException - Throws:
UnsupportedEncodingException
-
printDOM
-
printDOM
public static void printDOM(File file, Document doc, String encoding, String cdataElements) throws FileNotFoundException, UnsupportedEncodingException -
printDOM
public static void printDOM(String xmlFileName, Document doc, String encoding, String cdataElements) throws FileNotFoundException, UnsupportedEncodingException -
printDOM
- Throws:
FileNotFoundException
-
printDOM
-
readSchema
- Throws:
SAXException
-
readSchema
- Throws:
SAXException
-
readSchema
- Throws:
SAXException
-
readSchema
- Throws:
SAXException
-
readSchema
public static Schema readSchema(String schemaString) throws SAXException, FileNotFoundException, IOException -
printDOM
public static void printDOM(OutputStream ostr, Document document, String encoding, Document xslt, Map<String, String> parameters, boolean binary) throws UnsupportedEncodingException, FileNotFoundException, IOException, TransformerExceptionVersion with XSLT support.- Parameters:
ostr-document-encoding-xslt- Stylesheet transforming the documentparameters-binary-- Throws:
TransformerExceptionUnsupportedEncodingExceptionFileNotFoundExceptionIOException
-
buildIndex
-
addBooleanAttributeIfTrue
-
addBooleanAttributeIfFalse
-
addDoubleAttributeAsInteger
-
addAttributeIfNonNull
-
wrapDocumentFragment
-
stringToDocumentFragment
Expensive to use many times.- Parameters:
str-- Returns:
-