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

Method defaultNs

basex-core/src/main/java/org/basex/data/Namespaces.java:123–147  ·  view source on GitHub ↗

Returns the common default namespace of all documents of the database. @param ndocs number of documents @return namespace, or null if there is no common namespace

(final int ndocs)

Source from the content-addressed store, hash-verified

121 * @return namespace, or {@code null} if there is no common namespace
122 */
123 byte[] defaultNs(final int ndocs) {
124 // no namespaces defined: default namespace is empty
125 final int ch = root.children();
126 if(ch == 0) return Token.EMPTY;
127 // give up if number of default namespaces differs from number of documents
128 if(ch != ndocs) return null;
129
130 int id = 0;
131 for(int c = 0; c < ch; c++) {
132 final NSNode child = root.child(c);
133 final int[] values = child.values();
134 // give up if child node has more children or more than one namespace
135 // give up if namespace has a non-empty prefix
136 if(child.children() > 0 || child.pre() != 1 || values.length != 2 ||
137 prefix(values[0]).length != 0) return null;
138 // check if all documents have the same default namespace
139 if(c == 0) {
140 id = values[1];
141 } else if(id != values[1]) {
142 return null;
143 }
144 }
145 // return common default namespace
146 return uri(id);
147 }
148
149 // Requesting Namespaces Based on Context =======================================================
150

Callers

nothing calls this directly

Calls 6

childrenMethod · 0.95
valuesMethod · 0.95
preMethod · 0.95
prefixMethod · 0.95
uriMethod · 0.95
childMethod · 0.80

Tested by

no test coverage detected