Android XML Serializer Write writeSimpleElement(XmlSerializer serializer, String namespace, String elementName, String elementText)

Here you can find the source of writeSimpleElement(XmlSerializer serializer, String namespace, String elementName, String elementText)

Description

Writes a simple element such as johndoe.

License

Open Source License

Declaration

public static void writeSimpleElement(XmlSerializer serializer,
        String namespace, String elementName, String elementText)
        throws IOException, XmlPullParserException 

Method Source Code

//package com.java2s;
// for license please see accompanying LICENSE.txt file (available also at http://www.xmlpull.org/)

import java.io.IOException;

import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

public class Main {
    public static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";

    /**//  w  ww. j av a  2s  .c om
     * Writes a simple element such as <username>johndoe</username>. The namespace
     * and elementText are allowed to be null. If elementText is null, an xsi:nil="true"
     * will be added as an attribute.
     */
    public static void writeSimpleElement(XmlSerializer serializer,
            String namespace, String elementName, String elementText)
            throws IOException, XmlPullParserException {

        if (elementName == null) {
            throw new XmlPullParserException(
                    "name for element can not be null");
        }

        serializer.startTag(namespace, elementName);
        if (elementText == null) {
            serializer.attribute(XSI_NS, "nil", "true");
        } else {
            serializer.text(elementText);
        }
        serializer.endTag(namespace, elementName);
    }
}

Related

  1. writeMapXml(Map val, String name, XmlSerializer out)
  2. writeSetXml(Set val, String name, XmlSerializer out)
  3. writeSetXml(Set val, String name, XmlSerializer out)
  4. writeSetXml(Set val, String name, XmlSerializer out)
  5. writeSimpleElement(XmlSerializer serializer, String namespace, String elementName, String elementText)
  6. writeStringArrayXml(String[] val, String name, XmlSerializer out)
  7. writeStringArrayXml(String[] val, String name, XmlSerializer out)
  8. writeStringAttribute(XmlSerializer out, String name, String value)
  9. writeUriAttribute(XmlSerializer out, String name, Uri value)