0

I am trying to cut out some of the text that an XML file gives out. I have this XML data

<?xml version="1.0" encoding="utf-16"?>
<CurrentWeather>
  <Location>Luqa, Malta (LMML) 35-51N 014-29E 91M</Location>
  <Time>Apr 12, 2011 - 11:45 AM EDT / 2011.04.12 1545 UTC</Time>
  <Wind> from the WSW (240 degrees) at 8 MPH (7 KT) (direction variable):0</Wind>
  <Visibility> greater than 7 mile(s):0</Visibility>
  <Temperature> 66 F (19 C)</Temperature>
  <DewPoint> 41 F (5 C)</DewPoint>
  <RelativeHumidity> 39%</RelativeHumidity>
  <Pressure> 30.06 in. Hg (1018 hPa)</Pressure>
  <Status>Success</Status>
</CurrentWeather>

and i would like to put some of the values in seperate textboxes. I know I have to use the trim or substring but i would like to specify the text for example i want to retreive the text between the tags and anyone knows how to do this without using the substring counting of characters

I dont want to use the substring because the character locations can vary due to more or less characters in the XML

Thanks

Williham Totland
  • 28,471
  • 6
  • 52
  • 68
Dennis Vella
  • 21
  • 3
  • 4
  • You have to give much more information about the context. How are you processing the file and which textboxes are you talking about? Are you talking about a website, desktop or mobile phone application? Which values do you want to put where? You just give us the XML and tell us you want *some* data out of it... – Felix Kling Apr 12 '11 at 17:21

1 Answers1

0

Yes, you're right! Do not use substring! In fact, never, ever, try to cut and paste XML. It will fail, eventually.

Whatever language and tooling you are using, use a decent XML parser to extract the tagged content in a predictable and robust fashion. However, if you need more help, give us more context.

forty-two
  • 12,204
  • 2
  • 26
  • 36
  • I am using C# as a programming language and i want to get the values from between the tags location, visibility, wind and temperature. Any ideas how ? I am getting all the data from a web service – Dennis Vella Apr 14 '11 at 09:14
  • I'm not too familiar with recent C# web service support, but it was there already 10 years ago. Why don't you google on "C# web service client"? – forty-two Apr 14 '11 at 09:29
  • thanks for every one i found a solution by making some mathematics i just got the location of one tag minus the location of the same end tag and used subtstring method to get all the neccessary data – Dennis Vella Apr 14 '11 at 10:18