Post by altair on May 15, 2015 18:39:24 GMT 10
Hi guys,
I would like to know, how to cut the following text into two.
#open this is feeling good #end #open-26 ok not bad #end
I want to get the #open till the #end and not the second #end. How to do that.
Altair - The Flying One
|
|
Post by Nathan Lecompte on May 16, 2015 11:53:41 GMT 10
Hey altair , Does the string change or have different value or does it just stay the same. There's a split functionality you can use to split a string (there's also SplitEnd and SplitStart functionality's which do the same but then from the start or end). <<Should be easy to figure out how to use, this from the top of my head so correct me if I'm wrong
|
|
Post by altair on May 22, 2015 3:04:47 GMT 10
Well, the reason why I asked this question is based on my other post. Getting multiple path of the same XML. I have tried to implement it but the source returns invalid XML Characters (namely the numbers) that XmlDocument do not want to read but XmlReader reads I am using XmlReader. So I went across a different idea. Cut the text to the place I want to and parse it. Here is the source XML.
<time day="2015-05-21"> <symbol number="800" name="sky is clear" var="01d"/> <precipitation/> <windDirection deg="280" code="W" name="West"/> <windSpeed mps="5.11" name="Gentle Breeze"/> <temperature day="17.72" min="8.13" max="18.5" night="8.13" eve="16.81" morn="15.23"/> <pressure unit="hPa" value="991.17"/> <humidity value="43" unit="%"/> <clouds value="clear sky" all="0" unit="%"/> </time> <time day="2015-05-22"> <symbol number="500" name="light rain" var="10d"/> <precipitation value="0.24" type="rain"/> <windDirection deg="327" code="NNW" name="North-northwest"/> <windSpeed mps="8.61" name="Fresh Breeze"/> <temperature day="11.47" min="0.75" max="11.47" night="0.75" eve="7.83" morn="8.27"/> <pressure unit="hPa" value="1004.17"/> <humidity value="0" unit="%"/> <clouds value="clear sky" all="0" unit="%"/> </time> <time day="2015-05-23"> <symbol number="800" name="sky is clear" var="01d"/> <precipitation/> <windDirection deg="258" code="WSW" name="West-southwest"/> <windSpeed mps="5.03" name="Gentle Breeze"/> <temperature day="14.1" min="4.53" max="14.8" night="9.93" eve="14.8" morn="4.53"/> <pressure unit="hPa" value="1011.02"/> <humidity value="0" unit="%"/> <clouds value="clear sky" all="0" unit="%"/> </time> <time day="2015-05-24"> <symbol number="501" name="moderate rain" var="10d"/> <precipitation value="3.54" type="rain"/> <windDirection deg="249" code="WSW" name="West-southwest"/> <windSpeed mps="4.08" name="Gentle Breeze"/> <temperature day="20.2" min="12.04" max="20.2" night="13" eve="16.97" morn="12.04"/> <pressure unit="hPa" value="1006.01"/> <humidity value="0" unit="%"/> <clouds value="broken clouds" all="61" unit="%"/> </time> <time day="2015-05-25"> <symbol number="503" name="very heavy rain" var="10d"/> <precipitation value="55.26" type="rain"/> <windDirection deg="153" code="SSE" name="South-southeast"/> <windSpeed mps="2.66" name="Light breeze"/> <temperature day="14.82" min="10.72" max="16.34" night="15.55" eve="16.34" morn="10.72"/> <pressure unit="hPa" value="996.06"/> <humidity value="0" unit="%"/> <clouds value="overcast clouds" all="97" unit="%"/> </time>
So how to do it. I had an alternative JSON Path but I get the headaches. So I want to know how to get the text between <time day="2015-05-21"> and </time>
Altair - The Flying One 28 posts to go.
Last Edit: May 22, 2015 17:28:17 GMT 10 by altair
|
|
Post by dar on May 22, 2015 22:14:49 GMT 10
Why not use xdocument and access via XML path
Dim XML as xdocument = xdoicument.load(path as uri)
Dim timecontent as string = XML.<time>.value
|
|
Post by altair on May 23, 2015 18:10:41 GMT 10
I tried a similar one. But it is returning Nothing (String.Empty).
Public Sub getForecastData(xmlData As String) Dim [date] As String = "2015-05-22" Dim doc As XDocument = XDocument.Parse(xmlData) Dim field = doc.Descendants("time").Where(Function(x) DirectCast(x.Attribute("day"), String) = [date]).FirstOrDefault()
If field IsNot Nothing Then Output.Text = DirectCast(field.Value, String) Else showAlert("Forecast data returned null", "Something's Fishy!!") End If End Sub
Altair - The Flying One 27 posts to go
|
|
Post by dar on May 28, 2015 19:19:40 GMT 10
Use linq tags with xdocument, they are more dorect
|
|