I have an XML request, the objective is to extract only the XML namespace.
<s:student xmlns:s="http://www.way2tutorial.com/some_url1"
xmlns:res="http://www.way2tutorial.com/some_url2">
<r:result>
<r:name>Opal Kole</r:name>
<r:sgpa>8.1</r:sgpa>
<r:cgpa>8.4</r:cgpa>
</r:result>
<res:cv>
<res:name>Opal Kole</res:name>
<res:cgpa>8.4</res:cgpa>
</res:cv>
</s:student>
I would not like to parse the XML as the ML parsing can be costly. But is there any way to get just the declared XML Namespaces
Expected Output:
xmlns:s="http://www.way2tutorial.com/some_url1"
xmlns:res="http://www.way2tutorial.com/some_url2"
I have even tried using regular expression, But it the expression was incorrect.
Java Code using regular expression:
String txt = "<s:student xmlns:s=\"http://www.way2tutorial.com/some_url1\" xmlns:res=\"http://www.way2tutorial.com/some_url2\">";
String regularExpression = "xmlns:(.*?)=(\".*?\")";
Pattern p = Pattern.compile(regularExpression);
Matcher m = p.matcher(txt);
if (m.find()) {
String word1 = m.group(1);
System.out.print("(" + word1.toString() + ")" + "\n");
}