package cgeo.geocaching.utils;

import org.xmlpull.v1.XmlSerializer;

import java.io.IOException;

public final class XmlUtils {

    private XmlUtils() {
        // Do not instantiate
    }

    /**
     * Insert an attribute-less tag with enclosed text in a XML serializer output.
     *
     * @param serializer an XML serializer
     * @param prefix an XML prefix, see {@link XmlSerializer#startTag(String, String)}
     * @param tag an XML tag
     * @param text some text to insert
     * @throws IOException
     */
    public static void simpleText(final XmlSerializer serializer, final String prefix, final String tag, final String text) throws IOException {
        serializer.startTag(prefix, tag);
        serializer.text(text);
        serializer.endTag(prefix, tag);
    }

    /**
     * Insert pairs of attribute-less tags and enclosed texts in a XML serializer output
     *
     * @param serializer an XML serializer
     * @param prefix an XML prefix, see {@link XmlSerializer#startTag(String, String)} shared by all tags
     * @param tagAndText an XML tag, the corresponding text, another XML tag, the corresponding text, …
     * @throws IOException
     */
    public static void multipleTexts(final XmlSerializer serializer, final String prefix, final String... tagAndText) throws IOException {
        for (int i = 0; i < tagAndText.length; i += 2) {
            simpleText(serializer, prefix, tagAndText[i], tagAndText[i+1]);
        }
    }
}

@@ -480,17 +480,63 @@
 o insert
+, or %3Ctt%3Enull%3C/tt%3E to omit completely this tag
 %0A
-
      * @
@@ -699,32 +699,64 @@
 s IOException %7B%0A
+        if (text != null) %7B%0A    
         serializ
@@ -781,32 +781,36 @@
 , tag);%0A        
+    
 serializer.text(
@@ -816,32 +816,36 @@
 (text);%0A        
+  
+  
 serializer.endTa
@@ -856,24 +856,34 @@
 efix, tag);%0A
+        %7D%0A
     %7D%0A%0A    /
@@ -1234,11 +1234,103 @@
 text
-, %E2%80%A6
+. %3Ctt%3Enull%3C/tt%3E texts%0A     *                   will be omitted along with their respective tag.
 %0A   

fix #3690: NPE while exporting GPX