Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    public static boolean isTextXML(String text) {
        text = text.trim();
        if (!(text.startsWith("<") && text.endsWith(">")))
            return false; //If text doesn't begin with "<" it's not XML

        int firstClose = text.indexOf(">");
        int lastOpen = text.lastIndexOf("<");

        if (lastOpen == 0 && text.lastIndexOf("/") == firstClose - 1)
            return true; //Example "<DIMES />
        if (text.substring(1, firstClose + 1).equals(text.substring(lastOpen + 2)))
            return true; //<XML> blah </XML>

        return false;
    }
}