@Test public void noNamespace() { Assert.assertNull(XmlUtils.extractRootNamespace("<test></test>")); Assert.assertNull(XmlUtils.extractRootNamespace("")); }
public static String extractRootNamespace(String xmlContent) { Matcher matcher = ROOT_TAG_PATTERN.matcher(xmlContent); if (matcher.find()) { String rootElement = matcher.group(1).trim(); String rootNs = rootElement.split(" ", 2)[0].contains(":") ? rootElement.substring(0, rootElement.indexOf(":")) : ""; Matcher nsMatcher = NAMESPACE_PATTERN.matcher(rootElement); while (nsMatcher.find()) { if (nsMatcher.group(1).equals(rootNs)) { return nsMatcher.group(2); } } } return null; }
XmlUtils { public static String extractRootNamespace(String xmlContent) { Matcher matcher = ROOT_TAG_PATTERN.matcher(xmlContent); if (matcher.find()) { String rootElement = matcher.group(1).trim(); String rootNs = rootElement.split(" ", 2)[0].contains(":") ? rootElement.substring(0, rootElement.indexOf(":")) : ""; Matcher nsMatcher = NAMESPACE_PATTERN.matcher(rootElement); while (nsMatcher.find()) { if (nsMatcher.group(1).equals(rootNs)) { return nsMatcher.group(2); } } } return null; } }
XmlUtils { public static String extractRootNamespace(String xmlContent) { Matcher matcher = ROOT_TAG_PATTERN.matcher(xmlContent); if (matcher.find()) { String rootElement = matcher.group(1).trim(); String rootNs = rootElement.split(" ", 2)[0].contains(":") ? rootElement.substring(0, rootElement.indexOf(":")) : ""; Matcher nsMatcher = NAMESPACE_PATTERN.matcher(rootElement); while (nsMatcher.find()) { if (nsMatcher.group(1).equals(rootNs)) { return nsMatcher.group(2); } } } return null; } XmlUtils(); }
XmlUtils { public static String extractRootNamespace(String xmlContent) { Matcher matcher = ROOT_TAG_PATTERN.matcher(xmlContent); if (matcher.find()) { String rootElement = matcher.group(1).trim(); String rootNs = rootElement.split(" ", 2)[0].contains(":") ? rootElement.substring(0, rootElement.indexOf(":")) : ""; Matcher nsMatcher = NAMESPACE_PATTERN.matcher(rootElement); while (nsMatcher.find()) { if (nsMatcher.group(1).equals(rootNs)) { return nsMatcher.group(2); } } } return null; } XmlUtils(); static String extractRootNamespace(String xmlContent); static XMLStreamReader streamReader(InputStream inputStream); }
XmlUtils { public static String extractRootNamespace(String xmlContent) { Matcher matcher = ROOT_TAG_PATTERN.matcher(xmlContent); if (matcher.find()) { String rootElement = matcher.group(1).trim(); String rootNs = rootElement.split(" ", 2)[0].contains(":") ? rootElement.substring(0, rootElement.indexOf(":")) : ""; Matcher nsMatcher = NAMESPACE_PATTERN.matcher(rootElement); while (nsMatcher.find()) { if (nsMatcher.group(1).equals(rootNs)) { return nsMatcher.group(2); } } } return null; } XmlUtils(); static String extractRootNamespace(String xmlContent); static XMLStreamReader streamReader(InputStream inputStream);  }