eltorro Posted February 24, 2006 Author Posted February 24, 2006 (edited) Steve, Isn't that one of the main reasons for using CDATA so that you don't need to escape everything (since the CDATA is not parsed)? Can you comment on the trouble using _XMLCreateCDATA? I reproduced the same outcome that Gary got trying to use it. thanks, Dale Here's a fix for the write part: ;=============================================================================== ; Function Name: _XMLCreateCDATA ; Description: Create a CDATA SECTION node directly under root. ; Parameters: $node name of node to create ; $data CDATA value ; Syntax: _XMLCreateCDATA($node,$data) ; Author(s): Stephen Podhajecki <gehossafats@netmdc.com> ; Returns: on error set error to 1 and returns -1 ; fixme, won't append to exisiting node. must create new node. ;=============================================================================== Func _XMLCreateCDATA($strNode, $strCDATA,$strNameSpc="") Local $objChild, $objNode While @error = 0 $objNode = $objDoc.createNode (1, $strNode, $strNameSpc) $objChild = $objDoc.createCDATASection ($strCDATA) $objNode.appendChild($objChild) $objDoc.documentElement.appendChild ($objNode) $objDoc.Save ($strFile) $objChild = "" Return WEnd ; _XMLError( "Failed to create CDATA Section: " & $strNode & @CRLF & $oMyError.windescription) _XMLError( "Failed to create CDATA Section: " & $strNode & @CRLF) SetError(1) Return -1 EndFunc ;==>_XMLCreateCDATA Here's the xml as loaded in SciTe <?xml version="1.0"?> <Snippet><hCode><![CDATA[; Include Version:1.52 (8 February 2006) #include-once ; ------------------------------------------------------------------------------ ; ; AutoIt Version: 3.0 ; Language: English ; Description: Functions that assist with color management. ; ; ------------------------------------------------------------------------------ ;=============================================================================== ; ; Description: Get the red component of a given color. ; Syntax: ]]></hCode></Snippet> I'm still working on the read. I think that the CDATASection is considered a child of the the node and may have to be referenced by it's index. Steve Edit: updated code. Edited February 24, 2006 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
eltorro Posted February 24, 2006 Author Posted February 24, 2006 Here is the read part: expandcollapse popup;=============================================================================== ; Function Name: _XMLGetValue ; Description: Get XML Fieldbased on XPath input from root node. ; Parameters: $path xml tree path from root node (root/child/child..) ; Syntax: _XMLGetValue($path) ; Author(s): Stephen Podhajecki <gehossafats@netmdc.com> ; Returns: array of fields text values -1 on failure ;=============================================================================== Func _XMLGetValue($strXPath) Local $objNodeList, $arrResponse[1], $i While @error = 0 $objNodeList = $objDoc.selectNodes($strXPath) ; $objNodeList = $objDoc.selectNodes ($strXPath) If $objNodeList.length > 0 Then _DebugWrite("GetValue list length:" & $objNodeList.length) For $objNode In $objNodeList if $objNode.hasChildNodes() = False Then _ArrayAdd($arrResponse, $objNode.Text) Else $objNodeChild = $objNode.childNodes(0) if $objNodeChild.nodeType = $NODE_CDATA_SECTION Then _ArrayAdd($arrResponse, $objNodeChild.data) Else _ArrayAdd($arrResponse, $objNode.Text) EndIf EndIf _DebugWrite("GetValue:" & $objNode.nodeValue) Next Return $arrResponse ; Return $objNode.nodeValue ; Return $arrResponse Else $xmlerr = @CRLF & "No matching node(s)found!" Return -1 ExitLoop EndIf WEnd ; _XMLError( "Error Retrieving: " & $strXPath & @CRLF & $oMyError.windescription) _XMLError( "Error Retrieving: " & $strXPath & $xmlerr) ; _XMLError( "No matching node(s)found for: " & $strXPath & @CRLF & $oMyError.windescription) SetError(1) Return -1 EndFunc ;==>_XMLGetValue The script for testing: expandcollapse popup#Include <_XMLDomWrapper.au3> #Include <String.au3> ;init some vars global $snips_dir=@ScriptDir $sXMLRoot = "Snippet" $s_TName ="test.test" ;open and read 512 bytes from color.au3 $s_TSource = FileOpen("C:\Program Files\AutoIt3\include\Color.au3",0) $s_TCode =FileRead($s_TSource,512) FileClose($s_TSource) ;get down to business. SaveSnippet($s_TName,$s_Tcode); save code snippet as cdata in xml $retVal = LoadSnippet($s_TName); read it back if IsArray($retVal) Then _ArrayDisplay($retVal,"hCode") Else MsgBox(0,"Code",LoadSnippet($s_TName)) EndIf Exit ;funcs. Func SaveSnippet($s_Name, $code) Local $sFile = $snips_dir & '\' & $s_Name & '.xml' While @error = 0 _XMLCreateFile ($sFile, $sXMLRoot, True) _XMLFileOpen ($sFile) ; _XMLCreateRootChild ("hCode") _XMLCreateCDATA("hCode",$code); cdata needs new node ??? Return ExitLoop WEnd MsgBox(4096, "Error", _XMLError ()) EndFunc;==>SaveSnippet Func LoadSnippet($s_Name) Local $sFile = $snips_dir & '\' & $s_Name & '.xml', $ret, $s_code ConsoleWrite($sFile & @LF) If FileExists($sFile) Then While @error = 0 $ret = _XMLFileOpen ($sFile) $s_code = _XMLGetValue ("//hCode") Return $s_code WEnd MsgBox(4096, "Error", _XMLError ()) EndIf EndFunc;==>LoadSnippet Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
GaryFrost Posted February 24, 2006 Posted February 24, 2006 Thanks for the help, I now have a new version of CSnippet out, saves the snippets to XML files Gary SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
GaryFrost Posted February 24, 2006 Posted February 24, 2006 (edited) Forgot, had to clean up the include file i always use Opt('MustDeclareVars',1) and remove variables not being used Here's the cleaned up one, with the update functions also Gary Edit: Removed attachment Edited February 24, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference.
eltorro Posted February 24, 2006 Author Posted February 24, 2006 Thanks for the help, I now have a new version of CSnippet out, saves the snippets to XML files GaryGreat! Forgot, had to clean up the include file i always use Opt('MustDeclareVars',1)and remove variables not being usedHere's the cleaned up one, with the update functions alsoGaryThanks, SteveUdpated download in first post. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
eltorro Posted February 24, 2006 Author Posted February 24, 2006 (edited) @KlemsonGuy You can start with this code: expandcollapse popup;Stephen Podhajecki <gehossafats@netmdc.com> #Include <_XMLDomWrapper.au3> Local $sXmlFile, $oOXml, $my_ns opt("MustDeclareVars", 1) ;_SetDebug (True);show debug messages via console write $sXmlFile = "C:\Program Files\AutoIt3\scripts\allocation.xml";******* put your path here. If @error Then MsgBox(4096, "File Open", "No file chosen") Else $oOXml = "" $my_ns = "" $oOXml = _XMLFileOpen ($sXmlFile, $my_ns) EndIf Dim $sallocation[200][4], $x GetNode() Exit Func GetNode() Local $x, $y, $ret, $iNodeCt, $msg $iNodeCt = _XMLGetNodeCount ("//allocation/state", "", $NODE_ELEMENT) ; MsgBox(0, "Allocation", $iNodeCt) For $x = 1 To $iNodeCt - 1 $ret = GetAlloc($x) If IsArray($ret) Then $msg = "" For $y = 1 To UBound($ret) - 1 $msg = $msg & "State = " & $ret[$y][4] & " ID = " & $ret[$y][0] & _ " Comm = " & $ret[$y][1] & " Alloc = " & $ret[$y][2] & @LF Next ConsoleWrite("The Return Values:" & @LF & $msg) ;MsgBox(0, "Allocations", $msg) EndIf Next EndFunc ;==>GetNode Func GetAlloc($iIndex) Local $iChildct, $iNodeCt, $sState, $sallocation[1][5], $aAttrN[1], $aAttrV[1], $ret Local $x, $y, $z $iIndex = "[" & $iIndex & "]" $sState = _XMLGetAttrib ("//allocation/state" & $iIndex, "id") $iChildct = _XMLGetNodeCount ("//allocation/state" & $iIndex & "/servicer", "", $NODE_ELEMENT) _DebugWrite ("State>" & $sState & " Servicer ct>" & $iChildct & @LF) If $iChildct > 0 Then ReDim $sallocation[$iChildct + 1][5] For $y = 1 To $iChildct If $y = 0 Then $ret = _XMLGetAllAttrib ("//allocation/state" & $iIndex & "/servicer", $aAttrN, $aAttrV) Else $ret = _XMLGetAllAttrib ("//allocation/state" & $iIndex & "/servicer", $aAttrN, $aAttrV, "[" & $y & "]") EndIf If @error = 0 Then $sallocation[$y][0] = $aAttrV[0] $sallocation[$y][4] = $sState For $z = 1 To UBound($aAttrV) - 1 $sallocation[$y][$z] = $aAttrV[$z] Next EndIf Next Return $sallocation EndFunc ;==>GetAlloc Hope this is what you are looking for. Steve Edit: autoit code tags Edited January 26, 2007 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
rokey Posted February 28, 2006 Posted February 28, 2006 dear autoit-cracksi have read all post about xml and played around with it... but i can't figure out how i must implement what i'm looking for. hopefully some could help me i have the following xml file (could be found here)expandcollapse popup<buddyList> <name>Wojjie's Buddy List</name> <buddy> <name>Wojjie</name> <status>Online</status> <game> <shortname>bf2</shortname> <longname>BattleField 2</longname> </game> <server> <name>24/7 Wake - Krackhouse</name> <fullip>69.28.221.211:16567</fullip> <link>http://www.game-monitor.com/GameServer/69.28.221.211:16567/</link> <players>37/40</players> <map>Wake Island 2007</map> </server> <score>12</score> <ping>20 ms</ping> <duration></duration> </buddy> <buddy> <name>=GSF=FreekBoy</name> <status>Offline</status> <game> <shortname>all</shortname> <longname>All</longname> </game> <server> <name></name> <fullip>0.0.0.0:</fullip> <link>http://www.game-monitor.com/GameServer/0.0.0.0:/</link> <players></players> <map></map> </server> <score></score> <ping></ping> <duration></duration> </buddy> <buddy> <name>EVO_Matt</name> <status>Offline</status> <game> <shortname>all</shortname> <longname>All</longname> </game> <server> <name></name> <fullip>0.0.0.0:</fullip> <link>http://www.game-monitor.com/GameServer/0.0.0.0:/</link> <players></players> <map></map> </server> <score></score> <ping></ping> <duration></duration> </buddy> <buddy> <name>i365|klaude</name> <status>Offline</status> <game> <shortname>all</shortname> <longname>All</longname> </game> <server> <name></name> <fullip>0.0.0.0:</fullip> <link>http://www.game-monitor.com/GameServer/0.0.0.0:/</link> <players></players> <map></map> </server> <score></score> <ping></ping> <duration></duration> </buddy> <buddy> <name>i365|lreese</name> <status>Offline</status> <game> <shortname>all</shortname> <longname>All</longname> </game> <server> <name></name> <fullip>0.0.0.0:</fullip> <link>http://www.game-monitor.com/GameServer/0.0.0.0:/</link> <players></players> <map></map> </server> <score></score> <ping></ping> <duration></duration> </buddy> <buddy> <name>Saboom</name> <status>Offline</status> <game> <shortname>all</shortname> <longname>All</longname> </game> <server> <name></name> <fullip>0.0.0.0:</fullip> <link>http://www.game-monitor.com/GameServer/0.0.0.0:/</link> <players></players> <map></map> </server> <score></score> <ping></ping> <duration></duration> </buddy> <buddy> <name>[BWC]Rabbit</name> <status>Offline</status> <game> <shortname>bf2</shortname> <longname>BattleField 2</longname> </game> <server> <name></name> <fullip>0.0.0.0:</fullip> <link>http://www.game-monitor.com/GameServer/0.0.0.0:/</link> <players></players> <map></map> </server> <score></score> <ping></ping> <duration></duration> </buddy> <buddy> <name>^-DRz-^Picchioni</name> <status>Offline</status> <game> <shortname>all</shortname> <longname>All</longname> </game> <server> <name></name> <fullip>0.0.0.0:</fullip> <link>http://www.game-monitor.com/GameServer/0.0.0.0:/</link> <players></players> <map></map> </server> <score></score> <ping></ping> <duration></duration> </buddy> </buddyList>and i would like bring the information "Buddy Name", "Server Fullip", "Players" and the "Status" (changes the icon) in a gui, that it looks like thisit would be nice if someone could help my out!
eltorro Posted March 2, 2006 Author Posted March 2, 2006 (edited) dear autoit-cracks i have read all post about xml and played around with it... but i can't figure out how i must implement what i'm looking for. hopefully some could help me it would be nice if someone could help my out! expandcollapse popup#include <GUIConstants.au3> #Include <_XMLDomWrapper.au3> ;=============================================================================== ;Buddy list example by <Stephen Podhajecki gehossafats@netmdc.com> ;=============================================================================== Global $ledRed = "C:\Program Files\AutoIt3\Scripts\ledred.ico";change this to the script dir Global $ledGrn = "C:\Program Files\AutoIt3\Scripts\ledgrn.ico";change this to the script dir $Form1 = GUICreate("Buddy List", 315, 333, 192, 125) GUISetBkColor(0xF0F0F0) GUISetState(@SW_SHOW) $msg = "" opt("MustDeclareVars", 1) Local $buddysheet = @ScriptDir & "\buddylist.xml" ConsoleWrite($buddysheet) Local $oBs = _XMLFileOpen ($buddysheet) If @error Then MsgBox(0, "Error", "There was an error opening the file.") Exit EndIf FillGui() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;;;;;; EndSelect WEnd Exit ;=============================================================================== ;Funcs ;=============================================================================== Func _RetFirst($aArray); return first item in an array If IsArray($aArray) Then Return $aArray[1] EndIf EndFunc ;==>_RetFirst Func _StringPad($sText, $sChar, $iLen, $iFlag = 0); add text to string While StringLen($sText) < $iLen If $iFlag < 1 Then $sText = $sText & $sChar Else $sText = $sChar & $sText EndIf WEnd Return $sText EndFunc ;==>_StringPad Func _ResizeGui($iht); resize gui to fit all buds. Local $a = WinGetPos("") WinMove("", "", $a[0], $a[1], $a[2], $iht + 40) EndFunc ;==>_ResizeGui Func FillGui(); fill the gui with the list. Local $i_Budds = _XMLGetNodeCount ("//buddyList/*") If $i_Budds > 0 Then Local $x, $y[4], $z, $sRet = _XMLSelectNodes ("//buddyList/*") If IsArray($sRet) Then ;_ArrayDisplay($sRet,"Node Names") _ResizeGui(20 * $sRet[0]) GUISetState(@SW_LOCK) For $x = 1 To $sRet[0] If $sRet[$x] = "buddy" Then $y[0] = _RetFirst(_XMLGetField ("buddyList/*[" & $x & "]/status")) $y[1] = _StringPad(_RetFirst(_XMLGetField ("buddyList/*[" & $x & "]/name")), " ", 18) $y[2] = _StringPad(_RetFirst(_XMLGetField ("buddyList/*[" & $x & "]/server/fullip")), " ", 21) $y[3] = _StringPad(_RetFirst(_XMLGetField ("buddyList/*[" & $x & "]/server/players")), " ", 10) $z = 20* ($x - 1) GUICtrlCreateLabel($y[2], 166, $z, 125, -1) GUICtrlCreateLabel($y[3], 275, $z, 85, -1) GUICtrlCreateLabel(" " & $y[1], 16, $z, 150, -1) If StringUpper($y[0]) = "ONLINE" Then GUICtrlCreateIcon($ledGrn, -1, 16, $z, 16, 16) GUICtrlSetStyle(-1, BitOR($SS_ICON, $SS_NOTIFY)) Else GUICtrlCreateIcon($ledRed, -1, 16, $z, 16, 16) GUICtrlSetStyle(-1, BitOR($SS_ICON, $SS_NOTIFY)) EndIf ;_ArrayDisplay($y,"Data") EndIf Next GUISetState(@SW_UNLOCK) EndIf EndIf EndFunc ;==>FillGui contains script and icons. buddylist.zip Steve Edit: changed to AutoIt code tags Edited January 26, 2007 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
Steve B. Posted March 2, 2006 Posted March 2, 2006 Hi Guys! Im wondering if there is a way to handle more than one XML File. For Example combing Parts of XML to a new one? Steve .B
eltorro Posted March 2, 2006 Author Posted March 2, 2006 (edited) Hi,I just added another version of the wrapper. This one allows for working with multiple documents by supplying an index number to the object. The index is passed as the last optional parameter of every function so as to not interfere with previous operation.Currently the file index is set for 5 files max[0-4]. Unless you have gobs of memory, I think that this is a resonable max as all docs are loaded into memory by M$'s dll. The global const $MAXFILES can be changed to meet your requirements.This is basically a workaround and is considered an experimental version for testing. Another option is to re-code the functions requiring that the doc object be pass in for every function.At present, I don't have time to re-code.Basically it works as follows for multi files:Dim $myFiles[$MAXFILES] $myFiles[0]= _XMLFileOpen("MyFile.xml","",0) $myFiles[1] = _XMLFileOpen("Myfile1.xml","",1) etc.......Please see the first post for download link.Steve. Edited March 2, 2006 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
rokey Posted March 2, 2006 Posted March 2, 2006 @eltorroMANY THANKS!! it works great! this is exactly what i'm looked for! ...again thanks.
eltorro Posted March 11, 2006 Author Posted March 11, 2006 (edited) I had someone ask me for a script to get the required items from an XSD and print them to a csv file. Below is a basic script to do that. Please keep in mind that there may be bugs and it might not work on all xsd files. expandcollapse popup;AutoitXSDtool.au3, find required items in the XSD ; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.1.1.110 ; Author: Stephen Podhajecki eltorro ; Version: 0.1 ; ; Script Function: find "required" items in the XSD, export data to csv ; ; ---------------------------------------------------------------------------- #Include "C:\Program Files\AutoIt3\include\_XMLDomMdi.au3" #Include <Array.au3> opt("MustDeclareVars", 1) ;=============================================================================== Global $xsdFile Global $count = 0 Global $sNxPath, $fHwnd Global $sOutFile = @ScriptDir & "\" & @ScriptName & ".csv" ;=============================================================================== ;$xsdFile=@ScriptDir & "\Base_v2.xsd" $xsdFile = FileOpenDialog("Open XSD", @ScriptDir, "XSD (*.XSD)|XML (*.XML)", 1) If @error Then MsgBox(4096, "File Open", "No file chosen , Exiting") Exit EndIf Main() Exit ;=============================================================================== ;Funcs ;=============================================================================== Func Main() Local $sPath, $aNodeName, $find, $ns, $oXSD $ns = GetNameSpace() $oXSD = _XMLFileOpen ($xsdFile, $ns) If @error Or $oXSD < 1 Then MsgBox(0, "Error", "There was an error opening the file " & $xsdFile) $oXSD =0 Exit EndIf GetNameSpace() $sPath = '.' $aNodeName = _XMLGetChildNodes ($sPath) If $aNodeName[0] > 0 Then For $find = 1 To $aNodeName[0] DrillDown($sPath & "/*" & '[' & $find & ']') Next If MsgBox(1, "Results", "There were " & $count & " required items." & @LF & _ "Output is in " & $sOutFile & @LF & @LF & _ "Click Ok to copy path to clipboard.") = 1 Then ClipPut($sOutFile) Else MsgBox(0, "Error:", "No nodes found for " & $sPath) EndIf $oXSD =0 EndFunc ;==>Main Func DrillDown($path) If $sNxPath = "" Then $sNxPath = $path Local $aNames[1], $aValues[1], $line = "", $retval, $sNodeName, $sData, $values, $sFndPath, $nc $retval = String(_XMLGetAttrib ($path, "use")) If $retval = "required" Then $count = $count + 1 $sData = '"' & $path & '",' $values = _XMLGetAllAttrib ($path, $aNames, $aValues) For $y = 1 To UBound($aNames) $sData = $sData & '"' & $aValues[$y - 1] & '",' Next $sData = StringTrimRight($sData, 1) CSVOut($sData) EndIf $nc = _XMLGetNodeCount ($path & "/*") $sNodeName = _XMLSelectNodes ($path & "/*") If $nc > 0 Then For $iNxNode = 1 To $sNodeName[0] $sNxPath = $sNxPath & '/' & $sNodeName[$iNxNode] & '[' & $iNxNode & ']' $sFndPath = $path & '/*[' & $iNxNode & ']' DrillDown($sFndPath) Next Else $sNxPath = "" EndIf EndFunc ;==>DrillDown Func CSVOut($sData) If FileExists($sOutFile) Then If $fHwnd = 0 Then FileDelete($sOutFile) $fHwnd = FileOpen($sOutFile, 9) EndIf Else $fHwnd = FileOpen($sOutFile, 9) EndIf If $fHwnd > 0 Then FileWriteLine($fHwnd, $sData) EndIf EndFunc ;==>CSVOut Func GetNameSpace() Local $ns, $aAT[1], $aVl[1], $x, $ret,$oXSD $oXSD= _XMLFileOpen ($xsdFile) $ns = _XMLGetAllAttrib ("./*", $aAT, $aVl) If $ns <> 0 Then For $x = 0 To UBound($aAT) - 1 If StringLeft($aAT[$x], 5) = "xmlns" Then $ret = $aAT[$x] & "='" & $aVl[$x] & "'" Next EndIf $oXSD =0 Return $ret EndFunc ;==>GetNameSpace I hope that someone will find it useful. Steve Edited January 26, 2007 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
Moderators big_daddy Posted March 15, 2006 Moderators Posted March 15, 2006 (edited) Wow, this XML stuff is giving me a headache. First off here is the xml file I'm working with: I want to turn it into something like this: Basicly I want it to pull these values from //MACHINE/APPLICABLE But if /MACHINE/APPLICABLE/EXPIRED == "True" then drop those. NAME KB_NUMBER TYPE SEVERITY URL I'm currently working on something, but if anyone could help out I'd be very greatful. Okay, this is what I have so far: #include <_XMLDomWrapper.au3> $sXmlFile = "MAIND53B.xml" $oOXml = _XMLFileOpen ($sXmlFile) $cnt = _XMLGetNodeCount ('//MACHINE/APPLICABLE/*', "") Dim $aAttrName[1], $aAttrValue[1] For $i = 0 To $cnt - 1 $ret = _XMLGetAllAttribIndex ("//MACHINE/APPLICABLE/*", $aAttrName, $aAttrValue, "", $i) If IsArray($aAttrName) Then _ArrayDisplay($aAttrName, "Attrib Names") _ArrayDisplay($aAttrValue, "Attrib Values") Else MsgBox(0, "Error", "No items found.") Exit EndIf Next Edited March 15, 2006 by big_daddy
eltorro Posted March 15, 2006 Author Posted March 15, 2006 (edited) Here you go:expandcollapse popup;MAIN53B.au3, find un-expired updates ; ---------------------------------------------------------------------------- ; ; AutoIt Version: 3.1.1.110 ; Author: Stephen Podhajecki eltorro ; Version: 0.1 ; ; Script Function: find un-expired updates, export data to csv ; ; ---------------------------------------------------------------------------- #Include "C:\Program Files\AutoIt3\include\_XMLDomMdi.au3" #Include <Array.au3> ;_SetDebug(True) opt("MustDeclareVars", 1) ;=============================================================================== Global $xmlFile Global $count = 0 Global $sNxPath, $fHwnd Global $sOutFile = @ScriptDir & "\" & @ScriptName & ".csv";Change this to suit your needs ;=============================================================================== ;$xsdFile=@ScriptDir & "\Base_v2.xsd" $xmlFile = FileOpenDialog("Open XML", @ScriptDir, "XML (*.XML)", 1) If @error Then MsgBox(4096, "File Open", "No file chosen , Exiting") Exit EndIf Main() Exit ;=============================================================================== ;Funcs ;=============================================================================== Func Main() Local $szXPath, $aNodeName, $find, $ns, $oXSD $ns = GetNameSpace() $oXSD = _XMLFileOpen ($xmlFile, $ns) If @error Or $oXSD < 1 Then MsgBox(0, "Error", "There was an error opening the file " & $xmlFile) $oXSD = 0 Exit EndIf $szXPath = "//INVENTORY/*" $aNodeName = _XMLGetChildNodes ($szXPath) If $aNodeName <> - 1 Then For $find = 0 To $aNodeName[0] ConsoleWrite($aNodeName[$find]) DrillDown($szXPath & "/*" & '[' & $find & ']') Next If MsgBox(1, "Results", "There were " & $count & " items found." & @LF & _ "Output is in " & $sOutFile & @LF & @LF & _ "Click Ok to copy path to clipboard.") = 1 Then ClipPut($sOutFile) Else MsgBox(0, "Error:", "No nodes found for " & $szXPath) EndIf $oXSD = 0 EndFunc;==>Main Func GetNameSpace() Local $ns, $aAT[1], $aVl[1], $x, $ret, $oXSD $oXSD = _XMLFileOpen ($xmlFile) $ns = _XMLGetAllAttrib ("./*", $aAT, $aVl) If $ns <> 0 Then For $x = 0 To UBound($aAT) - 1 If StringLeft($aAT[$x], 5) = "xmlns" Then $ret = $aAT[$x] & "='" & $aVl[$x] & "'" Next EndIf $oXSD = 0 Return $ret EndFunc;==>GetNameSpace Func CSVCreate($szFileName, $sHeader) If FileExists($szFileName) Then If $fHwnd = 0 Then; if we don't have a handle then old file. FileDelete($sOutFile) $fHwnd = FileOpen($sOutFile, 9) EndIf Else $fHwnd = FileOpen($sOutFile, 9) EndIf If $fHwnd Then CSVOut($sHeader) Return $fHwnd EndFunc;==>CSVCreate Func CSVOut($sData) If $fHwnd > 0 Then FileWriteLine($fHwnd, $sData) EndIf EndFunc;==>CSVOut Func DrillDown($path) If $sNxPath = "" Then $sNxPath = $path Local $aNames[1], $aValues[1], $line = "", $retval, $sNodeName, $sData, $values, $sFndPath, $nc Local $y, $x, $sRet, $aSearch = _ArrayCreate ("NAME", "KB_NUMBER", "TYPE", "SEVERITY", "URL") $retval = String(_XMLGetAttrib ($path, "EXPIRED")) If $retval = "False" Then If Not $fHwnd Then CSVCreate($sOutFile, "Update Name,KB Number,Type,Severity,URL") $count = $count + 1 $sData = "" $values = _XMLGetAllAttrib ($path, $aNames, $aValues) ;make csv for Update Name,KB Number,Type,Severity,URL ;if not @error then _ArrayDisplay($aValues,"") For $x = 0 To 4 $sRet = "" ;find attribute names we want and get the corresponding values For $y = 0 To UBound($aNames) - 1 If $aNames[$y] = $aSearch[$x] Then $sRet = $aValues[$y] ExitLoop EndIf Next $sData = $sData & $sRet & ',' Next $sData = StringTrimRight($sData, 1) ;CSVOut("["&$count&"]"&$sData) CSVOut($sData) EndIf $nc = _XMLGetNodeCount ($path & "/*") $sNodeName = _XMLSelectNodes ($path & "/*") If $nc > 0 Then For $iNxNode = 1 To $sNodeName[0] $sNxPath = $sNxPath & '/' & $sNodeName[$iNxNode] & '[' & $iNxNode & ']' $sFndPath = $path & '/*[' & $iNxNode & ']' DrillDown($sFndPath) Next Else $sNxPath = "" EndIf EndFunc;==>DrillDownChange the $sOutFile to suit your needsEdit:The script runs the whole xml file.to run applicable use $szXPath = "//INVENTORY/MACHINE/APPLICABLE"Edit: Added Autoit code tagsSteve Edited January 26, 2007 by eltorro Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
Moderators big_daddy Posted March 15, 2006 Moderators Posted March 15, 2006 Here you go:It worked perfectly! Thank you for the help.
eltorro Posted March 15, 2006 Author Posted March 15, 2006 It worked perfectly! Thank you for the help.Not a problem. Glad I could help. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code
nfwu Posted March 16, 2006 Posted March 16, 2006 (edited) Really confused: Where is the download? ??? #) EDIT: forget it, i figured it's _XMLMdiDOM.au3 Nice work! this goes into my "autoit scripts and scraps" folder! Edited March 16, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
ralnee Posted April 4, 2006 Posted April 4, 2006 I'd like to try my hand at making an rss reader (as a noob), but I'm unable to walk the xml tree in a rdf file, using the examples shown here already. So, after two days of trying, I'd figured I'd ask. Below I have a sample rss feed, that I like to parse into a two pane window (feed leafs on left with headlines, and article on right). Here's a sample feed.Thanks in Advance=====START=====<?xml version="1.0" encoding="ISO-8859-1"?><rss version="2.0"><channel><title>mysite.com</title><link>http://www.mysite.com/rssclick/?section=mysite_topstories</link><description>mysite.com delivers up-to-the-minute news and information on the latest top stories, weather, entertainment, politics and more.</description><language>en-us</language><copyright>© 2006 musite.com.</copyright><pubDate>Mon, 03 Apr 2006 19:54:53 EDT</pubDate><ttl>5</ttl><image><title>xxx.com</title><link>http://www.mysite.com/rssclick/?section=mysite_topstories</link><url>http://i.mysite.net/mysite/.element/img/1.0/logo/mysite.logo.rss.gif</url><width>144</width><height>33</height><description>mysite.com delivers up-to-the-minute news and information on the latest top stories, weather, entertainment, politics and more.</description></image><item><title>Moussaoui: God curse you all</title><link>http://www.mysite.com/rssclick/2006/LAW/04/03/moussaoui.verdict/index.html?section=mysite_topstories</link><description>Al Qaeda conspirator Zacarias Moussaoui is eligible for the death penalty, a federal jury decided Monday in the first U.S. trial about the September 11, 2001, attacks. Jurors agreed with prosecutors that his lies to FBI agents resulted in 9/11 deaths. After jurors left the courtroom, Moussaoui shouted, "You'll never get my blood. God curse you all."</description><pubDate>Mon, 03 Apr 2006 18:40:38 EDT</pubDate></item><item><title>Replacement organs grown from patients' own cells</title><link>http://www.mysite.com/rssclick/2006/HEALTH/conditions/04/03/engineered.organs/index.html?section=mysite_topstories</link><description>Kaitlyne McNamara no longer worries about feeling different at school.</description><pubDate>Mon, 03 Apr 2006 18:32:04 EDT</pubDate></item></channel></rss>======END=========
Moderators SmOke_N Posted April 4, 2006 Moderators Posted April 4, 2006 Answered your question here... in the future, if you've tried something... post what you've tried, otherwise all you say you've done is just "words" . http://www.autoitscript.com/forum/index.ph...ndpost&p=168994 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now