B4J Question xmlBuilder help

woniol

Active Member
Licensed User
Longtime User

inakigarm

Well-Known Member
Licensed User
Longtime User
Not Tested !

From this doc (Oracle Java) --OutputKeys XML parameters

And from this post from Erel and the XMLBuilder docs

B4X:
Sub Activity_Create(FirstTime As Boolean)
   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")
   Log(x.asString2(props))
End Sub

Using the code above, to set Standalone to yes you have to add a map entry with Key=standalone and Value=Yes
B4X:
props.Put("standalone", "Yes")
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Above needs an enhancement using a JavaObject.
Have looked at the source code of the xml builder used by B4J here and found setXmlStandalone method is required.

Did test below enhancement:
B4X:
...
SetStandalone(x, True)
props.Put("standalone", "yes")
...

B4X:
Sub SetStandalone(x As XMLBuilder, b As Boolean)
    Dim joXML As JavaObject = x
    joXML.RunMethodJO("getDocument", Null).RunMethod("setXmlStandalone", Array(b))
End Sub

Result:
B4X:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 
Upvote 0

woniol

Active Member
Licensed User
Longtime User
Above needs an enhancement using a JavaObject.
Have looked at the source code of the xml builder used by B4J here and found setXmlStandalone method is required.

Did test below enhancement:
B4X:
...
SetStandalone(x, True)
props.Put("standalone", "yes")
...

B4X:
Sub SetStandalone(x As XMLBuilder, b As Boolean)
    Dim joXML As JavaObject = x
    joXML.RunMethodJO("getDocument", Null).RunMethod("setXmlStandalone", Array(b))
End Sub

Result:
B4X:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
It works.
Thanks a lot!!!
 
Upvote 0
Top