erifash Posted September 10, 2005 Share Posted September 10, 2005 (edited) I had created something better than my _INITable functions a while ago and I didn't do much of anything with them until now. They are called XML parsing functions because I thought that would be better tha meta, even though they work on any type of meta tag. So, just thought I'd share with you: expandcollapse popupFunc _XMLSet(ByRef $s_xml, $s_ele, $s_node) If _XMLExists($s_xml, $s_ele) Then _XMLDel($s_xml, $s_ele) $s_xml = $s_xml & "<" & $s_ele & ">" & $s_node & "</" & $s_ele & ">" & @CRLF EndFunc Func _XMLGet($s_xml, $s_ele) If not _XMLExists($s_xml, $s_ele) Then SetError(1) Return "" EndIf Return __StringParse($s_xml, "<" & $s_ele & ">", "</" & $s_ele & ">", 1) EndFunc Func _XMLDel(ByRef $s_xml, $s_ele) If not _XMLExists($s_xml, $s_ele) Then SetError(1) Return "" EndIf StringReplace("<" & $s_ele & ">" & _XMLGet($s_xml, $s_ele) & "</" & $s_ele & ">" & @CRLF, "", 0, 1) EndFunc Func _XMLExists($s_xml, $s_ele) If StringInStr($s_xml, "<" & $s_ele & ">") and StringInStr($s_xml, "</" & $s_ele & ">") Then Return 1 Return 0 EndFunc Func _XMLSave($s_xml, $s_file) FileWrite($s_file, $s_xml) Return not @error EndFunc Func _XMLLoad($s_file) Return __FileReadAll($s_file) EndFunc Func _XMLStartSection(ByRef $s_xml, $s_secname) $s_xml = $s_xml & "<" & $s_secname & ">" & @CRLF EndFunc Func _XMLEndSection(ByRef $s_xml, $s_secname) $s_xml = $s_xml & "</" & $s_secname & ">" & @CRLF EndFunc ;############################ ;# Helper Functions # ;############################ Func __FileReadAll($s_file) If not FileExists($s_file) Then SetError(1) Return "" EndIf Return FileRead($s_file, FileGetSize($s_file)) EndFunc Func __Test($b_Test, $v_True = 1, $v_False = 0) If $b_Test Then Return $v_True Return $v_False EndFunc Func __StringFindOccurances($sStr1, $sStr2) For $i = 1 to StringLen($sStr1) If not StringInStr($sStr1, $sStr2, 1, $i) Then ExitLoop Next Return $i EndFunc Func __StringParse($sz_str, $sz_before, $sz_after, $i_occurance = 0) Local $sz_sp1 = StringSplit($sz_str, $sz_before, 1) If $i_occurance < 0 or $i_occurance > $sz_sp1[0] Then SetError(1) Return "" EndIf Local $sz_sp2 If $i_occurance = 0 Then $sz_sp2 = StringSplit($sz_sp1[$sz_sp1[0]], $sz_after, 1) Else $sz_sp2 = StringSplit($sz_sp1[$i_occurance + 1], $sz_after, 1) EndIf Return $sz_sp2[1] EndFunc ;==>_StringParse() Hope you like them! Edited November 24, 2005 by erifash My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
erifash Posted September 10, 2005 Author Share Posted September 10, 2005 Oops! ...and here is the example: $xml = "" _XMLStartSection($xml, "main") _XMLSet($xml, "test", "hola") _XMLSet($xml, "second test", "what") _XMLStartSection($xml, "tester") _XMLSet($xml, "bored...", "wtf omg rofl") _XMLEndSection($xml, "tester") _XMLEndSection($xml, "main") _XMLSave($xml, "temp.xml") $load = _XMLLoad("temp.xml") FileDelete("temp.xml") MsgBox(0, "xml equal test", ($xml = $load)) MsgBox(0, "hola", _XMLGet($load, "test")) MsgBox(0, "what", _XMLGet($load, "second test")) MsgBox(0, "wtf omg rofl", _XMLGet($load, "bored...")) My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
Valik Posted September 10, 2005 Share Posted September 10, 2005 Doing XML by hand is pointless now since we can use COM and MSXML. You can simplify that code to just a few lines using MSXML. Link to comment Share on other sites More sharing options...
leecole Posted September 13, 2005 Share Posted September 13, 2005 I had created something better than my _INITable functions a while ago and I didn't do much of anything with them until now. They are called XML parsing functions because I thought that would be better tha meta, even though they work on any type of meta tag. So, just thought I'd share with you:expandcollapse popupFunc _XMLSet(ByRef $s_xml, $s_ele, $s_node) If _XMLExists($s_xml, $s_ele) Then _XMLDel($s_xml, $s_ele) $s_xml = $s_xml & "<" & $s_ele & ">" & $s_node & "</" & $s_ele & ">" & @CRLF EndFunc Func _XMLGet($s_xml, $s_ele) If not _XMLExists($s_xml, $s_ele) Then SetError(1) Return "" EndIf Return __StringParse($s_xml, "<" & $s_ele & ">", "</" & $s_ele & ">", 1) EndFunc Func _XMLDel(ByRef $s_xml, $s_ele) If not _XMLExists($s_xml, $s_ele) Then SetError(1) Return "" EndIf StringReplace("<" & $s_ele & ">" & _XMLGet($s_xml, $s_ele) & "</" & $s_ele & ">" & @CRLF, "", 0, 1) EndFunc Func _XMLExists($s_xml, $s_ele) If StringInStr($s_xml, "<" & $s_ele & ">") and StringInStr($s_xml, "</" & $s_ele & ">") Then Return 1 Return 0 EndFunc Func _XMLSave($s_xml, $s_file) FileWrite($s_file, $s_xml) Return not @error EndFunc Func _XMLLoad($s_file) Return __FileReadAll($s_file) EndFunc ;############################ ;# Helper Functions # ;############################ Func __FileReadAll($s_file) If not FileExists($s_file) Then SetError(1) Return "" EndIf Return FileRead($s_file, FileGetSize($s_file)) EndFunc Func __Test($b_Test, $v_True = 1, $v_False = 0) If $b_Test Then Return $v_True Return $v_False EndFunc Func __StringFindOccurances($sStr1, $sStr2) For $i = 1 to StringLen($sStr1) If not StringInStr($sStr1, $sStr2, 1, $i) Then ExitLoop Next Return $i EndFunc Func __StringParse($sz_str, $sz_before, $sz_after, $i_occurance = 0) Local $sz_sp1 = StringSplit($sz_str, $sz_before, 1) If $i_occurance < 0 or $i_occurance > $sz_sp1[0] Then SetError(1) Return "" EndIf Local $sz_sp2 If $i_occurance = 0 Then $sz_sp2 = StringSplit($sz_sp1[$sz_sp1[0]], $sz_after, 1) Else $sz_sp2 = StringSplit($sz_sp1[$i_occurance + 1], $sz_after, 1) EndIf Return $sz_sp2[1] EndFunc ;==>_StringParse()Hope you like them! <{POST_SNAPBACK}>Where is _XMLStartSection()and_XMLEndSection()? Talking Clockhttp://www.autoitscript.com/forum/index.php?showtopic=20751Talking Headlineshttp://www.autoitscript.com/forum/index.php?showtopic=20655Sometimes, I sits and thinkssometimes, I just sits Link to comment Share on other sites More sharing options...
Endgame Posted October 11, 2005 Share Posted October 11, 2005 Doing XML by hand is pointless now since we can use COM and MSXML. You can simplify that code to just a few lines using MSXML.What if MSXML is not installed on the system running the script? This UDF would be a good way around that issue. EndgameMy UDFsFile Size ConvertMacros in INI UDF Link to comment Share on other sites More sharing options...
DaleHohm Posted October 11, 2005 Share Posted October 11, 2005 Not likely it won't be there. MSXML is installed as part of Internet Explorer (first with IE 4.0 -- and that goes back a while) and with other products.DaleWhat if MSXML is not installed on the system running the script? This UDF would be a good way around that issue. Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble Link to comment Share on other sites More sharing options...
Endgame Posted October 12, 2005 Share Posted October 12, 2005 (edited) Not likely it won't be there. MSXML is installed as part of Internet Explorer (first with IE 4.0 -- and that goes back a while) and with other products.DaleExcellent point. I guess that's why is says "Newbie" under my name.Endgame Edited October 12, 2005 by Endgame EndgameMy UDFsFile Size ConvertMacros in INI UDF Link to comment Share on other sites More sharing options...
ning Posted October 31, 2005 Share Posted October 31, 2005 Doing XML by hand is pointless now since we can use COM and MSXML. You can simplify that code to just a few lines using MSXML.I imagine it would be faster too. Could you post a very quick example please? I'm looking to do some XML parsing and I really don't want to reinvent the wheel.ben Link to comment Share on other sites More sharing options...
blitzkrg Posted October 31, 2005 Share Posted October 31, 2005 I imagine it would be faster too. Could you post a very quick example please? I'm looking to do some XML parsing and I really don't want to reinvent the wheel.benI'd like to see some example code also Link to comment Share on other sites More sharing options...
Valik Posted October 31, 2005 Share Posted October 31, 2005 Find some examples of using MSXML in VBScript and port them to AutoIt. AutoIt and VBScript are syntactically similar enough that that shouldn't be too hard. There may also be some examples posted in the forum though I don't know of any off the top of my head. Link to comment Share on other sites More sharing options...
Talpa Posted November 24, 2005 Share Posted November 24, 2005 Where is _XMLStartSection() and _XMLEndSection()? Link to comment Share on other sites More sharing options...
erifash Posted November 24, 2005 Author Share Posted November 24, 2005 Where is _XMLStartSection() and _XMLEndSection()? Here ya go!Func _XMLStartSection(ByRef $s_xml, $s_secname) $s_xml = $s_xml & "<" & $s_secname & ">" & @CRLF EndFunc Func _XMLEndSection(ByRef $s_xml, $s_secname) $s_xml = $s_xml & "</" & $s_secname & ">" & @CRLF EndFuncUpdated in first post too! My UDFs:_FilePrint() | _ProcessGetName() | _Degree() and _Radian()My Scripts:Drive Lock - Computer Lock Using a Flash DriveAU3Chat - Simple Multiuser TCP ChatroomStringChunk - Split a String Into Equal PartsAutoProxy - Custom Webserver Link to comment Share on other sites More sharing options...
theguy0000 Posted February 5, 2006 Share Posted February 5, 2006 (edited) I dont really understand the example... it doesnt do anything when i run it... AH! nvm, i get it! very useful, and exactly what i was looking for! Edited February 5, 2006 by theguy0000 The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN Link to comment Share on other sites More sharing options...
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