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
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addAttributeIfNonNull
(Element element, String attName, Object value) static void
addBooleanAttributeIfFalse
(Element element, String attName, boolean value) static void
addBooleanAttributeIfTrue
(Element element, String attName, boolean value) static void
addDoubleAttributeAsInteger
(Element element, String attName, double value) buildIndex
(Element element, String tagName, String idName) createIndex
(Element root, String tagName, String idName) static InputSource
getInputSource
(String filename) Opens a Url, an input file, or returns stdin.static boolean
hasSpacePreserve
(Node node) Returns true if the node given as argument has the attribute xml:space, equal to "preserve"static InputStreamReader
mkReaderXml
(String docu, String xslt, String encoding) static Document
static Document
newDocument
(boolean isNamespaceAware) static Document
openXmlFile
(File file) static Document
openXmlFile
(File file, File schemaFile, boolean isNamespaceAware, boolean isXIncludeAware) static Document
openXmlFile
(File file, String schemaString, boolean isNamespaceAware, boolean isXIncludeAware) static Document
openXmlFile
(File file, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static Document
openXmlFile
(String string, String schemaString, boolean isNamespaceAware, boolean isXIncludeAware) static Document
openXmlReader
(Reader reader, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static Document
openXmlSource
(InputSource inputSource, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static Document
openXmlStream
(InputStream stream, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static Document
openXmlThing
(String thing) static Document
openXmlThing
(String thing, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static Document
openXmlUrl
(URL url, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static Document
openXmlUrlOrFile
(String thing, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) static Document
parseStringToXmlDocument
(String string, boolean isNamespaceAware, boolean isXIncludeAware) static void
static void
static void
printDOM
(OutputStream ostr, Document doc) static void
printDOM
(OutputStream ostr, Document doc, String encoding) static void
printDOM
(OutputStream ostr, Document doc, String encoding, String cdataElements) static void
printDOM
(OutputStream ostr, Document document, String encoding, Document xslt, Map<String, String> parameters, boolean binary) Version with XSLT support.static void
static void
static void
printHtmlDOM
(OutputStream ostr, Document doc, String encoding) static Schema
readSchema
(File schemaFile) static Schema
readSchema
(InputStream inputStream) static Schema
readSchema
(String schemaString) static Schema
readSchema
(URL schemaUrl) static Schema
readSchema
(Source source) static ByteArrayInputStream
static void
setDebug
(boolean dbg) static DocumentFragment
Expensive to use many times.static Document
wrapDocumentFragment
(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
-
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:
SAXException
IOException
-
openXmlFile
public static Document openXmlFile(File file, File schemaFile, boolean isNamespaceAware, boolean isXIncludeAware) throws SAXException, IOException - Throws:
SAXException
IOException
-
openXmlFile
public static Document openXmlFile(File file, String schemaString, boolean isNamespaceAware, boolean isXIncludeAware) throws SAXException, IOException - Throws:
SAXException
IOException
-
openXmlFile
public static Document openXmlFile(String string, String schemaString, boolean isNamespaceAware, boolean isXIncludeAware) throws SAXException, IOException - Throws:
SAXException
IOException
-
openXmlFile
- Throws:
IOException
SAXException
-
openXmlReader
public static Document openXmlReader(Reader reader, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOException
SAXException
-
openXmlStream
public static Document openXmlStream(InputStream stream, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOException
SAXException
-
openXmlSource
public static Document openXmlSource(InputSource inputSource, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOException
SAXException
-
openXmlThing
public static Document openXmlThing(String thing, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOException
SAXException
-
openXmlThing
- Throws:
IOException
SAXException
-
openXmlUrlOrFile
public static Document openXmlUrlOrFile(String thing, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOException
SAXException
-
openXmlUrl
public static Document openXmlUrl(URL url, Schema schema, boolean isNamespaceAware, boolean isXIncludeAware) throws IOException, SAXException - Throws:
IOException
SAXException
-
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 -
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:
TransformerException
UnsupportedEncodingException
FileNotFoundException
IOException
-
buildIndex
-
addBooleanAttributeIfTrue
-
addBooleanAttributeIfFalse
-
addDoubleAttributeAsInteger
-
addAttributeIfNonNull
-
wrapDocumentFragment
-
stringToDocumentFragment
Expensive to use many times.- Parameters:
str
-- Returns:
-