Solved

XML Parse format 2

Posted on 2007-03-26
16
1,421 Views
Last Modified: 2011-09-20
I have a formating issue
My problem is this WeatherCond0 = objXML.selectsingleNode("/dwml/data/parameters/weather time-layout/weather-conditions weather-summary[0]")

The above obj Fail with this error msxml3.dll (0x80004005)
Expected token 'eof' found 'NAME'. /dwml/data/parameters/weather -->time-layout<--/weather-conditions weather-summary[0]
/braincell/PFForcaster.asp, line 14

it seems spaces are the issue but I’m not sure

this is what I need <weather-conditions weather-summary="Partly Cloudy" />

This is my XML source: http://www.weather.gov/forecasts/xml/SOAP_server/ndfdSOAPclientByDay.php?lat=47.4828776&lon=-122.2170661&format=24+hourly&startDate=2007-03-26&numDays=3&Submit=Submit/

This is the xml node structure: you can see this in the above link at NOAA
- <weather time-layout="k-p24h-n3-1">
  <name>Weather Type, Coverage, and Intensity</name>
  <weather-conditions weather-summary="Partly Cloudy" />
- <weather-conditions weather-summary="Rain Showers">
  <value coverage="isolated" intensity="none" weather-type="thunderstorms" qualifier="none" />
  <value coverage="isolated" intensity="light" additive="and" weather-type="rain showers" qualifier="none" />
  </weather-conditions>
- <weather-conditions weather-summary="Chance Rain Showers">
  <value coverage="chance" intensity="light" weather-type="rain showers" qualifier="none" />
  </weather-conditions>
  </weather>
0
Comment
Question by:derekfurman
  • 8
  • 7
16 Comments
 
LVL 9

Expert Comment

by:owenli27
ID: 18794812
should be:  objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions[0]")
Both time-layout and weather-summary are attributes

0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 18794963
>>this is what I need <weather-conditions weather-summary="Partly Cloudy" /><<
Than it looks like you need to allow for more than one node with that attribute. Like now:

<weather time-layout="k-p24h-n3-1">
      <name>Weather Type, Coverage, and Intensity</name>
      <weather-conditions weather-summary="Partly Cloudy" />
      <weather-conditions weather-summary="Partly Cloudy" />
      <weather-conditions weather-summary="Rain Likely">
            <value coverage="likely" intensity="light" weather-type="rain" qualifier="none" />
      </weather-conditions>
</weather>

This XPath will give you all the nodes with that value:
/dwml/data/parameters/weather/weather-conditions[@weather-summary='Partly Cloudy']

0
 

Author Comment

by:derekfurman
ID: 18795059
Please see this link : http://www.weather.gov/forecasts/xml/SOAP_server/ndfdSOAPclientByDay.php?lat=47.4828776&lon=-122.2170661&format=24+hourly&startDate=2007-03-26&numDays=4&Submit=Submit

I tried WeatherCond0 = objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions[0]").text
but return no value with no error other dat is flowing fine just this node returns nuthing

any Ideas
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:derekfurman
ID: 18795233
I think I’m being confusing here let me try again :

I have this XML : http://www.weather.gov/forecasts/xml/SOAP_server/ndfdSOAPclientByDay.php?lat=47.4828776&lon=-122.2170661&format=24+hourly&startDate=2007-03-26&numDays=4&Submit=Submit

Here is the xml
   <?xml version="1.0" ?>
- <dwml version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.nws.noaa.gov/forecasts/xml/DWMLgen/schema/DWML.xsd">
+ <head>
- <data>
+ <location>
+ <time-layout time-coordinate="local" summarization="24hourly">
+ <time-layout time-coordinate="local" summarization="12hourly">
- <parameters applicable-location="point1">
+ <temperature type="maximum" units="Fahrenheit" time-layout="k-p24h-n4-1">
+ <temperature type="minimum" units="Fahrenheit" time-layout="k-p24h-n4-1">
+ <probability-of-precipitation type="12 hour" units="percent" time-layout="k-p12h-n8-2">
- <weather time-layout="k-p24h-n4-1">
  <name>Weather Type, Coverage, and Intensity</name>
  <weather-conditions weather-summary="Partly Cloudy" />
  <weather-conditions weather-summary="Partly Cloudy" />
