B4A Library B4A / B4J - XmlBuilder

Status
Not open for further replies.

mebcs

Member
Licensed User
My app needs to output its data in xml files.
Someone pointed me to XmlBuilder.
I have the java-xmlbuilder-0.4.jar file but need its xml to use in the b4a library. Catch 22 lol

Does anyone use it? can you post the needed files?
 

Erel

Administrator
Staff member
Licensed User
A wrapper is attached.

Example:
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
 

Attachments

Last edited:

warwound

Expert
Licensed User
This looks interesting - exactly what i'll be needing to create some KML files in the near future.

Thanks.

Martin.
 

Amalkotey

Active Member
Licensed User
@Erel:

How can I save file formatted XML? Thank you for your help in advance.
 

b4AMarkO

Member
Licensed User
Erel - Love this program was a great purchase
Ok, In vb I used xml files for small database in a few programs

Where I could add or remove attributes and add the data I needed to the xml

Will this let me do that?
 

melamoud

Active Member
Licensed User
is there a way to construct an XMLBuilder from an inputstream ?

anyone know if there is a way to build xmlBuilder from a string / file / input stream ?

I want to create an xmlBuilder from file, so I can add to it easily

thanks
 

andrewj

Active Member
Licensed User
Hi,
This may overlap the previous question, but is there any example of using the XML builder by loading an existing string taken from a file saved as per #5. I've got the output side working perfectly (and first time!), and I'd like to use a similar approach in reverse.

Thanks
Andrew
 

Douglas Farias

Expert
Licensed User
how to generate code like this
B4X:
<?xml version="1.0" encoding="utf-8"?>
<SERVICOS xmlns="SERVICO.COM.BR">
    <SERVICO>
        <ID>1</ID>
        <COD_APARELHO>6039111111</COD_APARELHO>
        <NUMERO_APARELHO>99999955555</NUMERO_APARELHO>
        <SERVICO>FEITO REVIS�O PREVIA E LIMPEZA DO XXX E YYYY, REVISEI TAMBEM O ??????,</SERVICO>            
        <CODIGO_USUARIO>1</CODIGO_USUARIO>
        <DATA_HORA>09/12/2014 09:52:00</DATA_HORA>
    </SERVICO>
</SERVICOS>
??

i dont understand how to put a value inside the element
like this
<ID>1</ID>

i m using
B4X:
       Dim x As XMLBuilder
   x = x.create("SERVICOS").attribute("xmlns", "SERVICO.COM.BR")
 
   x = x.element("SERVICO") _
        .element("ID") _
        .up() _
    .up() _
  
   Dim props As Map
   props.Initialize
   props.Put("{http://xml.apache.org/xslt}indent-amount", "4")
   props.Put("indent", "yes")
 
   Log(x.asString2(props))
but is not correct, and with atribute dont work too
<ID id="1"/>
i need <ID>1</ID>

how to make this?
 

Douglas Farias

Expert
Licensed User
yes i made this thx
B4X:
       Dim x As XMLBuilder
   x = x.create("SERVICOS").attribute("xmlns", "SERVICO.COM.BR")
  
   x = x.element("SERVICO_") _
        .element("ID") _
        .text("1") _
        .up() _
        .element("COD_APARELHO") _
        .text("110202120") _
        .up() _
        .element("NUMERO_APARELHO") _
        .text("110202120") _
        .up() _
        .element("DESC_SERVICO") _
        .text("110202120") _
        .up() _
        .element("CODIGO_USUARIO") _
        .text("110202120") _
        .up() _
        .element("DATA_HORA") _
        .text("110202120") _
        .up() _
    .up() _
   
   Dim props As Map
   props.Initialize
   props.Put("{http://xml.apache.org/xslt}indent-amount", "4")
   props.Put("indent", "yes")
  
   File.WriteString(fp, "1.xml", x.asString2(props))
   If File.Exists(fp,"1.xml" ) Then  Log("existe")
   File.Copy(fp, "1.xml", File.DirRootExternal, "1.xml")
 

loonet

Member
Licensed User
I'm using this library to output an XML file by using SQL lite database data.
This is the output I need but I have problems to add the <item> nodes under the <inspdata> node.
Someone can give me an example of code ? Thanks

<ispezione>
<data>2014-11-13</data>
<cliente>Aspiag xyz</cliente>
<sede>Mestrino</sede>
<reparto>RA-123123</reparto>
<inspdata>
<item>
<codice>345</codice>
<parte>trave1</parte>
<danno>medio</danno>
<item/>
<item>
<codice>5xyry</codice>
<parte>trave2</parte>
<danno>grave</danno>
<item/>
<item>
<codice>uret55</codice>
<parte>trave3</parte>
<danno>lieve</danno>
<item/>
</inspdata>
</ispezione>
 
Status
Not open for further replies.
Top