Languages :: Delphi :: Function to extract all key-value pairs from XML tag |
|||
| By: TheFalklands |
Date: 12/06/2003 00:00:00 |
Points: 50 | Status: Answered Quality : Excellent |
|
Hi all, I have written a function to use to extract all key-value pairs from an XML tag. The function prototype is: function extractAllKeyValues( str : string; pairs : TStringList; start_pos : integer; escape_char : integer = 92) : integer; And the code can be found at: <A HREF="http://www.pixelthis.co.nz/delphi/function_extractallkeyvalues.txt">http://www.pixelthis.co.nz/delphi/function_extractallkeyvalues.txt</a> It supports escaped characters, flags (keys with no values), quotes (both single and double). It returns all key-values as a string list: Examples: <name=martin surname="o'glaughlin' male/> resulting string list: name=martin surname=o'glaughlin male=true I have provided this because i know that someone can do it faster! Does anyone have a similar function to extract key-value pairs from a string perhaps written in machine-code? Or perhaps someone can optimise this one with machine code? It works by looping through every single character in the string and deciding whether to add it to the 'key', the 'value', or end a key, or end a value etc.... Hope it helps someone, and also hope someone can improve it and post back here! Cheers, |
|||
| By: VGR | Date: 12/06/2003 16:25:00 | Type : Answer |
|
| seems ok perhaps I would have, dpeending on the case, determined the set of chars able to end the current block and done some "while NOT (str in set) Inc(i);" but whatever this saves only some boolean evals per iteration |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








