XMLGUI ~ JSON
Hallo Leute,
ich möchte euch ein Skript vorstellen, mit diesem ihr eure GUI in XML (bzw. JSON) gestalten und bei eurem AutoIt Skript laden könnt.
Das Projekt habe ich für mich geschrieben, damit ich mich nicht dem Form Editor und dem Layout beschäftigen muss.
Hinweis
Der Umfang des Projekts ist noch überschaubar viele Funktionen sind noch nicht vorhanden. Sollte Interesse bestehen würde ich das Projekt fortführen und erweitern. Evtl. haben andere Interesse mitzumachen. Ich habe den aktuellen Stand hochgeladen bin mir bewusst das noch vieles fehlt, brauchte es für mich aber in keinem größeren Umfang.
Wie funktionierst?
Beispiel an einem Skript mit XMLGUI
ExampleXML.au3
#include <XML-GUI.au3> ;Skript importieren
;$App = _XMLGUI_CreateApp("Test.json")
;$App = _XMLGUI_CreateApp("Test.xml")
;$App = _XMLGUI_CreateApp("ExampleApp.xml")
$App = _XMLGUI_CreateApp("ExampleApp.json") ; _XMLGUI_CreateApp(FilenameXML|FilenameJSON) - Erstellt die Anwendung, Lädt XML oder JSON Datei
;_XMLGUI_ExportXMLFile($App,"Export.xml") ; Speichert die Anwendung als XML Datei
;_XMLGUI_ExportJSONFile($App,"Export.json") ; Speichert die Anwendung als JSON Datei
$Win = _XMLGUI_Query($App,"win")
$WinTitle = _XMLGUI_Query($App,$Win,"title")
; _XMLGUI_Query(App,Id|Node,Key,Value)
; App = Oberster Node => Normalerweise Rückgabe von _XMLGUI_CreateApp
; Id = Eingetragene Id im XML Code oder Rückgabe von _XMLGUI_Query(App,Id)
; Key = Wenn Null wird Inhalt geändert sonst das entsprechende Attribut
; Value = Wenn Default wird das Attribut oder Inhalt ausgegeben sonst verändert
func win_exit()
_XMLGUI_Query($App,$Win,"exit","true")
EndFunc
func btn_click()
MsgBox(0,$WinTitle,_XMLGUI_Query($App,"txt",null))
_XMLGUI_Query($App,"txt",null,"Ich bin sichtbar")
_XMLGUI_Query($App,"txt","show","true")
EndFunc
do
sleep(100)
until _XMLGUI_Query($app,$Win,"exit") = "true"
_XMLGUI_CloseApp($app) ; _XMLGUI_CloseApp(App)- Schließt die Anwendung
Alles anzeigen
ExampleApp.xml
<app>
<window id="win" width="800" height="600" show="true" title="Beispiel" onexit="win_exit">
<layout>
<tabview>
<tab title="Button,Inputs,CheckBox,Radio">
<layout padding="10">
<layout type="gridy" padding="10">
<input>Eingabe</input>
<input type="progress" pos="50"/>
<input type="slider" pos="50"/>
<input type="number"/>
<input type="date"/>
</layout>
<layout type="gridy" padding="10">
<checkbox checked="true">Auswahlbox</checkbox>
<checkbox>Auswahlbox</checkbox>
<group title="Radio">
<radiobox>Ja</radiobox>
<radiobox>Nein</radiobox>
</group>
<combolist>
<value>Lorem</value>
<value>Ipsum</value>
</combolist>
</layout>
</layout>
</tab>
<tab title="Lists">
<layout padding="10" type="gridy">
<button onclick="btn_click">Klick Mich</button>
<text id="txt" show="false">Mich sieht man noch nicht</text>
<treeview>
<value>Lorem</value>
<value>Ipsum</value>
</treeview>
<listview columns="2">
<value>Lorem</value>
<value>Ipsum</value>
</listview>
<list>
<value>Lorem</value>
<value selected="true">Ipsum</value>
<value>Lorem</value>
<value>Ipsum</value>
</list>
</layout>
</tab>
<tab title="Image">
<layout padding="10">
<image src="Bild.jpg"></image>
</layout>
</tab>
<tab title="Text">
<layout padding="10">
<text>Lorem Ipsum</text>
<group title="Gruppe">
<text>Lorem Ipsum</text>
</group>
<textarea>Textfeld</textarea>
</layout>
</tab>
</tabview>
</layout>
</window>
</app>
Alles anzeigen
ExampleApp.json
{
"class":"app",
"children":[
{
"class":"window",
"id":"win",
"attrs":{
"width":"800",
"height":"600",
"title":"Beispiel",
"show":"true",
"onexit":"win_exit"
},
"children":[
{
"class":"layout",
"children":[
{
"class":"button",
"value":"Klick Mich",
"attrs":{
"onclick":"btn_click"
}
},
{
"class":"text",
"id":"txt",
"value":"Text nicht sichtbar",
"attrs":{
"show":"false"
}
}
]
}
]
}
],
"attrs":{
"a":"10",
"b":"20"
}
}
Alles anzeigen
ExampleApp.xml in JSON umgewandelt => Test.json (Datei zu groß um hier zu posten)
Die XMLGUI.au3
#include <GUIConstantsEx.au3>
#include <GUIComboBoxEx.au3>
#include <GUIListBox.au3>
global $_XMLGUI_DLL
func _XMLGUI_Query($App,$Id,$Key = Default,$Value = Default)
if IsString($Id) then
$Node = _XMLGUI_GetNodeById($App,$Id)
Else
$Node = $Id
endif
if $Key = Default Then
Return $Node
elseif $Key = Null Then
if $Value = Default then
switch _XMLGUI_GetClass($Node)
case "button","text","input"
$ChangedValue = GUICtrlRead(_XMLGUI_GetToken($Node))
_XMLGUI_SetValue($Node,$ChangedValue)
return $ChangedValue
EndSwitch
return _XMLGUI_GetValue($Node)
endif
_XMLGUI_SetValue($Node,$Value)
switch _XMLGUI_GetClass($Node)
case "button","text","input"
GUICtrlSetData(_XMLGUI_GetToken($Node),$Value)
EndSwitch
return $Node
EndIf
if $Value = Default then
switch _XMLGUI_GetClass($Node)
case "input"
switch $Key
case "text"
$ChangedValue = GUICtrlRead(_XMLGUI_GetToken($Node))
_XMLGUI_SetAttr($Node,$Key,$ChangedValue)
return $ChangedValue
EndSwitch
EndSwitch
Return _XMLGUI_GetAttr($Node,$Key)
EndIf
_XMLGUI_SetAttr($Node,$Key,$Value)
$Class= _XMLGUI_GetClass($Node)
if $Key = "show" then
if $Class = "window" Then
if $Value = "true" Then
GUISetState(@SW_SHOW,_XMLGUI_GetToken($Node))
Else
GUISetState(@SW_HIDE,_XMLGUI_GetToken($Node))
endif
Else
_XMLGUI_ToggleView($Node)
endif
endif
switch $Class
case "window"
switch $Key
case "exit"
GUIDelete(_XMLGUI_GetToken($Node))
EndSwitch
case "button","text","input"
switch $Key
case "text"
GUICtrlSetData(_XMLGUI_GetToken($Node),$Value)
EndSwitch
EndSwitch
EndFunc
func _XMLGUI_CloseApp($App)
_XMLGUI_RemoveNode($App)
_XMLGUI_Close()
EndFunc
func _XMLGUI_CreateApp($Path)
_XMLGUI_Open()
switch StringRegExpReplace($Path, "^.*\.", "")
Case "xml"
$App = _XMLGUI_ImportXMLFile($Path)
case "json"
$App = _XMLGUI_ImportJSONFile($Path)
case Else
_XMLGUI_Close()
return msgbox(0,"","No Correct Type")
EndSwitch
_XMLGUI_RenderChildren($App)
return $App
EndFunc
func _XMLGUI_RenderChildren($Object)
$Len = _XMLGUI_GetChildrenLen($Object)
for $Index = 0 to $Len-1
_XMLGUI_RenderObject(_XMLGUI_GetChildrenByIndex($Object,$Index),$Index)
Next
EndFunc
func _XMLGUI_RenderObject($Object,$Index = -1)
switch _XMLGUI_GetClass($Object)
case "window"
$Handle = GUICreate(_XMLGUI_GetAttr($Object,"title"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
Opt("GUIOnEventMode", 1)
if not _XMLGUI_GetAttr($Object,"onexit") = "" then
GUISetOnEvent($GUI_EVENT_CLOSE,_XMLGUI_GetAttr($Object,"onexit"),$Handle)
endif
if _XMLGUI_GetAttr($Object,"show") ="true" Then
GUISetState(@SW_SHOW,$Handle)
endif
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_RenderChildren($Object)
case "text"
$Handle = GUICtrlCreateLabel(_XMLGUI_GetValue($Object),_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_ToggleView($Object,True)
case "textarea"
$Handle = GUICtrlCreateEdit(_XMLGUI_GetValue($Object),_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_ToggleView($Object,True)
case "checkbox"
$Handle = GUICtrlCreateCheckbox(_XMLGUI_GetValue($Object),_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_ToggleView($Object,True)
_XMLGUI_ToggleChecked($Object,True)
case "input"
switch _XMLGUI_GetAttr($Object,"type")
case "slider"
$Handle = GUICtrlCreateSlider(_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
GUICtrlSetData($Handle,_XMLGUI_GetAttr($Object,"pos"))
case "date"
$Handle = GUICtrlCreateDate(_XMLGUI_GetAttr($Object,"text"),_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
case "progress"
$Handle = GUICtrlCreateProgress(_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
GUICtrlSetData($Handle,_XMLGUI_GetAttr($Object,"pos"))
case else
$Handle = GUICtrlCreateInput(_XMLGUI_GetAttr($Object,"text"),_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
if _XMLGUI_GetAttr($Object,"type") = "number" Then
GUICtrlCreateUpdown($Handle)
EndIf
EndSwitch
_XMLGUI_SetToken($Object,$Handle)
case "image"
$Handle = GUICtrlCreatePic(_XMLGUI_GetAttr($Object,"src"),_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_ToggleView($Object,True)
case "button"
$Handle = GUICtrlCreateButton(_XMLGUI_GetValue($Object),_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
if not _XMLGUI_GetAttr($Object,"onclick") = "" then
GUICtrlSetOnEvent($Handle,_XMLGUI_GetAttr($Object,"onclick"))
endif
_XMLGUI_ToggleView($Object,True)
case "list"
$Handle = GUICtrlCreateList("",_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_RenderChildren($Object)
if not _XMLGUI_GetAttr($Object,"selected") = "" Then
_GUICtrlListBox_SetCurSel($Handle,Int(_XMLGUI_GetAttr($Object,"selected")))
endif
case "combolist"
$Handle = GUICtrlCreateCombo("",_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_RenderChildren($Object)
_XMLGUI_ToggleView($Object,True)
case "group"
$Handle = GUICtrlCreateGroup(_XMLGUI_GetAttr($Object,"title"),_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
if not _XMLGUI_GetAttr($Object,"title") = "" then
_XMLGUI_SetAttr($Object,"margin",16)
endif
_XMLGUI_Layout($Object)
case "tabview"
$Handle = GUICtrlCreateTab(_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_SetAttr($Object,"type","take")
_XMLGUI_SetAttr($Object,"margin",30)
_XMLGUI_Layout($Object)
GUICtrlCreateTabItem("")
case "tab"
$Handle = GUICtrlCreateTabItem(_XMLGUI_GetAttr($Object,"title"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_RenderChildren($Object)
case "radiobox"
$Handle = GUICtrlCreateRadio(_XMLGUI_GetValue($Object),_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_ToggleView($Object,True)
_XMLGUI_ToggleChecked($Object,True)
case "listview"
$Handle = GUICtrlCreateListView("|",_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_RenderChildren($Object)
case "treeview"
$Handle = GUICtrlCreateTreeView(_XMLGUI_GetAttr($Object,"left"),_XMLGUI_GetAttr($Object,"top"),_XMLGUI_GetAttr($Object,"width"),_XMLGUI_GetAttr($Object,"height"))
_XMLGUI_SetToken($Object,$Handle)
_XMLGUI_RenderChildren($Object)
case "layout"
_XMLGUI_Layout($Object)
case "value"
$Parent = _XMLGUI_GetParent($Object)
switch _XMLGUI_GetClass($Parent)
case "list"
_GUICtrlListBox_AddString(_XMLGUI_GetToken($Parent),_XMLGUI_GetValue($Object))
if _XMLGUI_GetAttr($Object,"selected") = "true" then
_XMLGUI_SetAttr($Parent,"selected",$Index)
endif
case "combolist"
GUICtrlSetData(_XMLGUI_GetToken($Parent),_XMLGUI_GetValue($Object))
case "listview"
GUICtrlCreateListViewItem(_XMLGUI_GetValue($Object),_XMLGUI_GetToken($Parent))
case "treeview"
GUICtrlCreateTreeViewItem(_XMLGUI_GetValue($Object),_XMLGUI_GetToken($Parent))
EndSwitch
EndSwitch
EndFunc
func _XMLGUI_ToggleView($Object,$Created = False)
if _XMLGUI_GetAttr($Object,"show") = "false" then
GUICtrlSetState(_XMLGUI_GetToken($Object),$GUI_HIDE)
Else
GUICtrlSetState(_XMLGUI_GetToken($Object),$GUI_SHOW)
endif
EndFunc
func _XMLGUI_ToggleChecked($Object,$Created = False)
if _XMLGUI_GetAttr($Object,"checked") = "true" then
GUICtrlSetState(_XMLGUI_GetToken($Object),$GUI_CHECKED)
Else
GUICtrlSetState(_XMLGUI_GetToken($Object),$GUI_UNCHECKED)
_XMLGUI_SetAttr($Object,"checked","false")
endif
EndFunc
func _XMLGUI_Layout($Object)
$Len = _XMLGUI_GetChildrenLen($Object)
$Type = _XMLGUI_GetAttr($Object,"type")
$Left = _XMLGUI_GetAttr($Object,"left")
$Top = _XMLGUI_GetAttr($Object,"top")
$Padding = _XMLGUI_GetAttr($Object,"padding")
$PaddingTop = _XMLGUI_GetAttr($Object,"padding-top")
$PaddingLeft = _XMLGUI_GetAttr($Object,"padding-left")
$PaddingBottom = _XMLGUI_GetAttr($Object,"padding-bottom")
$PaddingRight = _XMLGUI_GetAttr($Object,"padding-right")
$Margin = _XMLGUI_GetAttr($Object,"margin")
$Width = _XMLGUI_GetAttr($Object,"width")
$Height = _XMLGUI_GetAttr($Object,"height")
if $Width = 0 or $Height = 0 Then
$Parent = _XMLGUI_GetParent($Object)
if not $Parent = 0 Then
$Left = _XMLGUI_GetAttr($Parent,"left")
$Top = _XMLGUI_GetAttr($Parent,"top")
$Width = _XMLGUI_GetAttr($Parent,"width")
$Height = _XMLGUI_GetAttr($Parent,"height")
endif
EndIf
if $Margin > 0 Then
$Left += $Margin
$Top += $Margin
$Width -= $Margin*2
$Height -= $Margin*2
endif
switch $Type
case "take"
case "gridy"
$Height /= $Len
$MaxHeight = _XMLGUI_GetAttr($Object,"maxheight")
if not $MaxHeight = 0 and $Height > $MaxHeight Then
$Height = $MaxHeight
EndIf
case "gridx"
ContinueCase
case else
$Width /= $Len
EndSwitch
for $Index = 0 to $Len-1
$Child = _XMLGUI_GetChildrenByIndex($Object,$Index)
_XMLGUI_SetAttr($Child,"left",$Left+$Padding+$PaddingLeft)
_XMLGUI_SetAttr($Child,"top",$Top+$Padding+$PaddingTop)
_XMLGUI_SetAttr($Child,"width",$Width-$Padding*2-$PaddingLeft-$PaddingRight)
_XMLGUI_SetAttr($Child,"height",$Height-$Padding*2-$PaddingTop-$PaddingBottom)
switch $Type
case "take"
case "gridy"
$Top += $Height
case "gridx"
ContinueCase
case else
$Left += $Width
EndSwitch
Next
_XMLGUI_RenderChildren($Object)
EndFunc
func _XMLGUI_Open()
$_XMLGUI_DLL = DllOpen("XML-GUI.dll")
EndFunc
func _XMLGUI_AddNode($Parent,$Class = "",$Id = "",$Value = "")
$Result = Dllcall($_XMLGUI_DLL,"int","AddNode","int",$Parent,"wstr",$Class,"wstr",$Id,"wstr",$Value)
return $Result[0]
EndFunc
func _XMLGUI_GetChildrenByIndex($This,$Index)
$Result = Dllcall($_XMLGUI_DLL,"int","GetChildrenByIndex","int",$This,"int",$Index)
return $Result[0]
EndFunc
func _XMLGUI_GetChildrenLen($This)
$Result = Dllcall($_XMLGUI_DLL,"int","GetChildrenLen","int",$This)
return $Result[0]
EndFunc
func _XMLGUI_RemoveNode($This)
$Result = Dllcall($_XMLGUI_DLL,"int","RemoveNode","int",$This,"int",0)
return $Result[0]
EndFunc
func _XMLGUI_ImportXML($String)
$Result = Dllcall($_XMLGUI_DLL,"int","ImportXML","wstr",$String)
return $Result[0]
EndFunc
func _XMLGUI_ImportXMLFile($Filename)
$Result = Dllcall($_XMLGUI_DLL,"int","ImportXMLFile","wstr",$Filename)
return $Result[0]
EndFunc
func _XMLGUI_ExportXMLFile($This,$Filename)
$Result = Dllcall($_XMLGUI_DLL,"int","ExportXMLFile","int",$This,"wstr",$Filename)
return $Result[0]
EndFunc
func _XMLGUI_ExportJSONFile($This,$Filename)
$Result = Dllcall($_XMLGUI_DLL,"int","ExportJSONFile","int",$This,"wstr",$Filename)
return $Result[0]
EndFunc
func _XMLGUI_ImportJSONFile($Filename)
$Result = Dllcall($_XMLGUI_DLL,"int","ImportJSONFile","wstr",$Filename)
return $Result[0]
EndFunc
func _XMLGUI_SetValue($This,$Value)
$Result = Dllcall($_XMLGUI_DLL,"int","SetValue","int",$This,"wstr",$Value)
return $Result[0]
EndFunc
func _XMLGUI_GetValue($This)
$Result = Dllcall($_XMLGUI_DLL,"wstr","GetValue","int",$This)
return $Result[0]
EndFunc
func _XMLGUI_SetId($This,$Id)
$Result = Dllcall($_XMLGUI_DLL,"int","SetId","int",$This,"wstr",$Id)
return $Result[0]
EndFunc
func _XMLGUI_GetId($This)
$Result = Dllcall($_XMLGUI_DLL,"wstr","GetId","int",$This)
return $Result[0]
EndFunc
func _XMLGUI_SetClass($This,$Class)
$Result = Dllcall($_XMLGUI_DLL,"int","SetClass","int",$This,"wstr",$Class)
return $Result[0]
EndFunc
func _XMLGUI_GetClass($This)
$Result = Dllcall($_XMLGUI_DLL,"wstr","GetClass","int",$This)
return $Result[0]
EndFunc
func _XMLGUI_SetToken($This,$Token)
$Result = Dllcall($_XMLGUI_DLL,"int","SetToken","int",$This,"int",$Token)
return $Result[0]
EndFunc
func _XMLGUI_GetToken($This)
$Result = Dllcall($_XMLGUI_DLL,"int","GetToken","int",$This)
return $Result[0]
EndFunc
func _XMLGUI_SetAttr($This,$Name,$Value)
$Result = Dllcall($_XMLGUI_DLL,"int","SetAttr","int",$This,"wstr",$Name,"wstr",$Value)
return $Result[0]
EndFunc
func _XMLGUI_GetAttr($This,$Name)
$Result = Dllcall($_XMLGUI_DLL,"wstr","GetAttr","int",$This,"wstr",$Name)
return $Result[0]
EndFunc
func _XMLGUI_GetParent($This)
$Result = Dllcall($_XMLGUI_DLL,"int","GetParent","int",$This)
return $Result[0]
EndFunc
func _XMLGUI_GetNodeById($Current,$Id)
$Result = Dllcall($_XMLGUI_DLL,"int","GetNodeById","int",$Current,"wstr",$Id)
return $Result[0]
EndFunc
func _XMLGUI_Close()
dllclose($_XMLGUI_DLL)
EndFunc
Alles anzeigen
XML-GUI.dll in PureBasic
EnableExplicit
Structure Node
Id.s
Class.s
Value.s
Token.i
Map Attrs.s()
List *Children()
*Parent.Node
EndStructure
Procedure FindChildren(*This.Node,*Child.Node)
If *This = 0
ProcedureReturn #False
EndIf
ForEach *This\Children()
If *This\Children() = *Child
ProcedureReturn #True
EndIf
Next
ProcedureReturn #False
EndProcedure
ProcedureDLL AddNode(*Parent.Node,Class.s,Id.s,Value.s)
Define *This.Node = AllocateStructure(Node)
With *This.Node
\Id = Id
\Class = Class
\Value = Value
\Parent = *Parent
EndWith
If Not *Parent = 0
AddElement(*Parent\Children())
*Parent\Children() = *This
EndIf
ProcedureReturn *This
EndProcedure
Procedure ExtractXML(*XMLNode,*Node.Node)
Define *NextXMLNode, AttrName.s, AttrValue.s
If *Node = 0
*Node = AddNode(0,"","","")
EndIf
With *Node
\Class = GetXMLNodeName(*XMLNode)
\Value = GetXMLNodeText(*XMLNode)
ExamineXMLAttributes(*XMLNode)
While NextXMLAttribute(*XMLNode)
AttrName = XMLAttributeName(*XMLNode)
AttrValue = XMLAttributeValue(*XMLNode)
\Attrs(AttrName) = AttrValue
If AttrName = "id"
\Id = AttrValue
EndIf
Wend
EndWith
*NextXMLNode = ChildXMLNode(*XMLNode)
If *NextXMLNode
ExtractXML(*NextXMLNode,AddNode(*Node,"","",""))
Repeat
*NextXMLNode = NextXMLNode(*NextXMLNode)
If *NextXMLNode
ExtractXML(*NextXMLNode,AddNode(*Node,"","",""))
Else
Break
EndIf
ForEver
EndIf
ProcedureReturn *Node
EndProcedure
Procedure ExtractJSON(*JSONNode,*Node.Node)
Define *JSONNext, AttrName.s, AttrValue.s, i.i
If *Node = 0
*Node = AddNode(0,"","","")
EndIf
ExamineJSONMembers(*JSONNode)
While NextJSONMember(*JSONNode)
AttrName = JSONMemberKey(*JSONNode)
*JSONNext = JSONMemberValue(*JSONNode)
Select JSONType(*JSONNext)
Case #PB_JSON_String
AttrValue = GetJSONString(*JSONNext)
Select AttrName
Case "id"
*Node\Id = AttrValue
Case "class"
*Node\Class = AttrValue
Case "value"
*Node\Value = AttrValue
Default
*Node\Attrs(AttrName) = AttrValue
EndSelect
Case #PB_JSON_Object
If AttrName = "attrs"
ExamineJSONMembers(*JSONNext)
While NextJSONMember(*JSONNext)
*Node\Attrs(JSONMemberKey(*JSONNext)) = GetJSONString(JSONMemberValue(*JSONNext))
Wend
EndIf
Case #PB_JSON_Array
If AttrName = "children"
For i = 0 To JSONArraySize(*JSONNext)-1
ExtractJSON(GetJSONElement(*JSONNext,i),AddNode(*Node,"","",""))
Next
EndIf
EndSelect
Wend
ProcedureReturn *Node
EndProcedure
Procedure ConstructXML(*XMLNode,*Node.Node)
Define *NextXMLNode
With *Node
*NextXMLNode = CreateXMLNode(*XMLNode,\Class)
If Not \Value = ""
SetXMLNodeText(*NextXMLNode,\Value)
EndIf
SetXMLAttribute(*NextXMLNode,"id",\Id)
ForEach \Attrs()
SetXMLAttribute(*NextXMLNode,MapKey(\Attrs()),\Attrs())
Next
ForEach \Children()
ConstructXML(*NextXMLNode,\Children())
Next
EndWith
EndProcedure
Procedure ConstructJSON(*JSONNode,*Node.Node)
Define *NextJSONNode, *Attrs, *Children
With *Node
*NextJSONNode = AddJSONMember(*JSONNode,"id")
SetJSONString(*NextJSONNode,\Id)
*NextJSONNode = AddJSONMember(*JSONNode,"class")
SetJSONString(*NextJSONNode,\Class)
If Not \Value = ""
*NextJSONNode = AddJSONMember(*JSONNode,"value")
SetJSONString(*NextJSONNode,\Value)
EndIf
If MapSize(\Attrs()) > 0
*NextJSONNode = AddJSONMember(*JSONNode,"attrs")
*Attrs = SetJSONObject(*NextJSONNode)
ForEach \Attrs()
SetJSONString(AddJSONMember(*Attrs,MapKey(\Attrs())),\Attrs())
Next
EndIf
If ListSize(\Children()) > 0
*NextJSONNode = AddJSONMember(*JSONNode,"children")
*Children = SetJSONArray(*NextJSONNode)
ForEach \Children()
ConstructJSON(SetJSONObject(AddJSONElement(*Children)),\Children())
Next
EndIf
EndWith
EndProcedure
ProcedureDLL ImportXML(String.s)
Define XML = ParseXML(#PB_Any,String)
ProcedureReturn ExtractXML(MainXMLNode(XML),0)
EndProcedure
ProcedureDLL ImportXMLFile(Filename.s)
Define XML = LoadXML(#PB_Any,Filename)
ProcedureReturn ExtractXML(MainXMLNode(XML),0)
EndProcedure
ProcedureDLL ImportJSONFile(Filename.s)
Define JSON = LoadJSON(#PB_Any,Filename)
ProcedureReturn ExtractJSON(JSONValue(JSON),0)
EndProcedure
ProcedureDLL ExportXMLFile(*This.Node,Filename.s)
Define XML = CreateXML(#PB_Any)
ConstructXML(RootXMLNode(XML),*This)
FormatXML(XML,#PB_XML_WindowsNewline | #PB_XML_ReFormat )
SaveXML(XML,Filename)
ProcedureReturn #True
EndProcedure
ProcedureDLL ExportJSONFile(*This.Node,Filename.s)
Define JSON = CreateJSON(#PB_Any)
ConstructJSON(SetJSONObject(JSONValue(JSON)),*This)
SaveJSON(JSON,Filename,#PB_JSON_PrettyPrint )
ProcedureReturn #True
EndProcedure
ProcedureDLL AddChildren(*This.Node,*Children.Node)
AddElement(*This\Children())
*This\Children() = *Children
*Children\Parent = *This
EndProcedure
ProcedureDLL GetNodeById(*Current.Node,Id.s)
Define *ResultNode
If *Current\Id = Id
ProcedureReturn *Current
EndIf
ForEach *Current\Children()
*ResultNode = GetNodeById(*Current\Children(),Id)
If *ResultNode
ProcedureReturn *ResultNode
EndIf
Next
EndProcedure
ProcedureDLL GetChildrenByIndex(*This.Node,Index.i)
SelectElement(*This\Children(),Index)
ProcedureReturn *This\Children()
EndProcedure
ProcedureDLL GetChildrenLen(*This.Node)
ProcedureReturn ListSize(*This\Children())
EndProcedure
ProcedureDLL RemoveNode(*This.Node, Depth.i)
ForEach *This\Children()
RemoveNode(*This\Children(),Depth + 1)
Next
If Depth = 0 And FindChildren(*This\Parent,*This)
DeleteElement(*This\Parent\Children(),1)
EndIf
FreeStructure(*This)
ProcedureReturn #True
EndProcedure
ProcedureDLL GetParent(*This.Node)
ProcedureReturn *This\Parent
EndProcedure
ProcedureDLL SetAttr(*This.Node,Name.s,Value.s)
*This\Attrs(Name) = Value
EndProcedure
ProcedureDLL.s GetAttr(*This.Node,Name.s)
If FindMapElement(*This\Attrs(),Name)
ProcedureReturn *This\Attrs()
EndIf
EndProcedure
ProcedureDLL SetValue(*This.Node,Value.s)
*This\Value = Value
EndProcedure
ProcedureDLL.s GetValue(*This.Node)
ProcedureReturn *This\Value
EndProcedure
ProcedureDLL SetId(*This.Node,Id.s)
*This\Id = Id
EndProcedure
ProcedureDLL.s GetId(*This.Node)
ProcedureReturn *This\Id
EndProcedure
ProcedureDLL SetClass(*This.Node,Class.s)
*This\Class = Class
EndProcedure
ProcedureDLL.s GetClass(*This.Node)
ProcedureReturn *This\Class
EndProcedure
ProcedureDLL SetToken(*This.Node,Token.i)
*This\Token = Token
EndProcedure
ProcedureDLL GetToken(*This.Node)
ProcedureReturn *This\Token
EndProcedure
Alles anzeigen
XML: Übersicht der Elemente und Attribute (Nicht alle Attribute funktionieren)
<app></app>
<window id="" width="" height="" show="true|false" title="" onexit=""></window>
<layout id="" left="" top="" width="" height="" show="true|false" type="gridx|gridy|take" padding="" paddng-right="" padding-left="" padding-bottom="" padding-top="" margin="" margin-right="" margin-left="" margin-bottom="" margin-top=""></layout>
<group id="" left="" top="" width="" height="" show="true|false" title="" type="gridx|gridy|take"></group>
<tabview id="" left="" top="" width="" height="" show="true|false" selected="">
<tab id="" title="" selected="true|false"></tab>
</tabview>
<list id="" left="" top="" width="" height="" show="true|false" selected="">
<value id="" selected="true|false">TEXT</value>
</list>
<listview id="" left="" top="" width="" height="" show="true|false" columns="" selected="">
<value id="" selected="true|false">TEXT</value>
</listview>
<treeview id="" left="" top="" width="" height="" show="true|false" selected="">
<value id="" selected="true|false">TEXT</value>
</treeview>
<text id="" left="" top="" width="" height="" show="true|false">TEXT</text>
<button id="" left="" top="" width="" height="" show="true|false" onclick="">TEXT</button>
<image id="" left="" top="" width="" height="" show="true|false" src=""></image>
<input id="" left="" top="" width="" height="" show="true|false" type="" pos="">TEXT</input>
<textarea id="" left="" top="" width="" height="" show="true|false">TEXT</textarea>
<checkbox id="" left="" top="" width="" height="" show="true|false" checked="true|false">TEXT</checkbox>
<radiobox id="" left="" top="" width="" height="" show="true|false" checked="true|false">TEXT</radiobox>
<combolist id="" left="" top="" width="" height="" show="true|false" selected="">
<value id="" selected="true|false">TEXT</value>
</combolist>
Alles anzeigen