Java XML Node Path pathUp(Node node, int level)

Here you can find the source of pathUp(Node node, int level)

Description

path Up

License

Open Source License

Declaration

public static String pathUp(Node node, int level) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2008-2010 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from  w  w w  .  j  a va 2s .c o  m
 *      Sonatype, Inc. - initial API and implementation
 *******************************************************************************/

import org.w3c.dom.Element;
import org.w3c.dom.Node;

public class Main {
    public static String pathUp(Node node, int level) {
        StringBuffer buf = new StringBuffer();
        int current = level;
        while (node != null && current > 0) {
            if (node instanceof Element) {
                if (buf.length() > 0) {
                    buf.insert(0, "/");
                }
                buf.insert(0, node.getNodeName());
                current = current - 1;
            }
            node = node.getParentNode();
        }
        return buf.toString();
    }
}

Related

  1. getValueViaPath(Node node, String path)
  2. getVectorPathFromNode(Node node)
  3. getVectorPathFromNode(Node node)
  4. getVectorPathFromNode(Node node)
  5. pathTo(Node xmlNode)
  6. pathUp(Node node, int level)