Page 1 of 1

Get values from Http file.

Posted: 14 Aug 2017 13:09
by MohitBariya
I want to get data from this site: http://synd.cricbuzz.com/j2me/1.0/livematches.xml

Can anyone look out and help me for seperate data. I have created flow for it. Please look in details.
Response from http is as below.

Code: Select all

<mchdata NMchs="9">
		<links fUrlBase="http://synd.cricbuzz.com/j2me/1.0/flags/team_" />
	
	
		<match id="4" type="TEST" srs="India A tour of South Africa, 2017" mchDesc="RSAA vs INDA" mnum="1st unofficial Test"  vcity="Pretoria" vcountry="South Africa" grnd="LC de Villiers Oval" inngCnt="3" datapath="http://synd.cricbuzz.com/j2me/1.0/match/2017/2017_SAA_INDA/RSAA_INDA_AUG12_AUG15/" >
	 <state mchState="lunch" status="RSA A lead by 408 runs" TW="RSAA" decisn="Batting" addnStatus="Day 3: Lunch Break" splStatus="">
	</state>
	<Tm id="268" Name="RSAA" sName="RSAA"  flag='0'/>
	<Tm id="78" Name="IndA" sName="INDA"  flag='0'/>
	
	
	<Tme Dt="Aug 12 2017" stTme="07:30" enddt ="Aug 15 2017" ></Tme>		

	<mscr>
		<inngsdetail noofovers="62" rrr="0" crr="3.79" cprtshp="46(39)"/>
	<btTm id="268" sName="RSAA">
			<Inngs desc="2nd Inns" r="182"  Decl="0" FollowOn="0" ovrs="48" wkts="2"/>
			<Inngs desc="1st Inns" r="346"  Decl="0" FollowOn="0" ovrs="117.3" wkts="10"/>
	</btTm>
	<blgTm id="78" sName="INDA">
			<Inngs desc="1st Inns" r="120"  Decl="0" FollowOn="0" ovrs="39" wkts="10"/>
	</blgTm>

	</mscr>
	</match>
	
	
	
		<match id="1" type="TEST" srs="India tour of Sri Lanka, 2017" mchDesc="SL vs IND" mnum="3rd Test"  vcity="Pallekele" vcountry="Sri Lanka" grnd="Pallekele International Cricket Stadium" inngCnt="3" datapath="http://synd.cricbuzz.com/j2me/1.0/match/2017/2017_SL_IND/SL_IND_AUG12_AUG16/" >
	 <state mchState="complete" status="Ind won by an innings and 171 runs" TW="Ind" decisn="Batting" addnStatus="" splStatus="">
	</state>
	<Tm id="5" Name="SL" sName="SL"  flag='1'/>
	<Tm id="2" Name="Ind" sName="IND"  flag='1'/>
	
	
	<Tme Dt="Aug 12 2017" stTme="04:30" enddt ="Aug 16 2017" ></Tme>		

	<mscr>
		<inngsdetail noofovers="0" rrr="0" crr="2.43" cprtshp=""/>
	<btTm id="5" sName="SL">
			<Inngs desc="2nd Inns" r="181"  Decl="0" FollowOn="1" ovrs="74.3" wkts="10"/>
			<Inngs desc="1st Inns" r="135"  Decl="0" FollowOn="0" ovrs="37.4" wkts="10"/>
	</btTm>
	<blgTm id="2" sName="IND">
			<Inngs desc="1st Inns" r="487"  Decl="0" FollowOn="0" ovrs="122.3" wkts="10"/>
	</blgTm>

	</mscr>
	</match>
	
	
	
	<match id='18461' type="TEST" srs="India tour of Sri Lanka, 2017" mchDesc="SL vs IND" mnum="3rd Test"  inngCnt="3" datapath="http://synd.cricbuzz.com/j2me/1.0/match/2017/2017_SL_IND/SL_IND_AUG12_AUG16/" >
	
		<state mchState="Result" status="Ind won by an innings and 171 runs">	</state>
			<manofthematch NoOfPlayers="1">
				<mom Name="Hardik Pandya"/>
			</manofthematch>
			<ManOftheSeries  NoOfPlayers="1">
				<mos Name="Shikhar Dhawan"/>
			</ManOftheSeries >
		<Tm id="5" Name="SL" sName="SL"  flag='1'/>
		<Tm id="2" Name="Ind" sName="IND"  flag='1'/>
		
		<Tme Dt="Aug 12 2017" stTme="04:30" enddt ="Aug 16 2017"></Tme>

	</match>
	
	
	<match id='18329' type="T20" srs="Caribbean Premier League, 2017" mchDesc="STS vs GAW" mnum="12th Match"  inngCnt="2" datapath="http://synd.cricbuzz.com/j2me/1.0/match/2017/2017_CPL/STS_GAW_AUG13/" >
	
		<state mchState="Result" status="Guyana Amazon WAR won by 6 wkts">	</state>
			<manofthematch NoOfPlayers="1">
				<mom Name="Rashid Khan"/>
			</manofthematch>
		<Tm id="263" Name="STS" sName="STS"  flag='0'/>
		<Tm id="159" Name="GAW" sName="GAW"  flag='0'/>
		
		<Tme Dt="Aug 13 2017" stTme="22:00" enddt ="Aug 13 2017"></Tme>

	</match>
	</mchdata>


