Here you can find the source of getBaseNamespace(InputStream owlStream)
public static String getBaseNamespace(InputStream owlStream)
//package com.java2s; //License from project: Open Source License import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; public class Main { public static String getBaseNamespace(InputStream owlStream) { String base = ""; try {//from w w w . j av a 2 s.c o m DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(owlStream); Element root = doc.getDocumentElement(); //get root name space NamedNodeMap attributes = root.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Node node = attributes.item(i); if (node != null) { if (node.getNodeType() == Node.ATTRIBUTE_NODE) { String name = node.getNodeName(); if (name.equals("xmlns")) base = node.getNodeValue(); else if (name.equals("xml:base")) base = node.getNodeValue() + "#"; } } } } } catch (Exception e) { e.printStackTrace(); } return base; } }