dexto Posted June 27, 2009 Posted June 27, 2009 (edited) I needed to read some info from XML so i found out that I needed to use COM objects. Oh well, I went and tried it. Its so complicated and I just want to read an XML (text file)! So, here is what I came up with: Examples: Reads: <realfeel>24</realfeel> using:XMLget($file, 'adc_database\currentconditions\realfeel') <sun rise="05:59" set="21:14"/> using:XMLget($file, 'adc_database\planets\sun') <day number="2"><txtlong>Nice weather tomorrow</txtlong></day> using:XMLget($file, 'adc_database\forecast\day number="2"\daytime\txtlong') <pressure state="Unavailable">1009.995</pressure> using: XMLget($file, 'adc_database\currentconditions\pressure') Edit: faster and more accurate.expandcollapse popupLocal $xmlPath = @ScriptDir & '\data.xml' If Not FileExists($xmlPath) Then Exit $file = FileRead($xmlPath) $file = StringReplace($file, @LF, '') $file = StringSplit($file, @CR, 1) MsgBox(0, 'DONE!!!', XMLget($file, 'adc_database\currentconditions\realfeel')) MsgBox(0, 'DONE!!!', XMLget($file, 'adc_database\planets\sun')) MsgBox(0, 'DONE!!!', XMLget($file, 'adc_database\forecast\day number="1"\daytime\txtlong')) MsgBox(0, 'DONE!!!', XMLget($file, 'adc_database\currentconditions\pressure')) Func XMLget($file, $Path); XMLget($file,'adc_database\currentconditions\realfeel') $Path = StringSplit($Path, '/\|', 0) $lastline = 0 For $lvl = 1 To $Path[0] Step 1 For $line = $lastline To $file[0] Step 1 $lastline = $line $hstart = StringInStr($file[$line], '<' & $Path[$lvl] & '>', 0) $hstarta = StringInStr($file[$line], '<' & $Path[$lvl] & ' ', 0) If $hstart Or $hstarta Then If $lvl == $Path[0] Then If $hstart Then $end = StringInStr($file[$line], '</' & $Path[$lvl] & '>', 0) If $end Then $hstart = $hstart + StringLen('<' & $Path[$lvl] & '>') Return StringMid($file[$line], $hstart, $end - $hstart) EndIf EndIf If $hstarta Then $end = StringInStr($file[$line], '/>', 0) If $end Then $hstarta = $hstarta + StringLen('<' & $Path[$lvl] & ' ') $return = StringMid($file[$line], $hstarta, $end - $hstarta) Return $return EndIf $ends = StringInStr($file[$line], '>', 0) If $ends Then $hstart = $ends + 1 $end = StringInStr($file[$line], '</' & $Path[$lvl] & '>', 0) If $end Then $return = StringMid($file[$line], $hstart, $end - $hstart) Return $return EndIf EndIf EndIf EndIf ContinueLoop 2 EndIf Next If $line == $file[0] Then ExitLoop Next Return 'not found' EndFunc ;==>XMLget Data for testing:data.zip Edited June 28, 2009 by dexto DreamVB 1
Yashied Posted June 28, 2009 Posted June 28, 2009 Good idea, dexto, and good job. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More...
dexto Posted June 28, 2009 Author Posted June 28, 2009 Thnx, I'll update it if I have newer versions.
VAG Posted September 16, 2009 Posted September 16, 2009 Hi, are you able to read the attributes of this path from your data.xml? I get the ''not found" message. My XML data has the similar format but cannot read out zone="MIZ076" county="MIC163" isactive="0" also.XMLget($file, 'adc_database\watchwarnareas')
baamr Posted October 13, 2014 Posted October 13, 2014 Hi, Is it possible to get more than first value from a XMLget($file, $Path) ? I mean if You have eg. 10 similar $Path in that same file.
jdelaney Posted October 13, 2014 Posted October 13, 2014 It's hard to handle ever single possible scenario without using the XMLDOM. Good luck. IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
baamr Posted October 13, 2014 Posted October 13, 2014 It's hard to handle ever single possible scenario without using the XMLDOM. Good luck. Thanks for reply, But i am not so familiar with XMLdom. I get all correct values from eg: MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databasecurrentconditionsrealfeel')) MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databaseplanetssun')) MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databaseforecastday number="1"daytimetxtlong')) MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databasecurrentconditionspressure')) My problem is when a $path is repeated eg. 3 times like this: MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databaseplanetssun')) MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databaseplanetssun')) MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databaseplanetssun')) I will get first value in every case even though i know there is 3 different. How can i get this routine correct?
baamr Posted October 14, 2014 Posted October 14, 2014 Can i put $path into array(in some way) or is it a constant?
baamr Posted October 15, 2014 Posted October 15, 2014 Hi, Here`s an example of what i mean. I have added an extra line in Data saying : <planets> <sun rise="06:05" set="21:20"/> I tried to add another line in code like this: MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databaseplanetssun')) But it will always give result from this line: <planets> <sun rise="05:59" set="21:14"/> How can i get results from the second line? Thanks, data.zip
baamr Posted October 16, 2014 Posted October 16, 2014 Hi, Here`s an example of what i mean. I have added an extra line in Data saying : <planets> <sun rise="06:05" set="21:20"/> I tried to add another line in code like this: MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databaseplanetssun')) But it will always give result from this line: <planets> <sun rise="05:59" set="21:14"/> How can i get results from the second line? Thanks, No one wants to reply?
guinness Posted October 17, 2014 Posted October 17, 2014 No one wants to reply? Please don't be impatient, this just fuels people not wanting to help you. If you're stuck ask in GHS about your generic issue. UDF List: _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
baamr Posted October 19, 2014 Posted October 19, 2014 Please don't be impatient, this just fuels people not wanting to help you. If you're stuck ask in GHS about your generic issue. Ok, thanks.
jdelaney Posted October 27, 2014 Posted October 27, 2014 (edited) Post your code...if it's truley the second instance then: MsgBox(0, 'DONE!!!', XMLget($file, 'adc_databaseplanets[2]sun')) Else, anyones guess is as good as mine. This might be better posted to the Help and Support forum Edited October 27, 2014 by jdelaney IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
TheSaint Posted October 28, 2014 Posted October 28, 2014 Three things. [1] Do some reading on how XML works. [2] There are many posts here about XML and even an old UDF. [3] Like guinness said, ask questions in General Help, where you can link to topics like this one, especially as the last post before your first here, was almost five years ago. Your questions will be noted far sooner than in this Forum which deals mostly with Example scripts. Make sure brain is in gear before opening mouth! Remember, what is not said, can be just as important as what is said. Spoiler What is the Secret Key? Life is like a Donut If I put effort into communication, I expect you to read properly & fully, or just not comment. Ignoring those who try to divert conversation with irrelevancies. If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it. I'm only big and bad, to those who have an over-active imagination. I may have the Artistic Liesense to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)
kesavan Posted July 20, 2017 Posted July 20, 2017 Hi, I downloaded 'Dexto' code. I implement the same for my requirement. It is working fine. However, for some XPATH, it is returning the other XPATH value. For eg: If I ask to read Parametes\Inputs\Pressure\Minimum, the script returns Parametes\Inputs\FlowRate\Minimum. Again, If I ask to read Parametes\Inputs\Temperature\Minimum, the script returns Parametes\Inputs\FlowRate\Minimum. I have attached the XML and AutoIt script. Please suggest me what i am doing wrong. Thanks in advance. sendxml.zip
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