|
Hi,
I have been given an .xml file to investigate how it produces data.
Basically there is a file called testData.xml
when this file is double clicked, it opens up in excel with data.
If you right click and open in excel then a properly formatted excel workbook with two named sheets appear which have both got formatted data in them.
I have pasted the first few lines of the xml file for you to see.
Could you let me know how this is possible and where is the data coming from?
<?xml version="1.0" ?>
- <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns ="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
- <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
<Author>Ursula Bitterlin</Author>
<LastAuthor>874496</LastAuthor>
<LastPrinted>2006-07-05T15:45:06Z</LastPrinted>
<Created>2005-01-12T14:14:33Z</Created>
<LastSaved>2006-07-10T11:15:56Z</LastSaved>
<Company>Engineering</Company>
<Version>10.6735</Version>
</DocumentProperties>
- <OfficeDocumentSettings xmlns="urn:schemas-microsoft-com:office:office">
<DownloadComponents />
<LocationOfComponents HRef="/" />
</OfficeDocumentSettings>
- <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
<WindowHeight>5325</WindowHeight>
<WindowWidth>11820</WindowWidth>
<WindowTopX>120</WindowTopX>
<WindowTopY>60</WindowTopY>
<ActiveSheet>1</ActiveSheet>
<ProtectStructure>False</ProtectStructure>
<ProtectWindows>False</ProtectWindows>
</ExcelWorkbook>
- <Styles>
- <Style ss:ID="Default" ss:Name="Normal">
<Alignment ss:Vertical="Bottom" />
<Borders />
<Font />
<Interior />
<NumberFormat />
<Protection />
</Style>
- <Style ss:ID="s16" ss:Name="Comma">
<NumberFormat ss:Format="_ * #,##0.00_ ;_ * \-#,##0.00_ ;_ * "-"??_ ;_ @_" />
</Style>
|
|
|
|
|
I have the following XML and struggling to sort it how I need it..
<MyStuff>
<Job name="Job1" oldvalue="" type="Report 1" seq="29" >
< Param name="name" value="EARTH" newvalue="" />
< Param name="Colour" value="YELLOW" newvalue="" />
</Job>
<Job name="Job2" oldvalue="" type="Report 1" seq="29" >
< Param name="name" value="WIND" newvalue="" />
< Param name="Colour" value="GREEN" newvalue="" />
</Job>
<Job name="Job3" oldvalue="" type="Report 1" seq="29" >
< Param name="name" value="FIRE" newvalue="" />
< Param name="Colour" value="RED" newvalue="" />
</Job>
<Job name="Job4" oldvalue="" type="Report 1" seq="29" >
< Param name="name" value="DISCO" newvalue="" />
< Param name="Colour" value="BLUE" newvalue="" />
</Job>
</MyStuff>
I want to display the <Job> element, but have them sorted by a child element. eg display the Jobs in alphabetical order of Colour. I use the following snippet to sort on the higher level branch, (@seq) but i now want it sorted on /Param/[@name="Colour"] , or some syntax like that
System.Xml.XPath.XPathExpression exprBatch1 = xmlNavBatch1.Compile(String.Format("/MyStuff/Job", batch));
exprBatch1.AddSort("@seq", System.Xml.XPath.XmlSortOrder.Ascending, System.Xml.XPath.XmlCaseOrder.None, "", System.Xml.XPath.XmlDataType.Number);
Anybody any idea?
Regards
Malc
*********************************************
|
|
|
|
|
My XSL takes a date in this format: 2007-06-04T00:00:00 (Year/Month/Day/Time) from an SQL query that outputs FOR XML.
I would like the XSL to output it like so: dd/MM/yyyy (British date style)
How would i go about doing this in XSL?
or is it simpler to control the output style in SQL ?
Thanks.
|
|
|
|
|
You could possibly do it in XSL if there was support for XPath 2.0, but that's not likely. The SQL way is probably going to be the easiest. Also, if your stylesheet is only run though msxml, you can use a script. Here's an example:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:date-time="http://mycompany.com/mynamespace"
version="1.0"
exclude-result-prefixes="date-time msxsl">
...
<xsl:value-of select="date-time:GetMyDate()"/>
...
<msxsl:script language="JavaScript" implements-prefix="date-time">
<![CDATA[
function GetMyDate()
{
var myDate = new Date()
var y = myDate.getFullYear()
var m = EnsureLength(myDate.getMonth() + 1, 2)
var d = EnsureLength(myDate.getDate(), 2)
var h = EnsureLength(myDate.getHours(), 2)
var min = EnsureLength(myDate.getMinutes(), 2)
var s = EnsureLength(myDate.getSeconds(), 2)
var mil = EnsureLength(myDate.getMilliseconds(), 3)
return y + "-" + m + "-" + d + "-" + h + min + s + mil
}
function EnsureLength(s,n)
{
s = new String(s)
while (s.length < n)
s = "0" + s;
return s;
}
]]>
</msxsl:script>
</xsl:stylesheet>
The EnsureLength function I created because I couldn't find a string padding function in JavaScript.
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
Hello:
I am now creating an excel file using xslt with the code below:
dim objFsXML as System.IO.StringReader
dim objXmlTxtWrt as System.Xml.XmlTextReader
dim objXPath as System.Xml.Xpath.XpathDocument
dim objXslTran as System.Xml.Xsl.XslTransform
'Create Output Stream to write the file to disk
objFsXML = New System.IO.FileStream(strExcelFile,System.IO.FileMode.Create)
objXmlTxtWrt = New XmlTextWriter(objFsXML,System.Text.Encoding.Unicode)
'Create Xpath Doc to be given as used while doing the XSL Trannsfor
objStrRdr = New StringReader(dsDataSet.GetXml)
objXmlTxtRdr = New XmlTextReader(objStrRdr)
objXPath = New XPath.XPathDocument(objXmlTxtRdr)
objXslTran = New Xsl.XslTransform
objXslTran.Load(strXSLTempFile)' here throws exception
However, when there is a blank or a special char in one of my headers, i've got an invalid xpath expression which throw an exception
what can i do ?
thx
-- modified at 22:55 Wednesday 23rd August, 2006
|
|
|
|
|
hi
can any one tell me how to remove perticular node from xml file through c#
plz help
Rahul Khokale
|
|
|
|
|
I believe the XmlDocument class has a Remove method.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I want the client to be able to save the svg doc he/she modified on my web app
but I don't know how to write javascript that provide that functionality.
I have found several example on saving format such as txt and html.
But could not find one for svg. I want it to be saved as .svg because the client can see it as picture still unlike saving as txt.
|
|
|
|
|
How insert data in old xml file.
I want old data in xml as it is when i insert new next time in same xml
|
|
|
|
|
You could load data from xml file into XmlDocument, then add new xml data and save to the same file again.
Something like this:
XmlDocument doc = new XmlDocument();
doc.Load("file_path.xml");
XmlElement element = doc.CreateElement("NewElement");
element.InnerText = "test data";
doc.DocumentElement.AppendChild(element);
doc.Save("file_path.xml");
Vitaliy Tsvayer
Tikle
|
|
|
|
|
I've seen this question enough times that I wrote an article on it: Link[^]
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
|
...which is why I'm pasting in 300 lines of code
The ParseDaysXML routine is based on the ParseWeatherXML Routine. Not surprisingly, the code I copeid and pasted is working fine, but the stuff I tried to adapt isn't.
The commented code in ParseDaysXML is what is causing the problem. Based on the "Object reference not set to an instance of an object" error pointing to line 123 (second Dim line in the FindLayoutTable function), I'm suspecting something isn't right with my SelectSingleNode line (the first commented one).
So, three questions:
1) What is causing the error
2) how to fix?
3) My goal is simply to get period name from the WKKI2.xml file matched with the appopriate period in thew WKKI.xml file. Is there a more efficient way to go about it?
Thanks in advance....
Scott
---------------------------
Imports System.Xml
Imports System.Text
Imports System.Math
Public Class NWS_XML
#Region "Structs"
Private strStation As String
Private Structure WeatherTable
Public nodTimeLayout As XmlNode
Public nodData As XmlNode
End Structure
Private Structure WeatherData
Public wtHighTemp As WeatherTable
Public wtLowTemp As WeatherTable
Public wtLiquidPrecip As WeatherTable
Public wtSnowPrecip As WeatherTable
Public wtPrecipProb As WeatherTable
Public wtWindSpeed As WeatherTable
Public wtWindDirection As WeatherTable
Public wtCloudCover As WeatherTable
Public wtDayName As WeatherTable
Public wtNightName As WeatherTable
End Structure
Private Structure DayData
Public PeriodName As String
Public dt As Date
End Structure
Private Structure TemperatureData
Public F As Integer
Public ReadOnly Property C() As Integer
Get
Return Integer.Parse(Math.Round(((Double.Parse(F) - 32) / 9) * 5))
End Get
End Property
Public dt As Date
End Structure
Private Structure PrecipitationData
Public Inches As Double
Public ReadOnly Property MM() As Double
Get
Return Inches * 25.4
End Get
End Property
Public dt As Date
End Structure
Private Structure PercentData
Public Pct As Integer
Public dt As Date
End Structure
Private Structure WindData
Public Knots As Integer
Public ReadOnly Property MPH() As Integer
Get
Return Integer.Parse(Math.Round((Double.Parse(Knots) * 6076.12) / 5280))
End Get
End Property
Public Degrees As Integer
Public ReadOnly Property Dir() As String
Get
Select Case Degrees
Case 0 To 11.25, 348.75 To 360
Return "N"
Case 11.25 To 33.75
Return "NNE"
Case 33.75 To 56.25
Return "NE"
Case 56.25 To 78.75
Return "ENE"
Case 78.75 To 101.25
Return "E"
Case 101.25 To 123.75
Return "ESE"
Case 123.75 To 146.25
Return "SE"
Case 146.25 To 168.75
Return "SSE"
Case 168.75 To 191.25
Return "S"
Case 191.25 To 213.75
Return "SSW"
Case 213.75 To 236.25
Return "SW"
Case 236.25 To 258.75
Return "WSW"
Case 258.75 To 281.25
Return "W"
Case 281.25 To 303.75
Return "WNW"
Case 303.75 To 326.25
Return "NW"
Case 326.25 To 348.75
Return "NNW"
End Select
End Get
End Property
Public dt As Date
End Structure
Private Structure FormattedWeatherData
Public HighTemp() As TemperatureData
Public LowTemp() As TemperatureData
Public LiquidPrecip() As PrecipitationData
Public SnowPrecip() As PrecipitationData
Public PrecipProb() As PercentData
Public Wind() As WindData
Public CloudCover() As PercentData
Public DayName() As DayData
Public NightName() As DayData
End Structure
#End Region
#Region "NWS XML Reader http://www.nws.noaa.gov/forecasts/xml"
Private Function FindLayoutTable(ByVal xmlDoc As XmlDocument, ByVal nodData As XmlNode)
Dim nlTimeLayouts As XmlNodeList = xmlDoc.SelectNodes("/dwml/data/time-layout")
Dim strTimeLayout As String = nodData.Attributes("time-layout").Value
Dim node As XmlNode
For Each node In nlTimeLayouts
If strTimeLayout = node.SelectSingleNode("layout-key").InnerText Then
Return node
End If
Next
Return Nothing
End Function
Private Function ParseDateTime(ByVal str As String) As Date
Return Date.Parse(str.Replace("T", " ").Substring(0, str.LastIndexOf("-")))
End Function
Private Sub FillTemperatureData(ByVal wt As WeatherTable, ByRef temp() As TemperatureData)
Dim intCount As Integer
Dim nlData As XmlNodeList = wt.nodData.SelectNodes("value")
Dim nlDate As XmlNodeList = wt.nodTimeLayout.SelectNodes("start-valid-time")
For intCount = 0 To UBound(temp) - 1
temp(intCount) = New TemperatureData()
temp(intCount).F = Integer.Parse(nlData(intCount).InnerText)
temp(intCount).dt = ParseDateTime(nlDate(intCount).InnerText)
Next
End Sub
Private Sub FillPrecipitationData(ByVal wt As WeatherTable, ByRef precip() As PrecipitationData)
Dim intCount As Integer
Dim nlData As XmlNodeList = wt.nodData.SelectNodes("value")
Dim nlDate As XmlNodeList = wt.nodTimeLayout.SelectNodes("start-valid-time")
For intCount = 0 To UBound(precip) - 1
precip(intCount) = New PrecipitationData()
If Len(nlData(intCount).InnerText) = 0 Then
precip(intCount).Inches = 0
Else
precip(intCount).Inches = Double.Parse(nlData(intCount).InnerText)
End If
precip(intCount).dt = ParseDateTime(nlDate(intCount).InnerText)
Next
End Sub
Private Sub FillPercentData(ByVal wt As WeatherTable, ByRef pct() As PercentData)
Dim intCount As Integer
Dim nlData As XmlNodeList = wt.nodData.SelectNodes("value")
Dim nlDate As XmlNodeList = wt.nodTimeLayout.SelectNodes("start-valid-time")
For intCount = 0 To UBound(pct) - 1
pct(intCount) = New PercentData()
pct(intCount).Pct = Integer.Parse(nlData(intCount).InnerText)
pct(intCount).dt = ParseDateTime(nlDate(intCount).InnerText)
Next
End Sub
Private Sub FillWindData(ByVal wtSpeed As WeatherTable, ByVal wtDir As WeatherTable, ByRef wind() As WindData)
Dim intCount As Integer
Dim nlSpeed As XmlNodeList = wtSpeed.nodData.SelectNodes("value")
Dim nlDir As XmlNodeList = wtDir.nodData.SelectNodes("value")
Dim nlDate As XmlNodeList = wtSpeed.nodTimeLayout.SelectNodes("start-valid-time")
For intCount = 0 To UBound(wind) - 1
wind(intCount) = New WindData()
wind(intCount).Knots = Integer.Parse(nlSpeed(intCount).InnerText)
wind(intCount).Degrees = Integer.Parse(nlDir(intCount).InnerText)
wind(intCount).dt = ParseDateTime(nlDate(intCount).InnerText)
Next
End Sub
Private Sub FillDayData(ByVal wt As WeatherTable, ByRef DName() As DayData)
Dim intCount As Integer
Dim nlData As XmlNodeList = wt.nodData.SelectNodes("value")
Dim nlDate As XmlNodeList = wt.nodTimeLayout.SelectNodes("period-name")
For intCount = 0 To UBound(DName) - 1
DName(intCount) = New DayData()
DName(intCount).PeriodName = nlData(intCount).InnerText
DName(intCount).dt = ParseDateTime(nlDate(intCount).InnerText)
Next
End Sub
Private Function ParseForecastXML(ByVal strXMLWeather) As FormattedWeatherData
Try
'Setup variables
Dim xmlDoc As New XmlDocument()
Dim wdData As New WeatherData()
Dim fwdData As New FormattedWeatherData()
wdData.wtHighTemp = New WeatherTable()
wdData.wtLowTemp = New WeatherTable()
wdData.wtLiquidPrecip = New WeatherTable()
wdData.wtSnowPrecip = New WeatherTable()
wdData.wtPrecipProb = New WeatherTable()
wdData.wtWindSpeed = New WeatherTable()
wdData.wtWindDirection = New WeatherTable()
wdData.wtCloudCover = New WeatherTable()
'Load XML data
xmlDoc.Load(strXMLWeather)
'Load data and their corresponding time nodes
wdData.wtHighTemp.nodData = xmlDoc.SelectSingleNode("/dwml/data/parameters/temperature[@type='maximum']")
wdData.wtLowTemp.nodData = xmlDoc.SelectSingleNode("/dwml/data/parameters/temperature[@type='minimum']")
wdData.wtLiquidPrecip.nodData = xmlDoc.SelectSingleNode("/dwml/data/parameters/precipitation[@type='liquid']")
wdData.wtSnowPrecip.nodData = xmlDoc.SelectSingleNode("/dwml/data/parameters/precipitation[@type='snow']")
wdData.wtPrecipProb.nodData = xmlDoc.SelectSingleNode("/dwml/data/parameters/probability-of-precipitation[@type='12 hour']")
wdData.wtWindSpeed.nodData = xmlDoc.SelectSingleNode("/dwml/data/parameters/wind-speed[@type='sustained']")
wdData.wtWindDirection.nodData = xmlDoc.SelectSingleNode("/dwml/data/parameters/direction[@type='wind']")
wdData.wtCloudCover.nodData = xmlDoc.SelectSingleNode("/dwml/data/parameters/cloud-amount[@type='total']")
wdData.wtHighTemp.nodTimeLayout = FindLayoutTable(xmlDoc, wdData.wtHighTemp.nodData)
wdData.wtLowTemp.nodTimeLayout = FindLayoutTable(xmlDoc, wdData.wtLowTemp.nodData)
wdData.wtLiquidPrecip.nodTimeLayout = FindLayoutTable(xmlDoc, wdData.wtLiquidPrecip.nodData)
wdData.wtSnowPrecip.nodTimeLayout = FindLayoutTable(xmlDoc, wdData.wtSnowPrecip.nodData)
wdData.wtPrecipProb.nodTimeLayout = FindLayoutTable(xmlDoc, wdData.wtPrecipProb.nodData)
wdData.wtWindSpeed.nodTimeLayout = FindLayoutTable(xmlDoc, wdData.wtWindSpeed.nodData)
wdData.wtWindDirection.nodTimeLayout = FindLayoutTable(xmlDoc, wdData.wtWindDirection.nodData)
wdData.wtCloudCover.nodTimeLayout = FindLayoutTable(xmlDoc, wdData.wtCloudCover.nodData)
'Setup formatted data variables
ReDim fwdData.HighTemp(wdData.wtHighTemp.nodTimeLayout.SelectNodes("start-valid-time").Count)
ReDim fwdData.LowTemp(wdData.wtLowTemp.nodTimeLayout.SelectNodes("start-valid-time").Count)
ReDim fwdData.LiquidPrecip(wdData.wtLiquidPrecip.nodTimeLayout.SelectNodes("start-valid-time").Count)
ReDim fwdData.SnowPrecip(wdData.wtSnowPrecip.nodTimeLayout.SelectNodes("start-valid-time").Count)
ReDim fwdData.PrecipProb(wdData.wtPrecipProb.nodTimeLayout.SelectNodes("start-valid-time").Count)
ReDim fwdData.Wind(wdData.wtWindSpeed.nodTimeLayout.SelectNodes("start-valid-time").Count)
ReDim fwdData.CloudCover(wdData.wtCloudCover.nodTimeLayout.SelectNodes("start-valid-time").Count)
'Fill in data
FillTemperatureData(wdData.wtHighTemp, fwdData.HighTemp)
FillTemperatureData(wdData.wtLowTemp, fwdData.LowTemp)
FillPrecipitationData(wdData.wtLiquidPrecip, fwdData.LiquidPrecip)
FillPrecipitationData(wdData.wtSnowPrecip, fwdData.SnowPrecip)
FillPercentData(wdData.wtPrecipProb, fwdData.PrecipProb)
FillWindData(wdData.wtWindSpeed, wdData.wtWindDirection, fwdData.Wind)
FillPercentData(wdData.wtCloudCover, fwdData.CloudCover)
Return fwdData
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
End Try
End Function
Private Function ParseDaysXML(ByVal strXMLWeather) As FormattedWeatherData
Try
'Setup variables
Dim xmlDaysDoc As New XmlDocument()
Dim wdDaysData As New WeatherData()
Dim fwdDaysData As New FormattedWeatherData()
'Load XML data
xmlDaysDoc.Load(strXMLWeather)
'Load data and their corresponding time nodes
'wdDaysData.wtDayName.nodData = xmlDaysDoc.SelectSingleNode("/dwml/data/time-layout/start-valid-time/@period-name")
'wdDaysData.wtNightName.nodData = xmlDaysDoc.SelectSingleNode("/dwml/data/time-layout/start-valid-time/@period-name")
wdDaysData.wtHighTemp.nodData = xmlDaysDoc.SelectSingleNode("/dwml/data/parameters/temperature[@type='maximum']")
wdDaysData.wtLowTemp.nodData = xmlDaysDoc.SelectSingleNode("/dwml/data/parameters/temperature[@type='minimum']")
'wdDaysData.wtDayName.nodTimeLayout = FindLayoutTable(xmlDaysDoc, wdDaysData.wtDayName.nodData)
'wdDaysData.wtNightName.nodTimeLayout = FindLayoutTable(xmlDaysDoc, wdDaysData.wtNightName.nodData)
wdDaysData.wtHighTemp.nodTimeLayout = FindLayoutTable(xmlDaysDoc, wdDaysData.wtHighTemp.nodData)
wdDaysData.wtLowTemp.nodTimeLayout = FindLayoutTable(xmlDaysDoc, wdDaysData.wtLowTemp.nodData)
'Setup formatted data variables
'ReDim fwdDaysData.DayName(wdDaysData.wtDayName.nodTimeLayout.SelectNodes("start-valid-time").Count)
'ReDim fwdDaysData.NightName(wdDaysData.wtNightName.nodTimeLayout.SelectNodes("start-valid-time").Count)
ReDim fwdDaysData.HighTemp(wdDaysData.wtHighTemp.nodTimeLayout.SelectNodes("start-valid-time").Count)
ReDim fwdDaysData.LowTemp(wdDaysData.wtLowTemp.nodTimeLayout.SelectNodes("start-valid-time").Count)
'Fill in data
'FillDayData(wdDaysData.wtHighTemp, fwdDaysData.DayName)
'FillDayData(wdDaysData.wtLowTemp, fwdDaysData.NightName)
FillTemperatureData(wdDaysData.wtHighTemp, fwdDaysData.HighTemp)
FillTemperatureData(wdDaysData.wtLowTemp, fwdDaysData.LowTemp)
Return fwdDaysData
Catch ex As Exception
MsgBox(ex.ToString)
Return Nothing
End Try
End Function
#End Region
Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnWKKI.Click, btnKMAV.Click, btnWWWC.Click, btnKCHQ.Click
strStation = sender.Text
'load the weather array
Dim strWeatherXML As String = "http://distribution.customradionews.net/Forecast_XML/" & strStation & ".xml"
Dim fwdWeather As FormattedWeatherData = ParseForecastXML(strWeatherXML)
'load the days array
Dim strWeatherDaysXML As String = "http://distribution.customradionews.net/Forecast_XML/" & strStation & "2.xml"
Dim fwdWeatherDays As FormattedWeatherData = ParseDaysXML(strWeatherDaysXML)
|
|
|
|
|
Hi - Need help - some special characters are added to our XML document - unable to see this with notepad, wordpad, any type of XML readers like XMLSpy - is there a utility out there we could use? it adds this special characters at top of document ____ - the srainght line is the special characters.
thanks.
-- modified at 14:53 Friday 18th August, 2006
- Used Windiff - which displayed special characters.
- Removed the UTF-8 encoding - it seems to be causing error - leaving
- which seems to work for us.
|
|
|
|
|
hi,
i am doing program on xml and i am new to xml,how to get popupmenu on trayicon,anyone please help me,thanks.
kanth
|
|
|
|
|
firstly, xml is not a programming language, but more a description/markup language. it only serves in organizing informations in a document.
if you want to do something with the tray, tell what programming language you use, and even prefer asking the correct message board.
[edit]
forget the second part, you already asked the question in the VC++ forum...
[/edit]
|
|
|
|
|
<meaning>abc<type>xyz</type></meaning>
when i use
node.innertext
it concatenates abc and xyz both how can i retrive only the innertext of meaning tag.. i.e abc only
BIa
-- modified at 4:58 Friday 18th August, 2006
|
|
|
|
|
Please don't write URGENT in the title of your post. It's actually less likely to get answered that way.
To answer your question though, there are technically two child nodes of the <meaning> node. The first child is a text node, the second is the <type> element. Instead of using node.InnerText , get the first child node and get the InnerText of that: node.FirstChild.InnerText . You also will have to be careful about whitespace in these situations.
Logifusion[^]
If not entertaining, write your Congressman.
|
|
|
|
|
thank You .. nd sorry abt that Urgent bit
|
|
|
|
|
Language: VB.net 2005.
Input XML file: http://distribution.customradionews.net/Forecast_XML/WKKI.xml
Background: I'm working to interpret information from the National Weather Service's National Digital Forecast Database. There are a number places I've found that make use of the Web Srvice offered by the NWS for this data. For reasons of capacity, I am directly downloading the NDFD data and generating my own XML files. So, I end up with a series of xml files, 1 for each station we serve.
I want to parse that file into a string array, such that the forecast for each 12 hours is in one line. An example of what one data line should look like, using the file as it stands at 12:55pm CDT 8/17/06:
1,Today,2006-08-17T08:00:00-04:00,2006-08-17T20:00:00-04:00,85,slight chance,none,none,thunderstorms,none
Translation: Record#,Valid_Start,Valid_End,Temp,coverage,intensity,weather-type,qualifier
(Note: in order to get sample values for the conditions, I had to go to a day other than today in the raw data. Null values are acceptable in any of the fields after Temp)
I don't have any sample code, because I'm having a hard time wrapping my mind around how to get the data from one form to another. Why, I'm not sure. I have a feeling that once someone gets me started in the right direction, I'll be able to take it form there.
Thanks!
Scott
|
|
|
|
|
Not sure what you are asking for but here is how I interpret the XML.
All the "value" type elements (temperature, cloud-amount, weather) use a time-layout attribute to reference the [layout-key] element value that they map to. After you have the corrosponding parent element there is a one-to-one child element association.
led mike
|
|
|
|
|
I guess what I'm having difficulty wrapping my mind around is what type of loop I need to build to parse the code.
For instance, should I step through the period-names, using them to build element two of each record in the array, then step through the valid times, throwing them into element three, and so forth -- or should I execute 1 loop. I guess what's causing the disconnect for me is how I match (for instance) the third item in the "Daily Minimum Temperature" group with the third item in the second "time-layout" group, so I end up with a low for Saturday of 63 degrees.
I'm still enough of a noob that the code to make that matchup isn't clear to me. If someone can code a snippet that will make that matchup and output the strings "Satruday night" and "63", I'll be able to take it from there.
Thanks for your response...it helped me define the problem better, anyway1
|
|
|
|
|
XmlDocument doc = new XmlDocument();
doc.Load(@"c:\research\xml\wkki.xml");
string xpPeriod = "//dwml/data/time-layout[2]/start-valid-time[3]/@period-name";
string xpTemp = "//dwml/data/parameters/temperature[2]/value[3]/text()";
XmlText nTemp = doc.SelectSingleNode(xpTemp) as XmlText;
XmlAttribute nPeriod = doc.SelectSingleNode(xpPeriod) as XmlAttribute ;
Console.WriteLine("{0} - {1}", nPeriod.Value, nTemp.Value);
XmlNodeList nlPeriod = doc.SelectNodes("//dwml/data/time-layout[2]/start-valid-time/@period-name");
XmlNodeList nlTemp = doc.SelectNodes("//dwml/data/parameters/temperature[2]/value/text()");
for (int n = 0; n < nlPeriod.Count; n++)
Console.WriteLine("{0} - {1}", (nlPeriod.Item(n) as XmlAttribute).Value,
(nlTemp.Item(n) as XmlText).Value);
|
|
|
|
|
Thank you very much. I think that's enough to get me going!
Best,
Scott
|
|
|
|
|
Okay, I converted this to VB as follows:
Private Sub Button_Clicked(ByVal sender As Object, ByVal e As EventArgs) Handles btnWKKI.Click, btnWWWC.Click
Dim strStation As String = sender.Text
Dim xDocument As New XmlDocument()
xDocument.Load("http://distribution.customradionews.net/Forecast_XML/" & strStation & ".xml")
Dim xpPeriod As String = "//dwml/data/time-layout[2]/start-valid-time[3]/@period-name"
Dim xpTemp As String = "//dwml/data/parameters/temperature[2]/value[3]/text()"
Dim nTemp As XmlText = xDocument.SelectSingleNode(xpTemp)
Dim nPeriod As XmlAttribute = xDocument.SelectSingleNode(xpPeriod)
Console.WriteLine("{0} - {1}", nPeriod.Value, nTemp.Value)
Dim nlPeriod As XmlNodeList = xDocument.SelectNodes("//dwml/data/time-layout[2]/start-valid-time/@period-name")
Dim nlTemp As XmlNodeList = xDocument.SelectNodes("//dwml/data/parameters/temperature[2]/value/text()")
Dim n As Integer = 0
While n < nlPeriod.Count
Console.WriteLine("{0} - {1}", (nlPeriod.Item(n) as XmlAttribute).Value, (nlTemp.Item(n) as XmlText).Value)
n += 1
End While
End Sub
However, the IDE gives "Expression Does Not Produce A Value" on Console.WriteLine("{0} - {1}", (nlPeriod.Item(n) as XmlAttribute)...the second part of the statement is okay. What did I miss?
|
|
|
|
|