visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
316 experts, 1194 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: Delphi :: Function to extract all key-value pairs from XML tag


By: TheFalklands U.S.A.  Date: 12/06/2003 00:00:00  English  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 English  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

EContact
browser fav
page generated in 288.236860 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page