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.

Declaration

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

Method Source Code

//package com.java2s;
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";

    /**/*from   w  w w.  j  av a  2  s . c  o m*/
     * 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. writeMapXml(Map val, String name, XmlSerializer out)
  3. writeSetXml(Set val, String name, XmlSerializer out)
  4. writeSetXml(Set val, String name, XmlSerializer out)
  5. writeSetXml(Set val, String name, XmlSerializer out)
  6. writeSimpleElement(XmlSerializer serializer, String namespace, String elementName, String elementText)
  7. writeStringArrayXml(String[] val, String name, XmlSerializer out)
  8. writeStringArrayXml(String[] val, String name, XmlSerializer out)
  9. writeStringAttribute(XmlSerializer out, String name, String value)