How to Dict to XML

So I found a extension xml do dict, which i did need.

but now I need dict to xml.

Thanks. - UCYT5040

1 Like

DictionaryToXml (1).aix (103.9 KB)

You can use this extension to convert dictionary into xml.

Blocks :

Source code :

package com.oseamiya.util.dictionarytoxml;

import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.*;
import com.google.appinventor.components.runtime.util.*;
import org.json.*;

@DesignerComponent(
        version = 1,
        description = "",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "https://github.com/oseamiya/Baserow/raw/main/assets/icon.png")

@SimpleObject(external = true)
// Used latest version of org.json to support XML 
@UsesLibraries(libraries = "json.jar")

public class DictionaryToXml extends AndroidNonvisibleComponent {

    //Activity and Context
    private Context context;
    private Activity activity;

    public DictionaryToXml(ComponentContainer container){
        super(container.$form());
        this.activity = container.$context();
        this.context = container.$context();
    }
    @SimpleEvent
    public void OnError(String error){
        EventDispatcher.dispatchEvent(this, "OnError", error);
    }
    @SimpleFunction
    public String ObjectToXml(Object dictionary){
        try{
            String json = JsonUtil.getJsonRepresentation(dictionary);
            JSONObject jsonObject = new JSONObject(json);
            return XML.toString(jsonObject);  
        }catch(JSONException e){
            OnError(e.getMessage());
            return "";
        }
    }
}

4 Likes

Or you can do something like this without the extension.
image

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.