Java examples for XML:XML Attribute
Get a valid xPath string to enable retrieval of an Element by OR ing attributes name and their corresponding value.
/*//from w ww . j a v a 2 s . c o m * Copyright 2005-2010 Ignis Software Tools Ltd. All rights reserved. */ //package com.java2s; public class Main { /** * * Get a valid xPath string to enable retrieval of an Element by ORing * 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 getXpathOR(String tagPath, String[] attrNames, String[] attrValues) { StringBuffer buf = new StringBuffer(); 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(" or "); } buf.append("]"); // System.out.println("Xpath generated: " + (retStr = buf.toString())); return buf.toString(); } }