Java XML Text Node Create createTextNode(Document doc, Calendar cal, boolean dateOnly)

Here you can find the source of createTextNode(Document doc, Calendar cal, boolean dateOnly)

Description

Creates a Text node for converting a Calendar object into a string of XML timeInstant type or XML date type.

License

Open Source License

Parameter

Parameter Description
doc <code>Document</code> object in which the new element to be created.
cal The <code>Calendar</code> to be converted into a XML <code>Text</code> node.
dateOnly true if the format is XML date type, or false if the format is XML timeInstant type

Declaration

public static Text createTextNode(Document doc, Calendar cal,
        boolean dateOnly) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * The MIT License (MIT)//from  w  w  w .  j  av a  2s .  c o  m
 *  
 * Copyright (c) 2015 Neustar Inc.
 *  
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *  
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *  
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *******************************************************************************/

import java.text.*;
import java.util.*;
import org.w3c.dom.*;

public class Main {
    private static SimpleDateFormat xmlDateFormat;
    private static SimpleDateFormat xmlShortDateFormat;

    /**
     * Creates a <code>Text</code> node for converting a
     * <code>Calendar</code> object into a string of XML timeInstant type.
     *
     * @param doc <code>Document</code> object in which the new element
     *            to be
     *            created.
     * @param cal The <code>Calendar</code> to be converted into a XML
     *            <code>Text</code> node.
     */
    public static Text createTextNode(Document doc, Calendar cal) {
        return createTextNode(doc, cal, false);
    }

    /**
     * Creates a <code>Text</code> node for converting a
     * <code>Calendar</code> object into a string of XML timeInstant
     * type or XML date type.
     *
     * @param doc <code>Document</code> object in which the new element
     *            to be created.
     * @param cal The <code>Calendar</code> to be converted into a XML
     *            <code>Text</code> node.
     * @param dateOnly true if the format is XML date type, or false
     *                 if the format is XML timeInstant type
     */
    public static Text createTextNode(Document doc, Calendar cal,
            boolean dateOnly) {
        if (dateOnly) {
            return doc.createTextNode(xmlShortDateFormat.format(cal
                    .getTime()));
        } else {
            return doc.createTextNode(xmlDateFormat.format(cal.getTime()));
        }
    }
}

Related

  1. createTextElement(Document doc, String name, String content)
  2. createTextElement(final Document document, final String tagName, final String text)
  3. createTextElement(QName qname, String value, Document doc)
  4. createTextLn(Document d, String text)
  5. createTextNode(Document _doc, String tagName, String tagValue)
  6. createTextNode(Document doc, String elemName, String attrName, String attrValue, String content)
  7. createTextNode(Document doc, String string)
  8. createTextNode(Element element, String nodeName, String textValue)
  9. createTextNode(Node doc, String elementName, String elementText)