Android examples for XML:XML Element
Gets the local part of a uri from XML Element
/*************************************** * 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(localName(uri)); }//from w ww . j a va 2s.c o m /** * Gets the local part of a uri. * @param uri the uri to split * @return the local part, if found */ public static String localName(String uri) { int i = getQNameSplitPoint(uri) + 1; if (i < uri.length()) { return uri.substring(i); } 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; } } } }