MCPcopy Create free account
hub / github.com/BaseXdb/basex / nsScope

Method nsScope

basex-core/src/main/java/org/basex/query/value/node/FElem.java:126–151  ·  view source on GitHub ↗

Gathers all defined namespaces in the scope of the given DOM element. @param elem DOM element @param nsMap map

(final Node elem, final TokenObjectMap<byte[]> nsMap)

Source from the content-addressed store, hash-verified

124 * @param nsMap map
125 */
126 private static void nsScope(final Node elem, final TokenObjectMap<byte[]> nsMap) {
127 Node n = elem;
128 // only elements can declare namespaces
129 while(n instanceof Element) {
130 final NamedNodeMap atts = n.getAttributes();
131 final String prefix = n.getPrefix();
132 if(prefix != null) {
133 final byte[] pref = token(prefix);
134 if(nsMap.get(pref) != null) nsMap.put(pref, token(n.getNamespaceURI()));
135 }
136 final int len = atts.getLength();
137 for(int i = 0; i < len; ++i) {
138 final Attr a = (Attr) atts.item(i);
139 final byte[] name = token(a.getName()), val = token(a.getValue());
140 if(Token.eq(name, XMLNS)) {
141 // default namespace
142 if(nsMap.get(Token.EMPTY) == null) nsMap.put(Token.EMPTY, val);
143 } else if(startsWith(name, XMLNS)) {
144 // prefixed namespace
145 final byte[] ln = local(name);
146 if(nsMap.get(ln) == null) nsMap.put(ln, val);
147 }
148 }
149 n = n.getParentNode();
150 }
151 }
152
153 @Override
154 public Atts namespaces() {

Callers 1

buildMethod · 0.95

Calls 14

eqMethod · 0.95
getParentNodeMethod · 0.80
tokenMethod · 0.65
getMethod · 0.65
getAttributesMethod · 0.45
getPrefixMethod · 0.45
putMethod · 0.45
getNamespaceURIMethod · 0.45
getLengthMethod · 0.45
itemMethod · 0.45
getNameMethod · 0.45
getValueMethod · 0.45

Tested by

no test coverage detected