Android Question Changing XML's Character Encoding

Cosmotastic

Member
Licensed User
Hello,
I have made an XML using XMLBuilder and im wondering how i could save the XML i have made like this

B4X:
<?xml version="1.0" encoding="ISO-8859-1"?>

This is my current code
B4X:
    Dim X As XMLBuilder
    X = X.create("DataBase")
    X =    X.e("NetworkData").e("OPC").Text("Active").up.up
    X =    X.e("Substations").e("SSName").Text("SS2").up
    X =    X.e("Meter").e("MName").Text("SS2 (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS2MSBPower).up
    X = X.e("Energy").Text(SS2MSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS2 (YSTD4 PORT P8)").up
    X = X.e("JobNo").Text(SS2YSTD4PORTP8JobNo).up
    X = X.e("SName").Text(SS2YSTD4PORTP8SName).up
    X = X.e("Power").Text(SS2YSTD4PORTP8Power).up
    X = X.e("Energy").Text(SS2YSTD4PORTP8Energy).up
    X = X.e("StaffNameIn").Text(SS2YSTD4PORTP8IN).up
    X = X.e("StaffNameOut").Text(SS2YSTD4PORTP8OUT).up.up                        
    X =    X.e("Meter").e("MName").Text("SS2 (YST12 8)").up
    X = X.e("JobNo").Text(SS2YST128JobNo).up
    X = X.e("SName").Text(SS2YST128SName).up
    X = X.e("Power").Text(SS2YST128Power).up
    X = X.e("Energy").Text(SS2YST128Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS2 (SPARE)").up
    X = X.e("JobNo").Text(SS2SPAREJobNo).up
    X = X.e("SName").Text(SS2SPARESName).up
    X = X.e("Power").Text(SS2SPAREPower).up
    X = X.e("Energy").Text(SS2SPAREEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS2 (YSTD4 PORT P2, P5)").up
    X = X.e("JobNo").Text(SS2YSTD4PORTP2P5JobNo).up
    X = X.e("SName").Text(SS2YSTD4PORTP2P5SName).up
    X = X.e("Power").Text(SS2YSTD4PORTP2P5Power).up
    X = X.e("Energy").Text(SS2YSTD4PORTP2P5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS2 (YST12 2, 5)").up
    X = X.e("JobNo").Text(SS2YST1225JobNo).up
    X = X.e("SName").Text(SS2YST1225SName).up
    X = X.e("Power").Text(SS2YST1225Power).up
    X = X.e("Energy").Text(SS2YST1225Energy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS2A").up
    X =    X.e("Meter").e("MName").Text("SS2A (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS2AMSBPower).up
    X = X.e("Energy").Text(SS2AMSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS2A (YST11 P2, P5)").up
    X = X.e("JobNo").Text(SS2AYST11P2P5JobNo).up
    X = X.e("SName").Text(SS2AYST11P2P5SName).up
    X = X.e("Power").Text(SS2AYST11P2P5Power).up
    X = X.e("Energy").Text(SS2AYST11P2P5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS2A (YST10 S2, S5)").up
    X = X.e("JobNo").Text(SS2AYST10S2S5JobNo).up
    X = X.e("SName").Text(SS2AYST10S2S5SName).up
    X = X.e("Power").Text(SS2AYST10S2S5Power).up
    X = X.e("Energy").Text(SS2AYST10S2S5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS2A (SPARE)").up
    X = X.e("JobNo").Text(SS2ASPAREJobNo).up
    X = X.e("SName").Text(SS2ASPARESName).up
    X = X.e("Power").Text(SS2ASPAREPower).up
    X = X.e("Energy").Text(SS2ASPAREEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS2A (YST11 P8)").up
    X = X.e("JobNo").Text(SS2AYST11P8JobNo).up
    X = X.e("SName").Text(SS2AYST11P8SName).up
    X = X.e("Power").Text(SS2AYST11P8Power).up
    X = X.e("Energy").Text(SS2AYST11P8Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS2A (YST10 S8)").up
    X = X.e("JobNo").Text(SS2AYST10S8JobNo).up
    X = X.e("SName").Text(SS2AYST10S8SName).up
    X = X.e("Power").Text(SS2AYST10S8Power).up
    X = X.e("Energy").Text(SS2AYST10S8Energy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS3").up
    X =    X.e("Meter").e("MName").Text("SS3 (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS3MSBPower).up
    X = X.e("Energy").Text(SS3MSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS3 (YSTD3 PORT P5, P6)").up
    X = X.e("JobNo").Text(SS3YSTD3PORTP5P6JobNo).up
    X = X.e("SName").Text(SS3YSTD3PORTP5P6SName).up
    X = X.e("Power").Text(SS3YSTD3PORTP5P6Power).up
    X = X.e("Energy").Text(SS3YSTD3PORTP5P6Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS3 (YSTD3 PORT P10)").up
    X = X.e("JobNo").Text(SS3YSTD3PORTP10JobNo).up
    X = X.e("SName").Text(SS3YSTD3PORTP10SName).up
    X = X.e("Power").Text(SS3YSTD3PORTP10Power).up
    X = X.e("Energy").Text(SS3YSTD3PORTP10Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS3 (YSTD4 STBD S8)").up
    X = X.e("JobNo").Text(SS3YSTD4STBDS8JobNo).up
    X = X.e("SName").Text(SS3YSTD4STBDS8SName).up
    X = X.e("Power").Text(SS3YSTD4STBDS8Power).up
    X = X.e("Energy").Text(SS3YSTD4STBDS8Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS3 (YSTD4 STBD S2, S5)").up
    X = X.e("JobNo").Text(SS3YSTD4STBDS2S5JobNo).up
    X = X.e("SName").Text(SS3YSTD4STBDS2S5SName).up
    X = X.e("Power").Text(SS3YSTD4STBDS2S5Power).up
    X = X.e("Energy").Text(SS3YSTD4STBDS2S5Energy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS4").up
    X =    X.e("Meter").e("MName").Text("SS4 (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS4MSBPower).up
    X = X.e("Energy").Text(SS4MSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS4 (YSTD3 STBD S2, S5)").up
    X = X.e("JobNo").Text(SS4YSTD3STBDS2S5JobNo).up
    X = X.e("SName").Text(SS4YSTD3STBDS2S5SName).up
    X = X.e("Power").Text(SS4YSTD3STBDS2S5Power).up
    X = X.e("Energy").Text(SS4YSTD3STBDS2S5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS4 (YSTD3 STBD S6, S10)").up
    X = X.e("JobNo").Text(SS4YSTD3STBDS6S10JobNo).up
    X = X.e("SName").Text(SS4YSTD3STBDS6S10SName).up
    X = X.e("Power").Text(SS4YSTD3STBDS6S10Power).up
    X = X.e("Energy").Text(SS4YSTD3STBDS6S10Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS4 (SPARE)").up
    X = X.e("JobNo").Text(SS4SPAREJobNo).up
    X = X.e("SName").Text(SS4SPARESName).up
    X = X.e("Power").Text(SS4SPAREPower).up
    X = X.e("Energy").Text(SS4SPAREEnergy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS4A").up
    X =    X.e("Meter").e("MName").Text("SS4A (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS4AMSBPower).up
    X = X.e("Energy").Text(SS4AMSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS4A (YST9 P2, P5)").up
    X = X.e("JobNo").Text(SS4AYST9P2P5JobNo).up
    X = X.e("SName").Text(SS4AYST9P2P5SName).up
    X = X.e("Power").Text(SS4AYST9P2P5Power).up
    X = X.e("Energy").Text(SS4AYST9P2P5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS4A (YST8 S2, S5)").up
    X = X.e("JobNo").Text(SS4AYST8S2S5JobNo).up
    X = X.e("SName").Text(SS4AYST8S2S5SName).up
    X = X.e("Power").Text(SS4AYST8S2S5Power).up
    X = X.e("Energy").Text(SS4AYST8S2S5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS4A (YST9 P8)").up
    X = X.e("JobNo").Text(SS4AYST9P8JobNo).up
    X = X.e("SName").Text(SS4AYST9P8SName).up
    X = X.e("Power").Text(SS4AYST9P8Power).up
    X = X.e("Energy").Text(SS4AYST9P8Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS4A (YST8 S8)").up
    X = X.e("JobNo").Text(SS4AYST8S8JobNo).up
    X = X.e("SName").Text(SS4AYST8S8SName).up
    X = X.e("Power").Text(SS4AYST8S8Power).up
    X = X.e("Energy").Text(SS4AYST8S8Energy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS5A").up
    X =    X.e("Meter").e("MName").Text("SS5A (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS5AMSBPower).up
    X = X.e("Energy").Text(SS5AMSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS5A (YSTD2 PORT P2, P5)").up
    X = X.e("JobNo").Text(SS5AYSTD2PORTP2P5JobNo).up
    X = X.e("SName").Text(SS5AYSTD2PORTP2P5SName).up
    X = X.e("Power").Text(SS5AYSTD2PORTP2P5Power).up
    X = X.e("Energy").Text(SS5AYSTD2PORTP2P5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS5A (YSTD2 PORT P6, P9)").up
    X = X.e("JobNo").Text(SS5AYSTD2PORTP6P9JobNo).up
    X = X.e("SName").Text(SS5AYSTD2PORTP6P9SName).up
    X = X.e("Power").Text(SS5AYSTD2PORTP6P9Power).up
    X = X.e("Energy").Text(SS5AYSTD2PORTP6P9Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS5A (SPARE)").up
    X = X.e("JobNo").Text(SS5ASPAREJobNo).up
    X = X.e("SName").Text(SS5ASPARESName).up
    X = X.e("Power").Text(SS5ASPAREPower).up
    X = X.e("Energy").Text(SS5ASPAREEnergy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS6").up
    X =    X.e("Meter").e("MName").Text("SS6 (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS6MSBPower).up
    X = X.e("Energy").Text(SS6MSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS6 (YSTD1 PORT P1, P5)").up
    X = X.e("JobNo").Text(SS6YSTD1PORTP1P5JobNo).up
    X = X.e("SName").Text(SS6YSTD1PORTP1P5SName).up
    X = X.e("Power").Text(SS6YSTD1PORTP1P5Power).up
    X = X.e("Energy").Text(SS6YSTD1PORTP1P5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS6 (YSTD1 PORT P8)").up
    X = X.e("JobNo").Text(SS6YSTD1PORTP8JobNo).up
    X = X.e("SName").Text(SS6YSTD1PORTP8SName).up
    X = X.e("Power").Text(SS6YSTD1PORTP8Power).up
    X = X.e("Energy").Text(SS6YSTD1PORTP8Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS6 (YSTD2 STBD S2, S6)").up
    X = X.e("JobNo").Text(SS6YSTD2STBDS2S6JobNo).up
    X = X.e("SName").Text(SS6YSTD2STBDS2S6SName).up
    X = X.e("Power").Text(SS6YSTD2STBDS2S6Power).up
    X = X.e("Energy").Text(SS6YSTD2STBDS2S6Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS6 (YSTD2 STBD S9)").up
    X = X.e("JobNo").Text(SS6YSTD2STBDS9JobNo).up
    X = X.e("SName").Text(SS6YSTD2STBDS9SName).up
    X = X.e("Power").Text(SS6YSTD2STBDS9Power).up
    X = X.e("Energy").Text(SS6YSTD2STBDS9Energy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS7").up
    X =    X.e("Meter").e("MName").Text("SS7 (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS7MSBPower).up
    X = X.e("Energy").Text(SS7MSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS7 (YST5 7, 9)").up
    X = X.e("JobNo").Text(SS7YST579JobNo).up
    X = X.e("SName").Text(SS7YST579SName).up
    X = X.e("Power").Text(SS7YST579Power).up
    X = X.e("Energy").Text(SS7YST579Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS7 (YST5 3, 5)").up
    X = X.e("JobNo").Text(SS7YST535JobNo).up
    X = X.e("SName").Text(SS7YST535SName).up
    X = X.e("Power").Text(SS7YST535Power).up
    X = X.e("Energy").Text(SS7YST535Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS7 (YSTD1 STBD S2, S5)").up
    X = X.e("JobNo").Text(SS7YSTD1STBDS2S5JobNo).up
    X = X.e("SName").Text(SS7YSTD1STBDS2S5SName).up
    X = X.e("Power").Text(SS7YSTD1STBDS2S5Power).up
    X = X.e("Energy").Text(SS7YSTD1STBDS2S5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS7 (YSTD1 STBD S8)").up
    X = X.e("JobNo").Text(SS7YSTD1STBDS8JobNo).up
    X = X.e("SName").Text(SS7YSTD1STBDS8SName).up
    X = X.e("Power").Text(SS7YSTD1STBDS8Power).up
    X = X.e("Energy").Text(SS7YSTD1STBDS8Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS7 (SPARE)").up
    X = X.e("JobNo").Text(SS7SPAREJobNo).up
    X = X.e("SName").Text(SS7SPARESName).up
    X = X.e("Power").Text(SS7SPAREPower).up
    X = X.e("Energy").Text(SS7SPAREEnergy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS7A").up
    X =    X.e("Meter").e("MName").Text("SS7A (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS7AMSBPower).up
    X = X.e("Energy").Text(SS7AMSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS7A (YST7 P8)").up
    X = X.e("JobNo").Text(SS7AYST7P8JobNo).up
    X = X.e("SName").Text(SS7AYST7P8SName).up
    X = X.e("Power").Text(SS7AYST7P8Power).up
    X = X.e("Energy").Text(SS7AYST7P8Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS7A (YST7 P2, P5)").up
    X = X.e("JobNo").Text(SS7AYST7P2P5JobNo).up
    X = X.e("SName").Text(SS7AYST7P2P5SName).up
    X = X.e("Power").Text(SS7AYST7P2P5Power).up
    X = X.e("Energy").Text(SS7AYST7P2P5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS7A (YST6 S2, S5)").up
    X = X.e("JobNo").Text(SS7AYST6S2S5JobNo).up
    X = X.e("SName").Text(SS7AYST6S2S5SName).up
    X = X.e("Power").Text(SS7AYST6S2S5Power).up
    X = X.e("Energy").Text(SS7AYST6S2S5Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS7A (YST6 S8)").up
    X = X.e("JobNo").Text(SS7AYST6S8JobNo).up
    X = X.e("SName").Text(SS7AYST6S8SName).up
    X = X.e("Power").Text(SS7AYST6S8Power).up
    X = X.e("Energy").Text(SS7AYST6S8Energy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS9A").up
    X =    X.e("Meter").e("MName").Text("SS9A (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS9AMSBPower).up
    X = X.e("Energy").Text(SS9AMSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS9A (YST3 P6, P8)").up
    X = X.e("JobNo").Text(SS9AYST3P6P8JobNo).up
    X = X.e("SName").Text(SS9AYST3P6P8SName).up
    X = X.e("Power").Text(SS9AYST3P6P8Power).up
    X = X.e("Energy").Text(SS9AYST3P6P8Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS9A (YST3 P2, P4)").up
    X = X.e("JobNo").Text(SS9AYST3P2P4JobNo).up
    X = X.e("SName").Text(SS9AYST3P2P4SName).up
    X = X.e("Power").Text(SS9AYST3P2P4Power).up
    X = X.e("Energy").Text(SS9AYST3P2P4Energy).up.up.up
    X =    X.e("Substations").e("SSName").Text("SS9B").up
    X =    X.e("Meter").e("MName").Text("SS9B (MSB)").up
    X = X.e("JobNo").Text("").up
    X = X.e("SName").Text("").up
    X = X.e("Power").Text(SS9BMSBPower).up
    X = X.e("Energy").Text(SS9BMSBEnergy).up.up
    X =    X.e("Meter").e("MName").Text("SS9B (YST2 P11, P13)").up
    X = X.e("JobNo").Text(SS9BYST2P11P13JobNo).up
    X = X.e("SName").Text(SS9BYST2P11P13SName).up
    X = X.e("Power").Text(SS9BYST2P11P13Power).up
    X = X.e("Energy").Text(SS9BYST2P11P13Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS9B (YST1, P19)").up
    X = X.e("JobNo").Text(SS9BYST1P19JobNo).up
    X = X.e("SName").Text(SS9BYST1P19SName).up
    X = X.e("Power").Text(SS9BYST1P19Power).up
    X = X.e("Energy").Text(SS9BYST1P19Energy).up.up
    X =    X.e("Meter").e("MName").Text("SS9B (YST2 P15, P18)").up
    X = X.e("JobNo").Text(SS9BYST2P15P18JobNo).up
    X = X.e("SName").Text(SS9BYST2P15P18SName).up
    X = X.e("Power").Text(SS9BYST2P15P18Power).up
    X = X.e("Energy").Text(SS9BYST2P15P18Energy).up.up.up
           
    Dim props As Map
    props.Initialize
    File.WriteString(File.DirRootExternal, "create.xml", X.asString2(props))
 

Cosmotastic

Member
Licensed User
Could you give me an example how i could change the character encoding for my current XML file generated using XMLBuilder? I have tried but i cant seem to change it :(
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Dim x As XMLBuilder
x = x.create("Projects")
x = x.element("java-xmlbuilder") _
    .attribute("language", "Java") _
    .attribute("scm", "SVN") _
    .element("Location") _
    .up() _
.up() _
.element("JetS3t")
Dim props As Map
props.Initialize
props.Put("{http://xml.apache.org/xslt}indent-amount", "4")
props.Put("indent", "yes")
props.Put("encoding", "ISO-8859-1") '<======================
Dim s As String = x.asString2(props)
Dim tw As TextWriter
tw.Initialize2(File.OpenOutput(File.DirInternal, "1.txt", False), "ISO-8859-1")
tw.Write(s)
tw.Close
 
Upvote 0
Top