XmlUtils { public static String getRootNamespace(String input) { try { TransformerPool tp = getGetRootNamespaceTransformerPool(); return tp.transform(input,null); } catch (Exception e) { log.warn(e); return null; } } XmlUtils(); static TransformerPool getDetectXsltVersionTransformerPool(); static TransformerPool getGetXsltConfigTransformerPool(); static Map<String,String> getXsltConfig(Resource source); static Map<String,String> getXsltConfig(Source source); static TransformerPool getRemoveNamespacesTransformerPool(boolean omitXmlDeclaration, boolean indent); static TransformerPool getGetIbisContextTransformerPool(); static TransformerPool getGetRootNamespaceTransformerPool(); static TransformerPool getAddRootNamespaceTransformerPool(String namespace, boolean omitXmlDeclaration, boolean indent); static TransformerPool getChangeRootTransformerPool(String root, boolean omitXmlDeclaration, boolean indent); static TransformerPool getRemoveUnusedNamespacesTransformerPool(boolean omitXmlDeclaration, boolean indent); static TransformerPool getRemoveUnusedNamespacesXslt2TransformerPool(boolean omitXmlDeclaration, boolean indent); static TransformerPool getCopyOfSelectTransformerPool(String xpath, boolean omitXmlDeclaration, boolean indent); static TransformerPool getIdentityTransformerPool(); static synchronized boolean isNamespaceAwareByDefault(); static synchronized boolean isXsltStreamingByDefault(); static synchronized boolean isIncludeFieldDefinitionByDefault(); static synchronized boolean isAutoReload(); static synchronized int getBufSize(); static void parseXml(Resource resource, ContentHandler handler); static void parseXml(String source, ContentHandler handler); static void parseXml(InputSource inputSource, ContentHandler handler); static void parseXml(InputSource inputSource, ContentHandler handler, ErrorHandler errorHandler); static XMLReader getXMLReader(ContentHandler handler); static XMLReader getXMLReader(Configuration classLoaderProvider); static Document buildDomDocument(Reader in); static Document buildDomDocument(Reader in, boolean namespaceAware); static Document buildDomDocument(Reader in, boolean namespaceAware, boolean resolveExternalEntities); static Document buildDomDocument(String s); static Document buildDomDocument(String s, boolean namespaceAware); static Document buildDomDocument(String s, boolean namespaceAware, boolean resolveExternalEntities); static Document buildDomDocument(URL url); static org.w3c.dom.Element buildElement(String s, boolean namespaceAware); static Node buildNode(String s, boolean namespaceAware); static Node buildNode(String s); static Element buildElement(String s); static Element buildElement(Message s); static String skipXmlDeclaration(String xmlString); static String skipDocTypeDeclaration(String xmlString); static String readXml(byte[] source, String defaultEncoding, boolean skipDeclaration); static String readXml(byte[] source, String defaultEncoding, boolean skipDeclaration, boolean useDeclarationEncoding); static String readXml(byte[] source, int offset, int length, String defaultEncoding, boolean skipDeclaration); static String readXml(byte[] source, int offset, int length, String defaultEncoding, boolean skipDeclaration, boolean useDeclarationEncoding); static TransformerPool getXPathTransformerPool(String namespaceDefs, String xPathExpression, String outputType, boolean includeXmlDeclaration, ParameterList params); static TransformerPool getXPathTransformerPool(String namespaceDefs, String xPathExpression, String outputType, boolean includeXmlDeclaration, ParameterList params, int xsltVersion); static String createXPathEvaluatorSource(String XPathExpression); static String createXPathEvaluatorSource(String namespaceDefs, String XPathExpression, String outputMethod, boolean includeXmlDeclaration); static String createXPathEvaluatorSource(String namespaceDefs, String XPathExpression, String outputMethod, boolean includeXmlDeclaration, List<String> paramNames); static String createXPathEvaluatorSource(String namespaceDefs, String XPathExpression, String outputMethod, boolean includeXmlDeclaration, List<String> paramNames, boolean stripSpace); static String getNamespaceClause(String namespaceDefs); static Map<String,String> getNamespaceMap(String namespaceDefs); static String createXPathEvaluatorSource(String namespaceDefs, String XPathExpression, String outputMethod, boolean includeXmlDeclaration, List<String> paramNames, boolean stripSpace, boolean ignoreNamespaces, String separator, int xsltVersion); static String createXPathEvaluatorSource(String namespaceDefs, String XPathExpression, String outputMethod); static String createXPathEvaluatorSource(String XPathExpression, String outputMethod); static Transformer createXPathEvaluator(String XPathExpression); static Transformer createXPathEvaluator(String namespaceDefs, String XPathExpression, String outputMethod); static Transformer createXPathEvaluator(String XPathExpression, String outputMethod); static Source stringToSource(String xmlString, boolean namespaceAware); static Source stringToSource(String xmlString); static Source stringToSourceForSingleUse(String xmlString); static Source stringToSourceForSingleUse(String xmlString, boolean namespaceAware); static SAXSource inputSourceToSAXSource(Resource resource); static SAXSource inputSourceToSAXSource(InputSource is); static int interpretXsltVersion(String xsltVersion); static int detectXsltVersion(String xsltString); static int detectXsltVersion(URL xsltUrl); static Transformer createTransformer(String xsltString); static Transformer createTransformer(String xsltString, int xsltVersion); static Transformer createTransformer(URL url); static Transformer createTransformer(URL url, int xsltVersion); static Transformer createTransformer(Source source); static Transformer createTransformer(Source source, int xsltVersion); static TransformerFactory getTransformerFactory(); static TransformerFactory getTransformerFactory(int xsltVersion); static synchronized DocumentBuilderFactory getDocumentBuilderFactory(); static synchronized DocumentBuilderFactory getDocumentBuilderFactory(boolean namespaceAware); static SAXParserFactory getSAXParserFactory(); static SAXParserFactory getSAXParserFactory(boolean namespaceAware); static String encodeChars(String string); static String encodeCharsAndReplaceNonValidXmlCharacters(String string); static String encodeChars(char[] chars, int offset, int length); static String decodeChars(String string); static String encodeURL(String url); static boolean getChildTagAsBoolean(Element el, String tag); static boolean getChildTagAsBoolean(
		Element el,
		String tag,
		boolean defaultValue); static long getChildTagAsLong(Element el, String tag); static long getChildTagAsLong(
		Element el,
		String tag,
		long defaultValue); static String getChildTagAsString(Element el, String tag); static String getChildTagAsString(
		Element el,
		String tag,
		String defaultValue); static Collection<Node> getChildTags(Element el, String tag); static Element getFirstChildTag(Element el, String tag); static String getStringValue(Element el); static String getStringValue(Element el, boolean trimWhitespace); static String encodeCdataString(String string); static String replaceNonValidXmlCharacters(String string); static String replaceNonValidXmlCharacters(String string, char to,
			boolean appendCharNum,
			boolean allowUnicodeSupplementaryCharacters); static String stripNonValidXmlCharacters(String string,
			boolean allowUnicodeSupplementaryCharacters); static boolean isPrintableUnicodeChar(int c); static boolean isPrintableUnicodeChar(int c,
			boolean allowUnicodeSupplementaryCharacters); static void setTransformerParameters(Transformer t, Map<String,Object> parameters); static String transformXml(Transformer t, Document d); static String transformXml(Transformer t, String s); static String transformXml(Transformer t, String s, boolean namespaceAware); static void transformXml(Transformer t, String s, Result result); static String transformXml(Transformer t, Source s); static void transformXml(Transformer t, Source s, Writer out); static boolean isWellFormed(String input); static boolean isWellFormed(String input, String root); static String identityTransform(Resource resource); static String getVersionInfo(); static String source2String(Source source, boolean removeNamespaces); static String removeNamespaces(String input); static String getRootNamespace(String input); static String addRootNamespace(String input, String namespace); static String removeUnusedNamespaces(String input); static String copyOfSelect(String input, String xpath); static Map<String, String> getIbisContext(String input); static String canonicalize(String input); static String nodeToString(Node node); static String nodeToString(Node node, boolean omitXmlDeclaration); static String cdataToText(String input); static StartElement mergeAttributes(StartElement tag, Iterator<? extends Attribute> attrs, Iterator<? extends Namespace> nsps, XMLEventFactory factory); static boolean attributesEqual(Attribute attribute1, Attribute attribute2); static String getAdapterSite(Object document); static String getAdapterSite(String input, Map parameters); static Collection<String> evaluateXPathNodeSet(String input, String xpathExpr); static String evaluateXPathNodeSetFirstElement(String input, String xpathExpr); static Double evaluateXPathNumber(String input, String xpathExpr); static Map<String, String> evaluateXPathNodeSet(String input, String xpathExpr, String keyElement, String valueElement); static Collection<String> evaluateXPathNodeSet(String input, String xpathExpr, String xpathExpr2); static String toXhtml(String htmlString); static XPathFactory getXPathFactory(); static synchronized XPathFactory getXPathFactory(int xsltVersion); static final int DEFAULT_XSLT_VERSION; static final String NAMESPACE_AWARE_BY_DEFAULT_KEY; static final String XSLT_STREAMING_BY_DEFAULT_KEY; static final String AUTO_RELOAD_KEY; static final String XSLT_BUFFERSIZE_KEY; static final int XSLT_BUFFERSIZE_DEFAULT; static final String INCLUDE_FIELD_DEFINITION_BY_DEFAULT_KEY; static final String OPEN_FROM_FILE; static final String OPEN_FROM_URL; static final String OPEN_FROM_RESOURCE; static final String OPEN_FROM_XML; static final char REPLACE_NON_XML_CHAR; static final String XPATH_GETROOTNODENAME; static final String IDENTITY_TRANSFORM; static final XMLEventFactory EVENT_FACTORY; static final XMLInputFactory INPUT_FACTORY; static final XMLOutputFactory OUTPUT_FACTORY; static final XMLOutputFactory REPAIR_NAMESPACES_OUTPUT_FACTORY; static final String STREAM_FACTORY_ENCODING; }
@Test public void testGetRootNamespace() throws SAXException, TransformerException, IOException, ConfigurationException { String lineSeparator=System.getProperty("line.separator"); testGetRootNamespace("<root><a>a</a><b></b><c/></root>",""); testGetRootNamespace("<root xmlns=\"xyz\"><a>a</a><b></b><c/></root>","xyz"); testGetRootNamespace("<root xmlns:xx=\"xyz\"><a xmlns=\"xyz\">a</a><b></b><c/></root>",""); testGetRootNamespace("<xx:root xmlns:xx=\"xyz\"><a xmlns=\"xyz\">a</a><b></b><c/></xx:root>","xyz"); }