Builds XML empty tag with name provided. - Android XML

Android examples for XML:XML Tag

Description

Builds XML empty tag with name provided.

Demo Code

/*/*from   w w  w .j a v a2  s.  c o m*/
 * Copyright 2016-present Open Networking Laboratory
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String name = "java2s.com";
        System.out.println(buildEmptyTag(name));
    }

    public static final String SLASH = "/";
    public static final String NEW_LINE = "\n";
    public static final String ANGLE_LEFT = "<";
    public static final String ANGLE_RIGHT = ">";

    /**
     * Builds XML empty tag with name provided.
     *
     * @param name tag name
     * @return string
     */
    public static String buildEmptyTag(String name) {
        return buildEmptyTag(name, true);
    }

    /**
     * Builds XML empty element tag with name provided.
     *
     * @param name tag name
     * @param addNewLine option to add new line character after tag
     * @return string
     */
    public static String buildEmptyTag(String name, boolean addNewLine) {
        if (addNewLine) {
            return (ANGLE_LEFT + name + SLASH + ANGLE_RIGHT + NEW_LINE);
        } else {
            return (ANGLE_LEFT + name + SLASH + ANGLE_RIGHT);
        }
    }
}

Related Tutorials