Android Question Upload XML?

Cosmotastic

Member
Licensed User
How do i upload my xml that i have created using XMLBuilder? I have tried this but it doesnt seem to change anything...

B4X:
Dim props As Map
    props.Initialize
    props.Put("{http://"&Main.Ip&"/PowerMeter/SampleData}indent-amount", "8")
    props.Put("indent", "Yes")
    File.WriteString(File.DirRootExternal, "create.xml", X.asString2(props))

This is my code for XMLBuilder
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("ShipStaff").Text(SS2YSTD4PORTP8).up.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("ShipStaff").Text(SS2YSTD4PORTP8).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
 

colboy

Member
Licensed User
Longtime User
You need to do something like this:

B4X:
   Dim Job2 As HttpJob
   Job2.Initialize("Job2", Me)
   Job2.PostString("http://"&Main.Ip&"/PowerMeter/SampleData", x.tostring) 'I think it's x.tostring, not sure, haven't used this before. Just need the text representation
   Job2.GetRequest.SetContentType("application/json")
   wait for (Job2) JobDone(Job2 As HttpJob)
   If Job2.Success Then
      'Your Code Here
   End If
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
You need a newer B4A Version for the wait for. What B4A Version are you using?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Im currently using B4A 3.5 at the moment
i strongly suggest to update to B4A 8+ (V3.5 is REALLY old now and a lot has changed in Android since 2013)

You can try https://www.b4x.com/android/forum/threads/httputils2-web-services-are-now-even-simpler.18992/ and check if you can use the old httputils.
Take the thread as example on how it works without using wait for. Use the Result-Event instead.

Try to use https://www.b4x.com/android/forum/threads/okhttp-replaces-the-http-library.54723/ this is the most up to date library.
 
Upvote 0
Top