Solved

XML Parse format 2

Posted on 2007-03-26
16
1,402 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
 

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now