Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String getLevel(String xpath, int level) {
        String[] paths = split(xpath);
        StringBuffer b = new StringBuffer();
        for (int i = 0; i < level; i++) {
            b.append(paths[i]);
            b.append(' '); // compensates the slash
        }
        b.append(paths[level]);
        b.append('/');
        return b.toString();
    }

    public static String[] split(String xpath) {
        String[] paths = xpath.split("/");
        if (paths.length == 0) {
            paths = new String[1];
            paths[0] = "";
        }
        return paths;
    }
}