?
Solved

XML to ASP string

Posted on 2005-03-23
5
Medium Priority
?
249 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
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/…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

777 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