gcue Posted July 13, 2011 Posted July 13, 2011 I have an XML i cannot read the values from. The examples I've hashed through in this forum have been <label>value</label> formatThe XML i have is more like <label child_labelA="value1" child_labelB="value2". And in some cases the child label "name" is repeated<?xml version="1.0" encoding="UTF-8" ?><Drives clsid="{8FDDDC1A-0C3C-43cd-A6B4-71A6D8C}"> <Drive clsid="{935DB-9CB8-4e3c-9914-7D57A47}" name="P:" status="P:" image="1" changed="2011-01-06 19:39:04" uid="{DDB66416-D9D6-4A8C-ADEC-4190332465}" bypassErrors="1" policyApplied="1"> <Properties action="R" thisDrive="NOCHANGE" allDrives="NOCHANGE" userName="" path="\\apps" label="Apps" persistent="1" useLetter="1" letter="P"></Properties> <Filters> <FilterGroup bool="AND" not="0" name="APPS_P_DM" sid="S-1-5-21-197296-17673-12288-2972" userContext="1" primaryGroup="0" localGroup="0"></FilterGroup></Filters></Drive> <Drive clsid="{935D1B74-9CB8-4e3c-9914-7559B7A47}" name="R:" status="R:" image="1" changed="2011-01-06 19:39:29" uid="{172D8-A779-44D1-BBF1-1C121831AE}" bypassErrors="1" policyApplied="1"> <Properties action="R" thisDrive="NOCHANGE" allDrives="NOCHANGE" userName="" path="\\teams" label="Teams" persistent="1" useLetter="1" letter="R"></Properties> <Filters> <FilterGroup bool="AND" not="0" name="Teams_R_DM" sid="S-1-5-21-19736-17678563-70918-20873" userContext="1" primaryGroup="0" localGroup="0"></FilterGroup></Filters></Drive> <Drive clsid="{935D1B74-9CB8-4e3c-9914-7D559B7A7}" name="S:" status="S:" image="1" changed="2011-01-06 19:38:22" uid="{5024EDF8-E1DD-4F15-B4C1-5784C2359D87}" bypassErrors="1" policyApplied="1"> <Properties action="R" thisDrive="NOCHANGE" allDrives="NOCHANGE" userName="" path="\\TempSpace" label="TempSpace" persistent="1" useLetter="1" letter="S"></Properties> <Filters> <FilterGroup bool="AND" not="0" name="TempSpace_S_DM" sid="S-1-5-21-19796-1767563-70988-21162" userContext="1" primaryGroup="0" localGroup="0"></FilterGroup></Filters></Drive> <Drive clsid="{935D1B74-9CB8-4e3c-9914-7D559B7A7}" name="U:" status="U:" image="1" bypassErrors="1" changed="2011-01-06 19:34:51" uid="{585CF6-A251-43C0-ACAE-E314B61E}" policyApplied="1"> <Properties action="R" thisDrive="NOCHANGE" allDrives="NOCHANGE" userName="" path="\\users\%username%" label="%username%'s User Drive" persistent="1" useLetter="1" letter="U"></Properties> <Filters> <FilterGroup bool="AND" not="0" name="Users_U_DM" sid="S-1-5-21-1971354296-17679563-7091288-21096" userContext="1" primaryGroup="0" localGroup="0"></FilterGroup></Filters></Drive> <Drive clsid="{935D1B74-9CB8-4e3c-9914-7D55A417}" name="U:" status="U:" image="1" userContext="1" bypassErrors="1" changed="2011-04-25 18:22:15" uid="{D01FAA-7D95-463D-9AC5-5CC3B9D773}" policyApplied="0"> <Properties action="R" thisDrive="NOCHANGE" allDrives="NOCHANGE" userName="" path="\\U-BP\%username%" label="" persistent="1" useLetter="1" letter="U"></Properties> <Filters> <FilterGroup bool="AND" not="0" name="U-BP_U_DM" sid="S-1-5-21-195296-176763-7091228-21645" userContext="1" primaryGroup="0" localGroup="0"></FilterGroup></Filters></Drive></Drives>I am trying to find both values of "name" for each Drive and "path" - where availableHere's the closest I got$nodes_array = _XMLSelectNodes("//Drives/*") for $x =1 to UBound($nodes_array)-1 ConsoleWrite($nodes_array[$x] & @CRLF) ConsoleWrite(_GetFirstValue('//Drives/Drive[name') & @CRLF) Next Func _GetFirstValue($node) $ret_val = _XMLGetValue($node) If IsArray($ret_val) Then Return ($ret_val[1]) Else Return SetError(1,3,0) EndIf EndFuncmany thanks in advance
Zedna Posted July 13, 2011 Posted July 13, 2011 Look here at my way :-) Resources UDF ResourcesEx UDF AutoIt Forum Search
guinness Posted July 13, 2011 Posted July 13, 2011 And my Example too >> #include <Array.au3> Global $aReturn, $sXMLData $sXMLData = "<data>This is a Simple example of XML</data><data>This is a Simple example of XML and is the Second String.</data>" $aReturn = _GetXML($sXMLData, "data") Switch @extended Case 1 MsgBox(64, "_GetXML()", _GetXML($aReturn, "data")) Case Else _ArrayDisplay($aReturn, "_GetXML()") EndSwitch Func _GetXML($sString, $sData) Local $aReturn, $iUbound $aReturn = StringRegExp($sString, '(?s)(?i)<' & $sData & '>(.*?)</' & $sData & '>', 3) If @error Then Return SetError(1, 0, $sString) EndIf $iUbound = UBound($aReturn, 1) If $iUbound = 1 Then Return SetError(0, $iUbound, StringStripWS($aReturn[0], 3)) EndIf Return SetError(0, $iUbound, $aReturn) EndFunc ;==>_GetXML UDF List: Reveal hidden contents _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018
PsaltyDS Posted July 13, 2011 Posted July 13, 2011 Those are attributes not values you are looking for, and this is a better way to walk through the Drive elements: #include <_XMLDOMWrapper.au3> _XMLFileOpen(@ScriptDir & "\Test1.xml") $iDriveCnt = _XMLGetNodeCount("/Drives/Drive") For $n = 1 To $iDriveCnt $sName = _XMLGetAttrib("/Drives/Drive[" & $n & "]", "name") ConsoleWrite($n & ": $sName = " & $sName & @LF) $sPath = _XMLGetAttrib("/Drives/Drive[" & $n & "]/Properties", "path") ConsoleWrite($n & ": $sPath = " & $sPath & @LF & @LF) Next Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
gcue Posted July 13, 2011 Author Posted July 13, 2011 (edited) On 7/13/2011 at 2:49 PM, 'guinness said: And my Example too >> #include <Array.au3> Global $aReturn, $sXMLData $sXMLData = "<data>This is a Simple example of XML</data><data>This is a Simple example of XML and is the Second String.</data>" $aReturn = _GetXML($sXMLData, "data") Switch @extended Case 1 MsgBox(64, "_GetXML()", _GetXML($aReturn, "data")) Case Else _ArrayDisplay($aReturn, "_GetXML()") EndSwitch Func _GetXML($sString, $sData) Local $aReturn, $iUbound $aReturn = StringRegExp($sString, '(?s)(?i)<' & $sData & '>(.*?)</' & $sData & '>', 3) If @error Then Return SetError(1, 0, $sString) EndIf $iUbound = UBound($aReturn, 1) If $iUbound = 1 Then Return SetError(0, $iUbound, StringStripWS($aReturn[0], 3)) EndIf Return SetError(0, $iUbound, $aReturn) EndFunc ;==>_GetXML thanks zedna/guiness =) i tried this method but it was very messy (had to do alot of string manipulation to getting the results i needed and im still like 3/4 of the way there with string manipulation). Edited July 13, 2011 by gcue
gcue Posted July 13, 2011 Author Posted July 13, 2011 On 7/13/2011 at 4:51 PM, 'PsaltyDS said: Those are attributes not values you are looking for, and this is a better way to walk through the Drive elements: #include <_XMLDOMWrapper.au3> _XMLFileOpen(@ScriptDir & "\Test1.xml") $iDriveCnt = _XMLGetNodeCount("/Drives/Drive") For $n = 1 To $iDriveCnt $sName = _XMLGetAttrib("/Drives/Drive[" & $n & "]", "name") ConsoleWrite($n & ": $sName = " & $sName & @LF) $sPath = _XMLGetAttrib("/Drives/Drive[" & $n & "]/Properties", "path") ConsoleWrite($n & ": $sPath = " & $sPath & @LF & @LF) Next works great! many thanks psalty! i am still trying to the get corresponding "name" from the "filtergroup" section.. I tried these but get a -1 error value $sGroup = _XMLGetAttrib("/Drives/Filters/FilterGroup[" & $n & "]", "name") ConsoleWrite($n & ": $sGroup = " & $sGroup & @LF & @LF) $sGroup = _XMLGetAttrib("/Drives/FilterGroup[" & $n & "]", "name") ConsoleWrite($n & ": $sGroup = " & $sGroup & @LF & @LF) so close! thanks again!
gcue Posted July 13, 2011 Author Posted July 13, 2011 i got it! $sGroup = _XMLGetAttrib("/Drives/Drive[" & $n & "]/Filters/FilterGroup", "name") ConsoleWrite($n & ": $sGroup = " & $sGroup & @LF & @LF) thanks again for all your help!!!
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