Java tutorial
//package com.java2s; public class Main { /** * * Get a valid xPath string to enable retrieval of an Element by ANDing * attributes name and their corresponding value. note that the full tag * path must also be stated * * @param tagPath * example: /calls/step * @param attrNames * example: call_step * @param attrValues * example: Call failed * * @return A valid xPath string * * */ public static String getXpathAND(String tagPath, String[] attrNames, String[] attrValues) { StringBuffer buf = new StringBuffer(); String retStr; buf.append(tagPath); buf.append("["); for (int i = 0; i < attrValues.length; i++) { buf.append("@"); buf.append(attrNames[i]); buf.append("="); buf.append("'"); buf.append(attrValues[i]); buf.append("'"); if (i != (attrValues.length - 1)) buf.append(" and "); } buf.append("]"); System.out.println("Xpath generated: " + (retStr = buf.toString())); return retStr; } }