- <weather-conditions weather-summary="Rain Likely">
  <value coverage="likely" intensity="light" weather-type="rain" qualifier="none" />
  </weather-conditions>
- <weather-conditions weather-summary="Rain Likely">
  <value coverage="likely" intensity="light" weather-type="rain" qualifier="none" />
  </weather-conditions>
  </weather>
+ <conditions-icon type="forecast-NWS" time-layout="k-p24h-n4-1">
  </parameters>
  </data>
  </dwml>

I need to parse the info in these nodes into my app
<weather-conditions weather-summary="Partly Cloudy" />
<weather-conditions weather-summary="Partly Cloudy" />
<weather-conditions weather-summary="Rain Likely">
<weather-conditions weather-summary="Rain Likely">

Right now this returns nothing with no error what am I doing wrong here
WeatherCond0 = objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions/value[0]")

Below is my ASP page
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Connect XML -->
<%Dim objXML,TempfNodeData0,TempfNodeData1,TempfNodeData2,WeatherCond0,WeatherCond1,WeatherCond2,WeatherPic0,WeatherPic1,WeatherPic2
set objXML = CreateObject("MSXML2.FreeThreadedDOMDocument.3.0")
objXML.async = False
objXML.setProperty "ServerHTTPRequest", true
objXML.Load ("http://www.weather.gov/forecasts/xml/SOAP_server/ndfdSOAPclientByDay.php?lat=47.4828776&lon=-122.2170661&format=24+hourly&startDate=2007-03-26&numDays=4&Submit=Submit")
If not objXML.parseError.errorCode <> 0 then
    TempfNodeData0 = objXML.selectsingleNode("/dwml/data/parameters/temperature/value[1]").text
      TempfNodeData1 = objXML.selectsingleNode("/dwml/data/parameters/temperature/value[2]").text
      TempfNodeData2 = objXML.selectsingleNode("/dwml/data/parameters/temperature/value[3]").text
      'WeatherCond0 = objXML.selectsingleNode("/dwml/data/parameters/weather time-layout/weather-conditions weather-summary[0]")
      'WeatherCond0 = objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions[1]").text
      'WeatherCond0 = objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions[1]").getattribute("weather-type")
      WeatherCond0 = objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions/value[0]").getattribute("weather-conditions")
      'WeatherCond1 = objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions/value[8]").getattribute("weather-type")
      'WeatherCond2 = objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions/value[2]").getattribute("weather-type")
      WeatherPic0 = objXML.selectsingleNode("/dwml/data/parameters/conditions-icon/icon-link[1]").text
      WeatherPic1 = objXML.selectsingleNode("/dwml/data/parameters/conditions-icon/icon-link[2]").text
      WeatherPic2 = objXML.selectsingleNode("/dwml/data/parameters/conditions-icon/icon-link[3]").text