Link for Flow: http://automagic4android.com/flow.php?i ... f5f2247e34

Re: Get values from Http file.

Posted: 14 Aug 2017 15:30
by Desmanto
What data you want to get? Since it is xml, it will be better to parse it as xml, not using regex. I don't have enough xml skill yet to parse the data. But I have a similiar project to do, maybe we can learn together.

Automagic has the function evaluteXPathAsString(xml, xpath) to parse it. Need to learn at least a little about xml and Xpath to use it. I know some attributes and elements, but sometimes still confused when defining it in XPath.

For the script, after several try and error, here the one to extract the srs

Code: Select all

list = evaluateXPathAsString(response, "//mchdata/match/@srs")
list will now become
list = "India A tour of South Africa, 2017"

//mchdata/match/ will select from the root node until match element. To go deeper, you can define the path until the element needed, example //mchdata/match/mscr/btTm/@sName
@srs will select the attributes of match. To select the other, just replace the @srs, example @mchDesc

Re: Get values from Http file.

Posted: 14 Aug 2017 16:29
by MohitBariya
Thanks for help.
But it gives only values from first match data.
I want to list out all 4 match.
Is it possible??

Re: Get values from Http file.

Posted: 14 Aug 2017 16:53
by Desmanto
That's the strange thing with automagic XPath. That syntax supposed to give all srs element in all match. I tested the syntax at https://www.freeformatter.com/xpath-tes ... #ad-output
It returns :
Attribute='srs=India A tour of South Africa, 2017'
Attribute='srs=India tour of Sri Lanka, 2017'
Attribute='srs=India tour of Sri Lanka, 2017'
Attribute='srs=Caribbean Premier League, 2017'

So, seem automagic Xpath implementation is a little different or maybe it stop at the first stop. To get around it, I use regex to find the number of the element and using loop to create the list of all matched srs.

Code: Select all

list = newList();
len = length(findAll(response, "<match.*srs=")) ;
for (i in [1 to len])
{
  addElement(list, evaluateXPathAsString(response, "//mchdata/match[{i}]/@srs"));
}
list is the result. len will count the number of match at the xml. And then using loop, we will parse the data from match[1] to match[4] (depend on the number of the match found).

list = [India A tour of South Africa, 2017, India tour of Sri Lanka, 2017, India tour of Sri Lanka, 2017, Caribbean Premier League, 2017]
Even though there is comma there, but if you use the above script, the number of elements in list is still 4. There is invisible pointer that is only available to automagic list variable.

Re: Get values from Http file.

Posted: 14 Aug 2017 17:15
by MohitBariya
Thanks for fast response. That coma problem i have shorted using map instead list. Map are easy to handle.