1 package eu.svjatoslav.inspector.xml.xsd;
3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.HashMap;
8 import javax.xml.parsers.ParserConfigurationException;
10 import org.xml.sax.SAXException;
12 import eu.svjatoslav.commons.data.xml.XmlElement;
13 import eu.svjatoslav.commons.data.xml.XmlHelper;
17 private static final String XMLNS_PREFIX = "xmlns:";
18 Map<String, String> namespaces = new HashMap<String, String>();
20 private void detectNamespaces(final XmlElement xsdSchema) {
21 for (final String attributeName : xsdSchema.getAttributeNames())
23 if (attributeName.startsWith(XMLNS_PREFIX)) {
24 final String nameSpaceName = attributeName
25 .substring(XMLNS_PREFIX.length());
26 namespaces.put(nameSpaceName,
27 xsdSchema.getAttributeValue(attributeName));
31 public void parse(final InputStream inputStream) throws SAXException,
32 IOException, ParserConfigurationException {
34 final XmlElement xsdSchema = XmlHelper.parseXml(inputStream);
36 detectNamespaces(xsdSchema);
38 System.out.println(xsdSchema.toString());
42 public String toString() {
43 final StringBuffer result = new StringBuffer();
45 result.append("namespaces:\n");
47 for (final Map.Entry<String, String> entry : namespaces.entrySet())
48 result.append(" " + entry.getKey() + " = " + entry.getValue()
51 return result.toString();