SRL Archive - OSR Help

Parsing this XML


I Am Legend

2011-12-14 18:09:35

how can i parse this XML

http://pastebin.com/raw.php?i=cQh47fBJ


so that each loop i do i can fill these variables
e.g.
for first loop

colour = 2565928
x = 976
y = 228


loop 2

colour = 2763307
x = 970
y = 208


and so on ..

i started on it using GetPage but im having problem going down line .=/

Remote := GetPage('http://pastebin.com/raw.php?i=cQh47fBJ');
writeln('hi');
for I := 0 to 31 do
begin
RemoteVersion := StrToInt(Between('</Item', '>', Remote));
writeln(RemoteVersion);
end;
Colour := StrToInt(Between('<Colour>', '</Colour>', Remote));
CoordX := StrToInt(Between('<CoordX>', '</CoordX>', Remote));
CoordX := StrToInt(Between('<CoordY>', '</CoordY>', Remote));

Kyle Undefined

2011-12-14 18:44:10

Why use XML? Why not just build an array of the values in your script? Or better yet, a object model.

Home

2011-12-14 18:44:27

Hello, there you go :)


Program Get_Info;


var
Name, Colour, CoordX, CoordY, Part, Source :String;
I :Integer;


begin
Source := GetPage('http://pastebin.com/raw.php?i=cQh47fBJ');
for I := 0 to 31 do
begin
Part := Between('<Item' + IntToStr(I) + '>', '</Data>', Source);
Name := Between('<Name>', '</Name>', Part);
Colour := Between('<Colour>', '</Colour>', Part);
CoordX := Between('<CoordX>', '</CoordX>', Part);
CoordY := Between('<CoordY>', '</CoordY>', Part);

WriteLn('Information For Current Data(' + IntToStr(I) + ')');
WriteLn(Name);
WriteLn(Colour);
WriteLn(CoordX);
WriteLn(CoordY);
end;
end.


~Home

I Am Legend

2011-12-14 18:57:50

wow thanks man , but i was jsut wondering how u managedd to scan each line
Part := Between('<Item' + IntToStr(I) + '>', '</Data>', Source);
Name := Between('<Name>', '</Name>', Part);


why use source and part ?

Home

2011-12-14 18:59:10

First I will get whole source of that page.

Then I will get Correct part of source. Using variable (I).

It's just simple playing around with Between :)


~Home

Kyle Undefined

2011-12-14 19:00:35

Source is the data that is returned from the GetData();

Part is getting the correct section of code. "<Item + IntToStr(I)" will walk down the nodes.

:ninja:'d

I Am Legend

2011-12-14 19:21:21

oh i see , hmm i learnt parsing on C was comparing string by reading it line by line, is tht method possible?

Sex

2011-12-14 19:24:46

If you really want to just explode it.
str := GetPage("page");
lines (TStringArray) := explode(chr(10), str);
:)
Edit: Also, be sure to know if your file uses line feed, carriage return, or both for line breaks.

I Am Legend

2011-12-14 20:03:17

wat is explode ?