Java XMLStreamWriter writeTag(XMLStreamWriter xmlWriter, String tag, Object value)

Here you can find the source of writeTag(XMLStreamWriter xmlWriter, String tag, Object value)

Description

write Tag

License

Open Source License

Declaration

public static void writeTag(XMLStreamWriter xmlWriter, String tag, Object value) throws XMLStreamException 

Method Source Code

//package com.java2s;
/*/*from  ww  w. j a  va2s . c om*/
 * Copyright (C) 2008-2012 Open Wide SA
 *  
 * This library is free software; you can redistribute 
 * it and/or modify it under the terms of version 2.1 of 
 * the GNU Lesser General Public License as published by  
 * the Free Software Foundation.
 * 
 * This library 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General 
 * Public License along with this library; if not, write to the 
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
 * Boston, MA  02111-1307  USA
 * 
 * More information at http://knowledge.openwide.fr/bin/view/Main/AlfrescoETLConnector/
 */

import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;

public class Main {
    public static void writeTag(XMLStreamWriter xmlWriter, String tag, Object value) throws XMLStreamException {
        if (value == null) {
            xmlWriter.writeEmptyElement(tag);
        } else {
            xmlWriter.writeStartElement(tag);
            xmlWriter.writeCData(value.toString());
            xmlWriter.writeEndElement();
        }
    }

    public static String toString(Throwable error) {
        StringBuffer buf = new StringBuffer(512);
        while (error != null) {
            buf.append(error.getClass().getName());
            buf.append(error.getMessage() == null ? "" : error.getMessage());
            buf.append("\r\n");
            StackTraceElement[] stack = error.getStackTrace();
            for (int i = 0; i < stack.length; i++) {
                buf.append("   ");
                buf.append(stack[i].toString());
                buf.append("\r\n");
            }
            if (error.getCause() != null) {
                buf.append("\r\nCaused by :");
            }
            error = error.getCause();
        }
        return buf.toString();
    }
}

Related

  1. writeIndent(XMLStreamWriter xmlsw, String indent)
  2. writeInsertPos(XMLStreamWriter w, boolean isBefore, int[] pos)
  3. writePath(XMLStreamWriter w, Supplier cssClass, Supplier fill, Supplier stroke, Supplier path)
  4. writeSimpleTag(XMLStreamWriter writer, String tag, Object value, boolean asCData)
  5. writeStartElement(XMLStreamWriter writer, QName name)
  6. writeWithCharacters(XMLStreamWriter w, String localName, String text)