AutoIT의 XML 구문 분석

Msxml2.DOMDocument를 사용한 AutoIT의 XML 구문 분석

C05348A3-9AB8-42C9-A6E0-81DB3AC59FEB
           
<results>
	<status>OK</status>
	<url>
http://technotes.videreresearch.com/autoit-sample-code
</url>
	<language>english</language>
	<text>
AutoIT Code Sample - Adding a shortcut in the user's Windows Startup folder in order to auto-start an AutoIT application every time a user logs-on to Windows. This script assumes that there is a checkbox defined on your Form, and will dynamically create or delete the shortcut on the check or uncheck event. ... While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 ;Do something Case $Checkbox1 If BitAND(GUICtrlRead($Checkbox1), $BN_CLICKED) = $BN_CLICKED Then If _GUICtrlButton_GetCheck($Checkbox1) Then ConsoleWrite("Checkbox checked... " & @CRLF) If Not FileExists(@StartupDir & "\linkName.lnk") Then FileCreateShortcut(@ScriptFullPath, @StartupDir & "\linkName.lnk", @ScriptDir, "", "AutoIT Script Description") EndIf Else ConsoleWrite("Checkbox unchecked... " & @CRLF) If FileExists(@StartupDir & "\linkName.lnk") Then You may also want to check for the presence of the shortcut when starting the application in order to properly display the state of the checkbox to the user. ... If FileExists(@StartupDir & "\linkName.lnk") Then _GUICtrlButton_SetCheck($Checkbox1) EndIf
</text>
	<keywords>
		<keyword>
			<text>AutoIT Code Sample</text>
			<relevance>0.990765</relevance>
		</keyword>
		<keyword>
			<text>AutoIT Script Description</text>
			<relevance>0.885643</relevance>
		</keyword>
		<keyword>
...
</keyword>
		<keyword>
			<text>nMsg</text>
			<relevance>0.432048</relevance>
		</keyword>
	</keywords>
</results>

다음은 Msxml2.DOMDocument.3.0을 사용하여 이 XML 파일을 구문 분석하는 데 사용되는 AutoIT 코드 샘플입니다.

;===============================================================================
; Description:		XML Parsing in AutoIT using Msxml2.DOMDocument
; Author(s):		Videre Research, LLC - http://videreresearch.com
;===============================================================================
 
$feed = "http://url.to.xml.file/"
$oOXml = _XmlFileLoad ($feed)
$oXMLRoot = $oOXml.documentElement
$content = ""
 
$oXmlroot = $oOXml.documentElement
 
$objElement = $oXmlroot.getElementsByTagName("language")
If IsObj($objElement) Then ConsoleWrite($objElement(0).childNodes(0).nodeValue &@crlf)
;For $oXmlNode In $objElement
	;ConsoleWrite($oXmlNode.nodename & " - "  & $oXmlNode.text &@crlf)
;Next
 
$objElement = $oXmlroot.getElementsByTagName("text")
If IsObj($objElement) Then ConsoleWrite($objElement(0).childNodes(0).nodeValue &@crlf)
;For $oXmlNode In $objElement
	;ConsoleWrite($oXmlNode.nodename & " - "  & $oXmlNode.text &@crlf)
;Next
 
$objElement = $oXmlroot.getElementsByTagName("keyword")
For $oXmlNode In $objElement
	;ConsoleWrite($oXmlNode.nodename & " - "  & $oXmlNode.text &@crlf)
	For $oXmlNodeD In $oXmlNode.childNodes
		;ConsoleWrite($oXmlNodeD.nodename & " - "  & $oXmlNodeD.text &@crlf)
		Select
		Case $oXmlnodeD.nodename = "text"
			ConsoleWrite($oXmlnodeD.text &":"&@crlf)
		Case $oXmlnodeD.nodename = "relevance"
			ConsoleWrite($oXmlnodeD.text &@crlf)
		EndSelect
	Next
 
Next
 
 
 
;===============================================================================
; Function Name:	 _XmlFileLoad
; Description:		Load and parse the XML file
; Parameters:		$strFile	XML file to load
; Syntax:			_XmlBuildTree($objXml,$treeview)
; Author(s):		Stephen Podhajecki 
; Returns:			Object handle on success
;					0 on failure and sets error to parser error.
;===============================================================================
Func _XmlFileLoad($strXmlFile)
	$strFile = $strXmlFile
	;if not isobj($oXml) then
	$oXml = ObjCreate("Msxml2.DOMDocument.3.0")
	$oXml.async=0
	$oXml.load ($strFile)
	If $oXml.parseError.errorCode <> 0 Then
		MsgBox(4096, "Error", "Error opening specified file: " & $strFile & @CRLF & $oXml.parseError.reason)
		SetError($oXml.parseError.errorCode)
		Return 0
	EndIf
	Return $oXml
EndFunc   ;==>_XmlFileLoad
댓글을 게시했습니다: 0