LoadDomDocument
Ukázka načtení DOM dokumentu z XML souboru
Popis
Obsah načítaného XML souboru je nasledující<?xml version="1.0"?> <request> <method>GET</method> <path>/request</path> <query>param=value</query> <headers> <header name="Content-Type">text/plain</header> <header name="Accept">*/*</header> <header name="Cache-Control">no-cache</header> <header name="Host">localhost:8080</header> <header name="Accept-Encoding">gzip, deflate, br</header> <header name="Connection">keep-alive</header> <header name="Content-Length">12</header> </headers> <content>SGVsbG8gV29ybGQh</content> </request>Skript načte DOM dokument z XML souboru a vypíše všechny elementy "header"
declare function LoadBase64FromFile dll "ActualDocument" (string): string declare function DomCreateDocument dll "ScriptEx" (integer, string, string, integer): integer declare procedure DomFree dll "ScriptEx" (var integer) declare function DomGetIntegerProp dll "ScriptEx" (integer, string): integer declare function DomGetStringProp dll "ScriptEx" (integer, string): string declare procedure DomSetStringProp dll "ScriptEx" (integer, string, string) declare function DomItem dll "ScriptEx" (integer, integer): integer declare function DomGetElementsByTagName dll "ScriptEx" (integer, string): integer declare function DomGetAttribute dll "ScriptEx" (integer, string): string script LoadDomDocument(): boolean var Base64: string TheDocument: integer HeaderList: integer I: integer HeaderNode: integer HeaderName: string HeaderValueNode: integer HeaderValue: string begin Base64 := LoadBase64FromFile("c:\Sources\Temp\Request_formatted.xml") TheDocument := DomCreateDocument(0, "", "", 0) DomSetStringProp(TheDocument, "Base64", Base64) HeaderList := DomGetElementsByTagName(TheDocument, "header") for I := 0 to DomGetIntegerProp(HeaderList, "Length") - 1 do HeaderNode := DomItem(HeaderList, I) HeaderName := DomGetAttribute(HeaderNode, "name") HeaderValueNode := DomGetIntegerProp(HeaderNode, "FirstChild") HeaderValue := DomGetStringProp(HeaderValueNode, "NodeValue") write(HeaderName + ": " + HeaderValue) end DomFree(TheDocument) result := true end