/** Parses the given XML string into a list of key/value pairs. */ public static Hashtable<String, String> parseXML(String xml) throws IOException { MetadataHandler handler = new MetadataHandler(); parseXML(xml, handler); return handler.getMetadata(); }
/** Writes the specified DOM to the given output stream. */ public static void writeXML(OutputStream os, Document doc) throws TransformerException { writeXML(os, doc, true); }
/** * Parses the XML contained in the given input stream into * using the specified XML handler. * Be very careful, as 'stream' <b>will</b> be closed by the SAX parser. */ public static void parseXML(RandomAccessInputStream stream, DefaultHandler handler) throws IOException { parseXML((InputStream) stream, handler); }
/** * Indents XML to be more readable. * Uses 3 spaces to indent, and may indent CDATA. * * @param xml the XML string to format * @return the formatted XML string * @see #indentXML(String, int, boolean) */ public static String indentXML(String xml) { return indentXML(xml, 3, false); }
/** * Attempts to validate the given XML string using * Java's XML validation facility. * @param xml The XML string to validate. * @return whether or not validation was successful. */ public static boolean validateXML(String xml) { return validateXML(xml, null, null); }
/** * Dumps the given OME-XML DOM tree to a string. * @param schemaLocation if null, no xmlns attribute will be added. * @param doc the {@link Document} representing the XML to be written * @param r the {@link Element} to use for adding the schema location * @return OME-XML as a string. */ public static String dumpXML(String schemaLocation, Document doc, Element r) { return dumpXML(schemaLocation, doc, r, true); }
public Document createNewDocument() { if (builder == null) { builder = XMLTools.createBuilder(); } return builder.newDocument(); }
/** * Indents XML by the given spacing to be more readable. * CDATA may be indented. * * @param xml the XML string to format * @param spacing the number of spaces by which to indent * @return the formatted XML string * @see #indentXML(String, int, boolean) */ public static String indentXML(String xml, int spacing) { return indentXML(xml, spacing, false); }
/** * Parses the given XML string into a list of key/value pairs. * * @param xml the {@link InputStream} representing the XML * @return a hashtable of key/value pairs representing the XML * @throws IOException if there is an error during parsing * @see MetadataHandler */ public static Hashtable<String, String> parseXML(String xml) throws IOException { MetadataHandler handler = new MetadataHandler(); parseXML(xml, handler); return handler.getMetadata(); }
/** * Attempts to validate the given XML string using * Java's XML validation facility. * @param xml The XML string to validate. * @return whether or not validation was successful. */ public static boolean validateXML(String xml) { return validateXML(xml, null, null); }
/** * Dumps the given OME-XML DOM tree to a string. * @param schemaLocation if null, no xmlns attribute will be added. * @return OME-XML as a string. */ public static String dumpXML(String schemaLocation, Document doc, Element r) { return dumpXML(schemaLocation, doc, r, true); }
/** * Parses the XML contained in the given input stream into * using the specified XML handler. * Be very careful, as 'stream' <b>will</b> be closed by the SAX parser. * * @param stream the {@link RandomAccessInputStream} representing the XML * @param handler the {@link DefaultHandler} to use for parsing * @throws IOException if there is an error during parsing */ public static void parseXML(RandomAccessInputStream stream, DefaultHandler handler) throws IOException { parseXML((InputStream) stream, handler); }
/** * Writes the specified DOM to the given output stream. * * @param os the {@link OutputStream} to which XML should be written * @param doc the {@link Document} representing the XML to write * @throws TransformerException if there is an error during writing */ public static void writeXML(OutputStream os, Document doc) throws TransformerException { writeXML(os, doc, true); }
/** Indents XML by the given spacing to be more readable. */ public static String indentXML(String xml, int spacing) { return indentXML(xml, spacing, false); }
/** * Attempts to validate the given XML string using * Java's XML validation facility. * @param xml The XML string to validate. * @param label String describing the type of XML being validated. * @return whether or not validation was successful. */ public static boolean validateXML(String xml, String label) { return validateXML(xml, label, null); }
/** * Parses the given XML string using the specified XML handler. * * @param xml the string representing the XML * @param handler the {@link DefaultHandler} to use for parsing * @throws IOException if there is an error during parsing */ public static void parseXML(String xml, DefaultHandler handler) throws IOException { parseXML(xml.getBytes(Constants.ENCODING), handler); }
/** * Indents XML to be more readable, avoiding any whitespace * injection into CDATA if the preserveCData flag is set. */ public static String indentXML(String xml, boolean preserveCData) { return indentXML(xml, 3, preserveCData); }
/** * Attempts to validate the given XML string using * Java's XML validation facility. * @param xml The XML string to validate. * @param label String describing the type of XML being validated. * @return whether or not validation was successful. */ public static boolean validateXML(String xml, String label) { return validateXML(xml, label, null); }
/** Indents XML to be more readable. */ public static String indentXML(String xml) { return indentXML(xml, 3, false); }
/** * Indents XML to be more readable, avoiding any whitespace * injection into CDATA if the preserveCData flag is set. * Uses 3 spaces to indent. * * @param xml the XML string to format * @param preserveCData true if CDATA nodes should be preserved * with no indenting * @return the formatted XML string * @see #indentXML(String, int, boolean) */ public static String indentXML(String xml, boolean preserveCData) { return indentXML(xml, 3, preserveCData); }