Wie üblich habe ich ohne konkrete Anwendung mit einem Beispiel herum gespielt. Nun habe ich zwei Merkwürdigkeiten die ich mir nicht erklären kann - in Zeile 12 ind in Zeile 92.
Die Forensuche war auch nicht ergiebig. Das kann aber auch daran liegen, dass ich noch nicht die richtigen Suchbegriffe bei dem Thema kenne.
Wer das Rätsel als erster löst wird in mein Nachtgebet mit aufgenommen.

edit : auf EnableExplicit getrimmt und Zeilennummern angepasst
Code: Alles auswählen
EnableExplicit
Define XML.s, *node, *MainNode, i, Event
#Window = 0
#TreeGadget = 0
#XML = 0
XML + "<!-- Kommentar Text -->" ; #PB_XML_Comment
; - kann mittels GetXMLNodeText() gelesen werden
;XML + "<![CDATA[Inhalt]]>" ; #PB_XML_CData <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< was stimmt hier nicht ?
; - Inhalt wird nicht vom Parser interpretiert, daher kann er zum Beispiel 'unescaped' "<" and ">" Zeichen enthalten.
XML + "<!DOCTYPE name SYSTEM 'external dtd uri'>" ; #PB_XML_DTD
; - da die PB-Bibliothek keinen gültigkeitsüberprüfenden Parser verwendet werden diese Deklarationen derzeit beim Parsen eines Dokuments ignoriert.
XML + "<?php If (...) ... ?>" ; #PB_XML_Instruction
; - repräsentiert eine Verarbeitungsanweisung welche dafür gedacht sind, von der Ziel-Applikation interpretiert/ausgeführt zu werden.
; Sie haben einen Namen, um den Inhalt der Anweisung zu spezifieren, und die Anweisungsdaten, auf welche mittels GetXMLNodeText() zugegriffen werden kann.
XML + "<test>" ; #PB_XML_Root
XML + " <pmaier>" ; ab hier #PB_XML_Normal
XML + " <Pers-Nr>142</Pers-Nr>"
XML + " <Name>Peter Maier</Name>"
XML + " </pmaier>"
XML + " <tschulz>"
XML + " <Pers-Nr id='02'>143</Pers-Nr>"
XML + " <Name ehemals='Weber'>Tina Schulz</Name>"
XML + " </tschulz>"
XML + " <aushilfe>"
XML + " <Pers-Nr>900</Pers-Nr>"
XML + " <Name></Name>"
XML + " </aushilfe>"
XML + " <gast Fremdfirma='Lieferant'>"
XML + " <Pers-Nr>999</Pers-Nr>"
XML + " <Firma></Firma>"
XML + " </gast>"
XML + "</test>"
Procedure FillTree(*CurrentNode, CurrentSublevel)
Protected Text$, i, *ChildNode
; Ignore anything except normal nodes. See the manual for
; XMLNodeType() for an explanation of the other node types.
;
If XMLNodeType(*CurrentNode) = #PB_XML_Normal
If ExamineXMLAttributes(*CurrentNode)
Text$ = GetXMLNodeName(*CurrentNode) + " : "
Text$ + GetXMLNodeText(*CurrentNode)
i=0
While NextXMLAttribute(*CurrentNode)
i+1 : If i = 1 : Text$ + " ( " : EndIf
Text$ + XMLAttributeName(*CurrentNode) + "=" + Chr(34) + XMLAttributeValue(*CurrentNode) + Chr(34) + " "
Wend
If i : Text$ + ") " : EndIf
EndIf
AddGadgetItem(#TreeGadget, -1, Text$, 0, CurrentSublevel)
; Now get the first child node (if any)
;
*ChildNode = ChildXMLNode(*CurrentNode)
; Loop through all available child nodes and call this procedure again
;
While *ChildNode <> 0
FillTree(*ChildNode, CurrentSublevel + 1)
*ChildNode = NextXMLNode(*ChildNode)
Wend
EndIf
EndProcedure
CatchXML(#XML, @XML, Len(XML))
If XMLStatus(#XML) = #PB_XML_Success ; Parser meldet keinen Fehler
*node = RootXMLNode(#XML)
Debug XMLChildCount(*node) ; sollte doch nur 1 Child sein - nämlich "<test>" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< liefert 4
*node = MainXMLNode(#XML)
Debug XMLChildCount(*node) ; 4 Childs von "<test>"
If OpenWindow(#Window, 0, 0, 500, 500, "XML Example", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
TreeGadget(#TreeGadget, 10, 10, 480, 480)
; Get the main XML node, and call the FillTree() procedure with it
*MainNode = MainXMLNode(#XML)
If *MainNode
FillTree(*MainNode, 0)
EndIf
; Expand all nodes for a nicer view
For i = 0 To CountGadgetItems(#TreeGadget) - 1
SetGadgetItemState(#TreeGadget, i, #PB_Tree_Expanded)
Next i
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
EndIf