Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**
     * Append string literal in XPath context.
     *
     * @param xpath StringBuilder for building XPath.
     * @param s string literal.
     */
    public static void appendStringLiteral(StringBuilder xpath, String s) {
        if (s.indexOf('"') >= 0) {
            if (s.indexOf('\'') >= 0)
                xpath.append("concat(\"").append(s.replace("\"", "\",'\"',\"")).append("\")");
            else
                xpath.append('\'').append(s).append('\'');
        } else {
            xpath.append('"').append(s).append('"');
        }
    }
}