end if
Set objXML = Nothing %>
<!-- XML loaded for parsing End -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
body {
      background-color: #000000;
      margin-left: 0px;
      margin-top: 0px;
      margin-right: 0px;
      margin-bottom: 0px;
}
.topHeader {
      font-family: Tahoma, Geneva, Arial, Helvetica, Sans-serif;
      font-size: 24px;
      background-image: url(images/pfback.jpg);
      font-weight: bold;
      color: #0000CC;
}
.Bottr {
      font-family: Arial, Helvetica, sans-serif;
      font-size: 24px;
      font-weight: bold;
      color: #FFF300;
      background-image: url(images/pfback2.jpg);
}
.style23 {font-size: 24px; font-family: Tahoma, Geneva, Arial, Helvetica, Sans-serif; font-weight: bold; color: #FFFF00; }
.style24 {
      color: #FFFFFF;
      font-family: Tahoma, Geneva, Arial, Helvetica, Sans-serif;
}
-->
</style>
</head>

<body>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr class="topHeader" background="images/pfback.png">
<td width="78" height="40" align="center">
<%response.write TempfNodeData0 %>&deg;</td>
<td width="78" height="40" align="center">
<%response.write TempfNodeData1 %>&deg;</td>
<td width="78" height="40" align="center">
<%response.write TempfNodeData2 %>&deg;</td>
</tr>
<tr>
<td width="78" align="center" bgcolor="#333333"><img src="<%response.write WeatherPic0 %>" alt="today" width="78" height="66" /></td>
<td width="78" align="center" bgcolor="#333333"><img src="<%response.write WeatherPic1 %>" alt="tomorrow" width="78" height="66" /></td>
<td width="78" align="center" bgcolor="#333333"><img src="<%response.write WeatherPic2 %>" alt="Day after tomorrow" width="78" height="66" /></td>
</tr>
<tr bgcolor="#000099" class="Bottr">
<td width="78" height="40" align="center" class="style23">TUE</td>
<td width="78" height="40" align="center" class="style23">WED</td>
<td width="78" height="40" align="center" class="style23">THUR</td>
</tr>
</table>
<p>&nbsp;</p>
<p><span class="style24">Renton 47.4828776 -122.2170661</span><br />
<span class="style24">
<%response.write WeatherCond0 %>
<br />
<%response.write WeatherCond1 %>
<br />
<%response.write WeatherCond2 %>
<br />
<%response.write WeatherPic0 %>
<br />
<%response.write WeatherPic1 %>
<br />
<%response.write WeatherPic2 %>
</span></p>
<p>&nbsp;</p>
</body>
</html>

0
 
LVL 9

Expert Comment

by:owenli27
ID: 18795270
can you try this:
WeatherCond0 = objXML.selectsingleNode("//dwml/data/parameters/weather/weather-conditions[position()=1]")
0
 

Author Comment

by:derekfurman
ID: 18795307
this is the error I get when i tried that

msxml3.dll (0x80004005)
Unknown method.
//dwml/data/parameters/weather/weather-conditions[-->position()<--=1]
/braincell/PFForcaster.asp, line 17
0
 
LVL 9

Expert Comment

by:owenli27
ID: 18795548
>>I tried WeatherCond0 = objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions[0]").text
>> but return no value with no error other dat is flowing fine just this node returns nuthing

I think that is correct because there is no  text data under weather-conditions[0] in xml file.
You can test it again after you modify your xml to:
<weather-conditions weather-summary="Partly Cloudy"> Whatvere it is here </weather-conditions>
0
 

Author Comment

by:derekfurman
ID: 18795596
its the "partly Cloudy" that I want  <weather-conditions weather-summary="Partly Cloudy" /> i want to draw Partly Cloudy into my app
0
 

Author Comment

by:derekfurman
ID: 18795601
The value of weather-conditions weather-summary=
0
 
LVL 9

Expert Comment

by:owenli27
ID: 18795705
Not sure. I am a Java guy :)   I think it should be one of them:

selectsingleNode("/dwml/data/parameters/weather/weather-conditions[0]").Attributes(0).Text
OR
selectsingleNode("/dwml/data/parameters/weather/weather-conditions[0]").Attributes.item(0).Text
0
 
LVL 9

Expert Comment

by:owenli27
ID: 18795745
Sorry for my jumping in this Q.  I initially thought it only related to XML and XSLT
0
 
LVL 9

Accepted Solution

by:
owenli27 earned 500 total points
ID: 18795828
Found a safe way to get it:

objXML.selectsingleNode("/dwml/data/parameters/weather/weather-conditions[0]").Attributes.getNamedItem("weather-summary").nodeValue
0
 

Author Comment

by:derekfurman
ID: 18796178
Sucess ! your my hero owenli27
Thank you so much
0
 
LVL 9

Expert Comment

by:owenli27
ID: 18797269
Thank you for rewards.  I am just lucky for getting it work.  If it was Java code, I can do it much better.  :)
0
 

Author Comment

by:derekfurman
ID: 18797676
ya know I bet your right.
I will make another question how do I do this with java script
0
 

Author Comment

by:derekfurman
ID: 18797702
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro to import XML in Access 2013 2 50
innerHTML 7 35
ASP exit 10 20
send email part1 9 28
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

830 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