My experience with XML is limited. I am trying to extract data from the sampling of the below XML file at end. The data use to be in a text file that was imported into Excel and processed via macros. I need to get the XML data into the same spreadsheet format to continue using the extensive programming within the Excel file.
Using the XMLTextReader, I am able to see the data, but I am trying to execute specific code based on the various elements. Example, the values of the SummaryValueData will be written in a specific area of an Excel Spreadsheet. The values of the DailyTestSummaryData will be written to another location as will the DailyCalibrationData values within the DailyTestSummaryData. The same will be true for the HourlyOperatingData. I am looking specifically for VB.Net coding (I am using 2003) to extract the data based on the major elements. Using the Excel XML features do not accomplish what I need, hence the VB.NET approach.
================CODE SNIPPET
Sub emXml()
'this section will process the EM xml file
'strFileName is a global variable
MsgBox("emXml : " & strFileName)
Dim strTemp As String
'Declare and Load file
Dim xmlDoc As New XmlDocument
Dim xNode As XmlNode
xmlDoc.Load(strFileName)
Dim reader As XmlTextReader = New XmlTextReader(strFileName)
Do While (reader.Read())
Select Case reader.NodeType
Case XmlNodeType.Element 'Display beginning of element.
strTemp = (reader.Name)
If reader.HasAttributes Then 'If attributes exist
While reader.MoveToNextAttribute
()
'Display attribute name and value.
strTemp = strTemp & (" {0}='{1}'" & reader.Name & reader.Value)
End While
End If
strTemp = strTemp
If strTemp = "SummaryValueData" Then
'this returns an integer...not what I wanted
MsgBox(XmlNodeType.Text & " " & reader.Value)
End If
If strTemp = "DailyTestSummaryData" Then
'this returns an integer...not what I wanted
MsgBox("DTSD " & XmlNodeType.Text & " " & reader.Value)
End If
Case XmlNodeType.Text 'Display the text in each element.
'this displays all of my values
lblFileName.Text = strTemp & ": " & reader.Value()
lblFileName.Refresh()
Dim x As Integer
For x = 1 To 100000000
'for next set just to allow the lblFileName.text
'to be read-not to be left as permanent part
'of program
Next
Select Case strTemp
'this is looking at various element names and gives appropriate value except it
'never hits the SummaryValueData Case
Case "ORISCode"
MsgBox("ORis is " & reader.Value)
Case "Year"
MsgBox("Year is " & reader.Value)
Case "SummaryValueData"
MsgBox("SummaryValueData is " & reader.Value)
End Select
End Select
Loop
'Call UpdateExcel()
End Sub
''''''''''XML FILE SAMPLING''''''''''''''''''
''''
<?xml version="1.0" encoding="utf-8"?>
<Emissions>
<ORISCode>1234</ORISCode>
<Year>2007</Year>
<Quarter>1</Quarter>
<SubmissionComment/>
<Version>1.2</Version>
<SummaryValueData>
<UnitID>001</UnitID>
<ParameterCode>CO2M</Param
eterCode>
<CurrentReportingPeriodTot
al>238270.
800</Curre
ntReportin
gPeriodTot
al>
<OzoneSeasonToDateTotal/>
<YearToDateTotal>238270.80
0</YearToD
ateTotal>
</SummaryValueData>
<DailyTestSummaryData>
<UnitID>001</UnitID>
<Date>2009-01-01</Date>
<Hour>7</Hour>
<Minute>24</Minute>
<MonitoringSystemID/>
<ComponentID>013</Componen
tID>
<TestTypeCode>DAYCAL</Test
TypeCode>
<TestResultCode>PASSED</Te
stResultCo
de>
<SpanScaleCode/>
<DailyCalibrationData>
<OnLineOffLineIndicator>1<
/OnLineOff
LineIndica
tor>
<UpscaleGasCode>HIGH</Upsc
aleGasCode
>
<ZeroInjectionDate>2009-01
-01</ZeroI
njectionDa
te>
<ZeroInjectionHour>7</Zero
InjectionH
our>
<ZeroInjectionMinute>22</Z
eroInjecti
onMinute>
<UpscaleInjectionDate>2009
-01-01</Up
scaleInjec
tionDate>
<UpscaleInjectionHour>7</U
pscaleInje
ctionHour>
<UpscaleInjectionMinute>24
</UpscaleI
njectionMi
nute>
<ZeroMeasuredValue>0.000</
ZeroMeasur
edValue>
<UpscaleMeasuredValue>2.60
0</Upscale
MeasuredVa
lue>
<ZeroAPSIndicator>0</ZeroA
PSIndicato
r>
<UpscaleAPSIndicator>0</Up
scaleAPSIn
dicator>
<ZeroCalibrationError>0.00
</ZeroCali
brationErr
or>
<UpscaleCalibrationError>2
.50</Upsca
leCalibrat
ionError>
<ZeroReferenceValue>0.000<
/ZeroRefer
enceValue>
<UpscaleReferenceValue>2.5
00</Upscal
eReference
Value>
</DailyCalibrationData>
</DailyTestSummaryData>
<DailyTestSummaryData>
<UnitID>001</UnitID>
<Date>2009-01-01</Date>
<Hour>7</Hour>
<Minute>25</Minute>
<MonitoringSystemID/>
<ComponentID>013</Componen
tID>
<TestTypeCode>INTCHK</Test
TypeCode>
<TestResultCode>PASSED</Te
stResultCo
de>
<SpanScaleCode/>
</DailyTestSummaryData>
<HourlyOperatingData>
<UnitID>001</UnitID>
<Date>2009-03-20</Date>
<Hour>15</Hour>
<OperatingTime>1.00</Opera
tingTime>
<HourLoad>90</HourLoad>
<LoadUnitsOfMeasureCode>MW
</LoadUnit
sOfMeasure
Code>
<LoadRange>9</LoadRange>
<CommonStackLoadRange/>
<FcFactor>1840.0</FcFactor
>
<FdFactor/>
<FwFactor/>
<FuelCode/>
<MonitorHourlyValueData>
<ParameterCode>CO2C</Param
eterCode>
<UnadjustedHourlyValue>12.
700</Unadj
ustedHourl
yValue>
<AdjustedHourlyValue/>
<MODCCode>01</MODCCode>
<MonitoringSystemID>104</M
onitoringS
ystemID>
<ComponentID>014</Componen
tID>
<PercentAvailable>86.8</Pe
rcentAvail
able>
<MoistureBasis/>
</MonitorHourlyValueData>
<MonitorHourlyValueData>
<ParameterCode>FLOW</Param
eterCode>
<UnadjustedHourlyValue>151
77000.000<
/Unadjuste
dHourlyVal
ue>
<AdjustedHourlyValue>15420
000.000</A
djustedHou
rlyValue>
<MODCCode>01</MODCCode>
<MonitoringSystemID>103</M
onitoringS
ystemID>
<ComponentID>013</Componen
tID>
<PercentAvailable>99.9</Pe
rcentAvail
able>
<MoistureBasis/>
</MonitorHourlyValueData>
<MonitorHourlyValueData>
<ParameterCode>NOXC</Param
eterCode>
<UnadjustedHourlyValue>107
.900</Unad
justedHour
lyValue>
<AdjustedHourlyValue/>
<MODCCode>01</MODCCode>
<MonitoringSystemID/>
<ComponentID>015</Componen
tID>
<PercentAvailable/>
<MoistureBasis/>
</MonitorHourlyValueData>
<MonitorHourlyValueData>
<ParameterCode>SO2C</Param
eterCode>
<UnadjustedHourlyValue>51.
800</Unadj
ustedHourl
yValue>
<AdjustedHourlyValue>51.80
0</Adjuste
dHourlyVal
ue>
<MODCCode>01</MODCCode>
<MonitoringSystemID>102</M
onitoringS
ystemID>
<ComponentID>012</Componen
tID>
<PercentAvailable>86.8</Pe
rcentAvail
able>
<MoistureBasis/>
</MonitorHourlyValueData>
<DerivedHourlyValueData>
<ParameterCode>CO2</Parame
terCode>
<UnadjustedHourlyValue/>
<AdjustedHourlyValue>111.6
000</Adjus
tedHourlyV
alue>
<MODCCode/>
<MonitoringSystemID/>
<FormulaIdentifier>401</Fo
rmulaIdent
ifier>
<PercentAvailable/>
<OperatingConditionCode/>
<SegmentNumber/>
<FuelCode/>
</DerivedHourlyValueData>
<DerivedHourlyValueData>
<ParameterCode>HI</Paramet
erCode>
<UnadjustedHourlyValue/>
<AdjustedHourlyValue>1064.
3000</Adju
stedHourly
Value>
<MODCCode/>
<MonitoringSystemID>104</M
onitoringS
ystemID>
<FormulaIdentifier>801</Fo
rmulaIdent
ifier>
<PercentAvailable/>
<OperatingConditionCode/>
<SegmentNumber/>
<FuelCode/>
</DerivedHourlyValueData>
<DerivedHourlyValueData>
<ParameterCode>NOXR</Param
eterCode>
<UnadjustedHourlyValue>0.1
87</Unadju
stedHourly
Value>
<AdjustedHourlyValue>0.187
0</Adjuste
dHourlyVal
ue>
<MODCCode>01</MODCCode>
<MonitoringSystemID>105</M
onitoringS
ystemID>
<FormulaIdentifier>501</Fo
rmulaIdent
ifier>
<PercentAvailable>78.4</Pe
rcentAvail
able>
<OperatingConditionCode/>
<SegmentNumber/>
<FuelCode/>
</DerivedHourlyValueData>
<DerivedHourlyValueData>
<ParameterCode>SO2</Parame
terCode>
<UnadjustedHourlyValue/>
<AdjustedHourlyValue>132.6
000</Adjus
tedHourlyV
alue>
<MODCCode/>
<MonitoringSystemID/>
<FormulaIdentifier>201</Fo
rmulaIdent
ifier>
<PercentAvailable/>
<OperatingConditionCode/>
<SegmentNumber/>
<FuelCode/>
</DerivedHourlyValueData>
</HourlyOperatingData>
<HourlyOperatingData>
<UnitID>001</UnitID>
<Date>2009-03-31</Date>
<Hour>23</Hour>
<OperatingTime>1.00</Opera
tingTime>
<HourLoad>89</HourLoad>
<LoadUnitsOfMeasureCode>MW
</LoadUnit
sOfMeasure
Code>
<LoadRange>9</LoadRange>
<CommonStackLoadRange/>
<FcFactor>1840.0</FcFactor
>
<FdFactor/>
<FwFactor/>
<FuelCode/>
<MonitorHourlyValueData>
<ParameterCode>NOXC</Param
eterCode>
<UnadjustedHourlyValue>108
.800</Unad
justedHour
lyValue>
<AdjustedHourlyValue/>
<MODCCode>01</MODCCode>
<MonitoringSystemID/>
<ComponentID>015</Componen
tID>
<PercentAvailable/>
<MoistureBasis/>
</MonitorHourlyValueData>
<MonitorHourlyValueData>
<ParameterCode>SO2C</Param
eterCode>
<UnadjustedHourlyValue>57.
000</Unadj
ustedHourl
yValue>
<AdjustedHourlyValue>57.00
0</Adjuste
dHourlyVal
ue>
<MODCCode>01</MODCCode>
<MonitoringSystemID>102</M
onitoringS
ystemID>
<ComponentID>012</Componen
tID>
<PercentAvailable>86.8</Pe
rcentAvail
able>
<MoistureBasis/>
</MonitorHourlyValueData>
<DerivedHourlyValueData>
<ParameterCode>SO2</Parame
terCode>
<UnadjustedHourlyValue/>
<AdjustedHourlyValue>144.2
000</Adjus
tedHourlyV
alue>
<MODCCode/>
<MonitoringSystemID/>
<FormulaIdentifier>201</Fo
rmulaIdent
ifier>
<PercentAvailable/>
<OperatingConditionCode/>
<SegmentNumber/>
<FuelCode/>
</DerivedHourlyValueData>
</HourlyOperatingData>
</Emissions>