Libraries & objects
About Archicad and BIMcloud libraries, their management and migration, objects and other library parts, etc.

Create XML document by GDL

Frank Beister
Moderator
The GDL documentation of the XML AddOn is quiet better than most of the GDL manual, but I struggle with creating an XML file out of an object. Has anyone a functionating example, which will introduce me and lead me around the AC crashes by using "Flush" an "NewElement"?

Thanks!
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
6 REPLIES 6
Ben Cohen
Advocate
Hi Frank

Depending on how you need your XML file formatted, the following code will create an xml file (a basic file with no schema). Remembering that xml is just fancy formatted text.

Hope this helps




!!-file path
fspec="C:\Your File Path\File Name.xml"

!!-First write - note this uses Mode = WO
chx = open("text",fspec,"Separator='\t',Mode = WO,FULLPATH")
OUTPUT chx, 1,1,"<Header 1>"
OUTPUT chx,1,2," <Header 2>"
close chx

!!- Create the main part of the xml file - note we use Mode = WA (Write Append Here)
!!- Loop into this sub routine as required
gosub 'Write XML Body'

!!-Finish off with this
ch = open("text",fspec,"Separator='\t',Mode = WA,FULLPATH")
OUTPUT ch,1,1," </Header 2>"
OUTPUT ch, 1,2,"</Header 1>"
close ch



end


!!=========

'Write XML Body':

ch = open("text",fspec,"Separator='\t',Mode = WA,FULLPATH")
OUTPUT ch,1,1,"<Body 1>"
OUTPUT ch,1,2,"<Field 2>" + Parameter1 + "</Field 2>"
OUTPUT ch,1,3,"<Field 3>" + Parameter2 + "</Field 3>"
OUTPUT ch,1,4,"<Field 4>" + Parameter3 + "</Field 4>"
OUTPUT ch,1,5,"<Field 5>" + Parameter4 + "</Field 5>"
OUTPUT ch,1,6,"<Field 6>"
OUTPUT ch,1,7,Parameter5
OUTPUT ch,1,8,"</Field 6>"
OUTPUT ch,1,9,"<Field 7>" + Parameter6 + "</Field 7>"
OUTPUT ch,1,10,"</Body 1>"
close ch

return
Ben Cohen
Mac and PC
Archicad (Latest Version) aus
www.4DLibrary.com.au
Frank Beister
Moderator
Thanks Ben, but this is only plan b. I know, that it is just a special formatted text file, but in your example I have to handle the whole structure and syntax by myself.

What I want is to open/create the XML file directly by the XML AddOn. I can create it in this way yet, but not more than the root node so far. Creating a child node causes AC crashes. It looks like I am doing something GS programmers haven't thought of somebody could do.
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
ztaskai
Graphisoft Alumni
Graphisoft Alumni
Hi,

Frank tracked down a bug in the GDL XML output. I fixed it and the fix will get into Hotfix 2. More exactly, any version after build 3467 in AC14 and in all later main AC versions of course.

Until these versions get published, you're left with Ben's idea using simple text output instead:(

Sorry for the hassle,
Zsolt Táskai
ArchiCAD Development - GDL Team
AC13, AC14 and upwards...
Frank Beister
Moderator
Does it affect the GDL webcontrol too?
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm
ztaskai
Graphisoft Alumni
Graphisoft Alumni
Yes. It uses the same add-on. I don't know the release and update schedule of v14 WebControl but I don't think this fix will trigger a new hotfix for webcontrol...
Zsolt Táskai
ArchiCAD Development - GDL Team
AC13, AC14 and upwards...
Frank Beister
Moderator


That's the environment I need it for. Writing values out of an object in webcontrol.
bim author since 1994 | bim manager since 2018 | author of selfGDL.de | openGDL | skewed archicad user hall of fame | author of bim-all-doors.gsm