fRequEnCy Posted March 5, 2010 Share Posted March 5, 2010 Hello all. I have an xml file which I wanna read from and don't wanna use the xml udf cuz other files that I need to read are not in xml format. So using regex to grab the info I need. Here's a sample of the data I'm stringing: expandcollapse popup<game name="terraf"> <description>Terra Force</description> <year>1987</year> <manufacturer>Nichibutsu</manufacturer> <rom name="terrafor.010" size="65536" crc="58b5f43b" sha1="9df77235c0b7ac5af4258c04bd90d0a86ccc86b0"/> <rom name="terrafor.002" size="65536" crc="148aa0c5" sha1="8d8a565540e91b384a9c154522501921b7da4d4e"/> <rom name="terrafor.003" size="65536" crc="d74085a1" sha1="3f6ba85dbd6e48a502c115b2d322a586fc4f56c9"/> <rom name="terrafor.004" size="65536" crc="2144d8e0" sha1="ed89da11abf3d79753b478603009970c2600ab60"/> <rom name="terrafor.005" size="65536" crc="744f5c9e" sha1="696223a087bb575c7cfaba11e682b221ada461e4"/> <rom name="terrafor.006" size="65536" crc="25d23dfd" sha1="da32895c1aca403209b7fb181fa4fa23a8e74d32"/> <rom name="terrafor.007" size="65536" crc="b9b0fe27" sha1="983c48239ba1524b517f89f281f2b70564bea1e9"/> <rom name="terrafor.008" size="32768" crc="bc6f7cbc" sha1="20b8a34de4bfa0c2fdcd2f7743a0ab35141f4bf9"/> <rom name="terrafor.009" size="32768" crc="d1014280" sha1="5ee8d71d77b31b25cce2bf1953c0a5166313a857"/> <rom name="terrafor.001" size="65536" crc="eb6b4138" sha1="04c53bf46d87a156d3fad86f051985d0df79bd20"/> <rom name="terrafor.011" size="65536" crc="5320162a" sha1="eaffafcaf146cdddb03f40f92ce23dfd096eb89e"/> <rom name="terrafor.012" size="32768" crc="4f0e1d76" sha1="b8636acde7547358663b94bdc8d49b5cc6b596eb"/> <rom name="terrafor.013" size="65536" crc="a86951e0" sha1="804cc6f143993f5a9d5f3798e971d7abfe94c3a8"/> <rom name="terrafor.014" size="65536" crc="8e5f557f" sha1="3462a58146c3f33bf8686adbd2ead25dae3804a8"/> <archive name="terra_force"/> <archive name="terraf"/> </game> <game name="tetrisp2"> <description>Tetris 2 Plus</description> <year>1996</year> <manufacturer>Jaleco</manufacturer> <rom name="t2p_04.rom" size="524288" crc="e67f9c51" sha1="d8b2937699d648267b163c7c3f591426877f3701"/> <rom name="t2p_01.rom" size="524288" crc="5020a4ed" sha1="9c0f02fe3700761771ac026a2e375144e86e5eb7"/> <rom name="96019-01.9" size="4194304" crc="06f7dc64" sha1="722c51b707b9854c0293afdff18b27ec7cae6719"/> <rom name="96019-02.8" size="4194304" crc="3e613bed" sha1="038b5e43fa3d69654107c8093126eeb2e8fa4ddc"/> <rom name="96019-06.13" size="4194304" crc="16f7093c" sha1="2be77c6a692c5d762f5553ae24e8c415ab194cc6"/> <rom name="96019-04.6" size="1048576" crc="b849dec9" sha1="fa7ac00fbe587a74c3fb8c74a0f91f7afeb8682f"/> <rom name="tetp2-10.bin" size="524288" crc="34dd1bad" sha1="9bdf1dde11f82839676400de5dd7acb06ea8cdb2"/> <rom name="96019-07.7" size="4194304" crc="a8a61954" sha1="86c3db10b348ba1f44ff696877b8b20845fa53de"/> <archive name="tetris_2_plus"/> <archive name="tetris2p"/> <archive name="tetrisp2"/> </game> Now the info I need is the info between... <game name=" & "> <description> & </description> <year> & </year> <manufacturer> & </manufacturer> I have the regex figured out. I know I can use string between and other things and have tried many variations. My question is what's the best way to handle this data for use in a listview? I currently am replacing the the string I need as follows: Description|Game Name|Year|Manufacturer and then stringing to array to put into the listview. Is this the best way to handle or can I do something with just StringRegExp instead of using StringRegExpReplace first? I like that when just using StringRegExp that it strings all the info I need but not sure how to handle the info when I have 4 back references. So the array would output this... terraf Terra Force 1987 Nichibutsu tetrisp2 Tetris 2 Plus 1996 Jaleco Sorry if I'm unclear but any help would be appreciated so I may move forward with my application. As is it works fine the way I'm doing it but would rather do it a better way if possible. Link to comment Share on other sites More sharing options...
Xenobiologist Posted March 5, 2010 Share Posted March 5, 2010 Something like this? #include <Array.au3> $filecontent = FileRead('testxml.txt') ;~ $re = StringRegExp($filecontent, '<description>(.+?)</description>|<game name="(.+?)">|<year>(.+?)</year>|<manufacturer>(.+?)</manufacturer>', 3) $re = StringRegExp($filecontent, '>(.+?)<|name="(.+?)">', 3) For $i = 0 To UBound($re) - 1 Step 5 ConsoleWrite($re[$i+1] & '|' & $re[$i+2] & '|' & $re[$i+3] & '|' & $re[$i+4] & '|' & @CRLF) Next _ArrayDisplay($re) Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
fRequEnCy Posted March 5, 2010 Author Share Posted March 5, 2010 Something like this? #include <Array.au3> $filecontent = FileRead('testxml.txt') ;~ $re = StringRegExp($filecontent, '<description>(.+?)</description>|<game name="(.+?)">|<year>(.+?)</year>|<manufacturer>(.+?)</manufacturer>', 3) $re = StringRegExp($filecontent, '>(.+?)<|name="(.+?)">', 3) For $i = 0 To UBound($re) - 1 Step 5 ConsoleWrite($re[$i+1] & '|' & $re[$i+2] & '|' & $re[$i+3] & '|' & $re[$i+4] & '|' & @CRLF) Next _ArrayDisplay($re) Ahhh ok. I think I had tried that before a long time ago when I first started my app. That seems like the easiest way to handle it without me having to do so many arrays or loops to gather the data. Thanks for the suggestion. Like this way better and is less code. 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