Android examples for XML:Namespace
gets the XML namespace part of the uri
/*************************************** * ViPER * * The Video Processing * * Evaluation Resource * * * * Distributed under the GPL license * * Terms available at gnu.org. * * * * Copyright University of Maryland, * * College Park. * ***************************************/ //package com.java2s; public class Main { public static void main(String[] argv) throws Exception { String uri = "java2s.com"; System.out.println(namespacePart(uri)); }/*from w ww . j a va2 s . c om*/ /** * gets the namespace part of the uri * @param uri the uri to split * @return the namespace part */ public static String namespacePart(String uri) { int splitChar = getQNameSplitPoint(uri); if (splitChar > 0) { return uri.substring(0, splitChar); } else { return ""; } } /** * Given a uri that represents a qualified name, tries to * determine the index of the split point between the namespace * and the local name. Returns the last index of #, /, or :, * checking for each. If the string contains no :, it doesn't count * as a uri and nothing is returned. * @param uri the uri * @return the split point, or -1 if not found */ public static int getQNameSplitPoint(String uri) { int col = uri.indexOf(":"); if (col < 0) { return -1; } else { int hash = uri.indexOf("#"); if (hash < 0) { int slash = Math.max(uri.lastIndexOf("/"), uri.lastIndexOf("\\")); if (slash > 0) { return slash; } else { return col; } } else { return hash; } } } }