Java tutorial
//package com.java2s; /* * Copyright 2007, Plutext Pty Ltd. * * This file is part of Docx4all. Docx4all is free software: you can redistribute it and/or modify it under the terms of version 3 of the GNU General Public License as published by the Free Software Foundation. Docx4all is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Docx4all. If not, see <http://www.gnu.org/licenses/>. */ import javax.xml.namespace.QName; import org.w3c.dom.Node; public class Main { public final static String getEnclosingTagPair(QName qname) { return getEnclosingTagPair(qname.getPrefix(), qname.getLocalPart()); } public final static String getEnclosingTagPair(Node node) { return getEnclosingTagPair(node.getPrefix(), node.getLocalName()); } private final static String getEnclosingTagPair(String prefix, String localName) { if (prefix == null) { prefix = ""; } else if (prefix.length() > 0) { prefix = prefix + ":"; } StringBuffer sb = new StringBuffer(); sb.append("<"); sb.append(prefix); sb.append(localName); sb.append(">"); sb.append("</"); sb.append(prefix); sb.append(localName); sb.append(">"); return sb.toString(); } }