1 3 56 57 package org.jboss.util.xml.catalog.helpers; 58 59 import org.w3c.dom.*; 60 61 72 public class Namespaces { 73 80 public static String getPrefix(Element element) { 81 String name = element.getTagName(); 82 String prefix = ""; 83 84 if (name.indexOf(':') > 0) { 85 prefix = name.substring(0, name.indexOf(':')); 86 } 87 88 return prefix; 89 } 90 91 98 public static String getLocalName(Element element) { 99 String name = element.getTagName(); 100 101 if (name.indexOf(':') > 0) { 102 name = name.substring(name.indexOf(':')+1); 103 } 104 105 return name; 106 } 107 108 117 public static String getNamespaceURI(Node node, String prefix) { 118 if (node == null || node.getNodeType() != Node.ELEMENT_NODE) { 119 return null; 120 } 121 122 if (prefix.equals("")) { 123 if (((Element) node).hasAttribute("xmlns")) { 124 return ((Element) node).getAttribute("xmlns"); 125 } 126 } else { 127 String nsattr = "xmlns:" + prefix; 128 if (((Element) node).hasAttribute(nsattr)) { 129 return ((Element) node).getAttribute(nsattr); 130 } 131 } 132 133 return getNamespaceURI(node.getParentNode(), prefix); 134 } 135 136 144 public static String getNamespaceURI(Element element) { 145 String prefix = getPrefix(element); 146 return getNamespaceURI(element, prefix); 147 } 148 } 149 | Popular Tags |