1 3 19 20 package com.sun.org.apache.xml.internal.resolver.helpers; 21 22 import org.w3c.dom.*; 23 24 35 public class Namespaces { 36 43 public static String getPrefix(Element element) { 44 String name = element.getTagName(); 45 String prefix = ""; 46 47 if (name.indexOf(':') > 0) { 48 prefix = name.substring(0, name.indexOf(':')); 49 } 50 51 return prefix; 52 } 53 54 61 public static String getLocalName(Element element) { 62 String name = element.getTagName(); 63 64 if (name.indexOf(':') > 0) { 65 name = name.substring(name.indexOf(':')+1); 66 } 67 68 return name; 69 } 70 71 80 public static String getNamespaceURI(Node node, String prefix) { 81 if (node == null || node.getNodeType() != Node.ELEMENT_NODE) { 82 return null; 83 } 84 85 if (prefix.equals("")) { 86 if (((Element) node).hasAttribute("xmlns")) { 87 return ((Element) node).getAttribute("xmlns"); 88 } 89 } else { 90 String nsattr = "xmlns:" + prefix; 91 if (((Element) node).hasAttribute(nsattr)) { 92 return ((Element) node).getAttribute(nsattr); 93 } 94 } 95 96 return getNamespaceURI(node.getParentNode(), prefix); 97 } 98 99 107 public static String getNamespaceURI(Element element) { 108 String prefix = getPrefix(element); 109 return getNamespaceURI(element, prefix); 110 } 111 } 112 | Popular Tags |