ZZeman94 |
|
| Ecco qui... dopo aver imparato un po come usare le funzioni delle stringhe ho creato questa piccola UDF che può servire alla gestione dei file XML. L'ho fatto per di più per allenamento , infatti le funzioni non sono troppo lunghe e difficili... Eccovi il source: CODICE ; #INDEX# ======================================================================================================================= ; Title .........: ; AutoIt Version : 3.3.7.20++ ; Description ...: Functions that assist with file *.xml management. ; Author(s) .....: ZZeman94 ; ===============================================================================================================================
; #CURRENT# ===================================================================================================================== ;_XMLReadTag ;_XMLWriteBtwTag ;_XMLCreate ;_XMLRead ;_XMLReturnTag ; ===============================================================================================================================
; #FUNCTION# ==================================================================================================================== ; Name...........: _XMLReadTag ; Description ...: Returns the string between two tags. ; Syntax.........: _XMLReadTag ($name,$line,$tag1,$tag2) ; Parameters ....: $name - The name of the file ; $line - The line to read. ; $tag1 - The first tag. ; $tag2 - The second tag. ; Return values .: The string between the tags ; Author ........: ZZeman94 (www.autoit.forumcommunity.net) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: www.autoit.forumcommunity.net ; Example .......: No ; =============================================================================================================================== Func _XMLReadTag ($name,$line,$tag1,$tag2) $read=FileReadLine($name,$line) $remplace=StringReplace($read,$tag1,"") $string=StringReplace($remplace,$tag2,"") Return $string EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _XMLWriteBtwTag ; Description ...: Write a line with specified tags and string between tags ; Syntax.........: _XMLWriteBtwTag ($file,$tag1,$tag2,$value) ; Parameters ....: $file - The name of the file ; $tag1 - The first tag. ; $tag2 - The second tag. ; $value - The string between the tag ; Return values .: ; Author ........: ZZeman94 (www.autoit.forumcommunity.net) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: www.autoit.forumcommunity.net ; Example .......: No ; =============================================================================================================================== Func _XMLWriteBtwTag ($file,$tag1,$tag2,$value) FileWriteLine ($file,$tag1&$value&$tag2) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _XMLCreate ; Description ...: Create a new file *.xml ; Syntax.........: _XMLCreate ($name,$version) ; Parameters ....: $name - The name of the file ; $version - The version of the xml language (example......: <?xml version="1.0"?>) ; Return values .: ; Author ........: ZZeman94 (www.autoit.forumcommunity.net) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: www.autoit.forumcommunity.net ; Example .......: No ; =============================================================================================================================== Func _XMLCreate ($name,$version) FileWrite($name,"<?xml version="&$version&"?>") EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _XMLRead ; Description ...: Read a file *.xml ; Syntax.........: _XMLRead ($name,$count) ; Parameters ....: $name - The name of the file ; $count - The number of characters to read (if $count=0 then it will read all document ; Return values .: ; Author ........: ZZeman94 (www.autoit.forumcommunity.net) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: www.autoit.forumcommunity.net ; Example .......: No ; =============================================================================================================================== Func _XMLRead ($name,$count) If $count=0 Then FileRead($name) Else FileRead($name,$count) EndIf EndFunc ; #FUNCTION# ==================================================================================================================== ; Name...........: _XMLReturnTag ; Description ...: Return the tags of a line from a file. ; Syntax.........: _XMLReturnTag ($file,$string,$line) ; Parameters ....: $file - The name of the file ; $string - The string between the tags ; $line - The line of the file for to read the tags ; Return values .: ; Author ........: ZZeman94 (www.autoit.forumcommunity.net) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: www.autoit.forumcommunity.net ; Example .......: No ; =============================================================================================================================== Func _XMLReturnTag ($file,$string,$line) $name=FileReadLine($file,$line) $string=StringReplace($name,$string,"") Return $string EndFunc
|
| |