?
Solved

XML to ASP string

Posted on 2005-03-23
5
Medium Priority
?
257 Views
Last Modified: 2012-06-27
I know this is a harder question and worth more than 50 points, but it is all that I have left.

I need to know a way to a small secion of code from a xml file and set it as a string in ASP, so that I can split the string and parse it into different variables. The part of the XML file is below.

<title>Current Conditions - 12:55 PM CST Mar. 2</title>
<link>http://www.wunderground.com/US/OK/Lawton.html</link>
      <description>Temperature: 55&#176;F / 13&#176;C | Humidity: 63% | Pressure: 30.01in / 1016hPa | Conditions: Overcast | Wind Direction: Variable | Wind Speed: 6mph / 9km/h
      </description>
        <pubDate>Wed, 2 Mar 2005 18:55:00 GMT
        </pubDate>
</item>

The section that I need in a string is:

      <description>Temperature: 55&#176;F / 13&#176;C | Humidity: 63% | Pressure: 30.01in / 1016hPa | Conditions: Overcast | Wind Direction: Variable | Wind Speed: 6mph / 9km/h
      </description>

Since it is separated by "|", I cannot show it how I want to in XML, I want to split that up and show it in different parts of a table. Thanks.
0
Comment
Question by:watyeag
  • 2
  • 2
5 Comments
 
LVL 9

Expert Comment

by:Wim_Bl
ID: 13614446
Hi,

you mean by splitting it into an array of strings ?

Dim myArray

myArray = split(description,"|")   --> make sure you only get the text, not the tags too

then loop through the array and use each part
0
 
LVL 10

Accepted Solution

by:
ThaSmartUno earned 200 total points
ID: 13614551
do you need an xml parser?

  Dim objXML
  Set objXML = Server.CreateObject("Msxml2.DomDocument.4.0")
  objXML.Load (Server.MapPath("/path/to/xml"))

  If objXML.parseError.errorCode <> 0 Then
    'there was an error ... do something

  End If
 
  Dim sDesc
  sDesc = objXML.selectSingleNode("//link/description").Text

  Set objXML = Nothing
 
  ' now use the code from Wim_Bl
  Dim myArray
  myArray = Split(sDesc,"|")
 
  ' do stuff with array
0
 

Author Comment

by:watyeag
ID: 13615855
Thanks for that, but I get an error now.

Object required: 'selectSingleNode(...)'
/xmltest.asp, line 12


Here is my code:

<%
  Dim objXML
  Set objXML = Server.CreateObject("Msxml2.DomDocument.4.0")
  objXML.Load ("C:/Lawton.xml")

  If objXML.parseError.errorCode <> 0 Then
    'there was an error ... do something

  End If
 
  Dim sDesc
  sDesc = objXML.selectSingleNode("/channel/link/description").Text

  Set objXML = Nothing
 
%>


 Is it just not finding the xml from this line...

sDesc = objXML.selectSingleNode("/channel/link/description").Text


Here is the complete xml file, if that helps.

<rss version="2.0">

<channel>
<title>Lawton, OK Weather from Weather Underground</title>
      <link>http://www.wunderground.com/</link>
      <description>Weather Underground RSS Feed for Lawton, OK US</description>
      <language>EN</language>
      <category>weather</category>
        <image>
                <url>http://icons.wunderground.com/graphics/smash/wunderTransparent.gif</url>
                <link>http://www.wunderground.com</link>
                <title>Weather Underground</title>    
        </image>
        <pubDate>Wed, 2 Mar 2005 18:55:00 GMT</pubDate>
        <lastBuildDate>Wed, 2 Mar 2005 18:55:00 GMT</lastBuildDate>
      <ttl>5</ttl>

<item>
<title>Current Conditions - 12:55 PM CST Mar. 2</title>
<link>http://www.wunderground.com/US/OK/Lawton.html</link>
      <description>Temperature: 55&#176;F / 13&#176;C | Humidity: 63% | Pressure: 30.01in / 1016hPa | Conditions: Overcast | Wind Direction: Variable | Wind Speed: 6mph / 9km/h
      </description>
        <pubDate>Wed, 2 Mar 2005 18:55:00 GMT
        </pubDate>
</item>

<item>
<title>Rest of Today as of Mar. 3 12:31 AM CST</title>
<link>http://www.wunderground.com/US/OK/Lawton.html</link>
     
<description>Rest of Today - Mostly cloudy with a 20 percent chance of thunderstorms. Highs in the upper 50s. Southwest winds up to 10 mph.  as of 12:31 PM CST on March 2, 2005      
      </description>
      <pubDate>Thu, 03 Mar 2005 06:31:00 GMT</pubDate>
</item>
</channel>
</rss>
0
 

Author Comment

by:watyeag
ID: 13616319
Nevermind, I got it working, i had this line incorrect

sDesc = objXML.selectSingleNode("/channel/link/description").Text

should be

sDesc = objXML.selectSingleNode("/channel/item/description").Text

I already know how to parse the text into string with an array, so I will give TheSmartUno all of the points.
0
 
LVL 10

Expert Comment

by:ThaSmartUno
ID: 13618110
sorry i couldnt help with the error ... i just got back now
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Integration Management Part 2
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question