[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

How do I extract data from an XML File?

Asked by abcserve in .Net Application Servers

Tags: VB.Net, XML

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</ParameterCode>
      <CurrentReportingPeriodTotal>238270.800</CurrentReportingPeriodTotal>
      <OzoneSeasonToDateTotal/>
      <YearToDateTotal>238270.800</YearToDateTotal>
   </SummaryValueData>
   <DailyTestSummaryData>
         <UnitID>001</UnitID>
         <Date>2009-01-01</Date>
         <Hour>7</Hour>
         <Minute>24</Minute>
         <MonitoringSystemID/>
         <ComponentID>013</ComponentID>
         <TestTypeCode>DAYCAL</TestTypeCode>
         <TestResultCode>PASSED</TestResultCode>
         <SpanScaleCode/>
         <DailyCalibrationData>
            <OnLineOffLineIndicator>1</OnLineOffLineIndicator>
            <UpscaleGasCode>HIGH</UpscaleGasCode>
            <ZeroInjectionDate>2009-01-01</ZeroInjectionDate>
            <ZeroInjectionHour>7</ZeroInjectionHour>
            <ZeroInjectionMinute>22</ZeroInjectionMinute>
            <UpscaleInjectionDate>2009-01-01</UpscaleInjectionDate>
            <UpscaleInjectionHour>7</UpscaleInjectionHour>
            <UpscaleInjectionMinute>24</UpscaleInjectionMinute>
            <ZeroMeasuredValue>0.000</ZeroMeasuredValue>
            <UpscaleMeasuredValue>2.600</UpscaleMeasuredValue>
            <ZeroAPSIndicator>0</ZeroAPSIndicator>
            <UpscaleAPSIndicator>0</UpscaleAPSIndicator>
            <ZeroCalibrationError>0.00</ZeroCalibrationError>
            <UpscaleCalibrationError>2.50</UpscaleCalibrationError>
            <ZeroReferenceValue>0.000</ZeroReferenceValue>
            <UpscaleReferenceValue>2.500</UpscaleReferenceValue>
         </DailyCalibrationData>
   </DailyTestSummaryData>
   <DailyTestSummaryData>
         <UnitID>001</UnitID>
         <Date>2009-01-01</Date>
         <Hour>7</Hour>
         <Minute>25</Minute>
         <MonitoringSystemID/>
         <ComponentID>013</ComponentID>
         <TestTypeCode>INTCHK</TestTypeCode>
         <TestResultCode>PASSED</TestResultCode>
         <SpanScaleCode/>
   </DailyTestSummaryData>
    <HourlyOperatingData>
         <UnitID>001</UnitID>
         <Date>2009-03-20</Date>
         <Hour>15</Hour>
         <OperatingTime>1.00</OperatingTime>
         <HourLoad>90</HourLoad>
         <LoadUnitsOfMeasureCode>MW</LoadUnitsOfMeasureCode>
         <LoadRange>9</LoadRange>
         <CommonStackLoadRange/>
         <FcFactor>1840.0</FcFactor>
         <FdFactor/>
         <FwFactor/>
         <FuelCode/>
         <MonitorHourlyValueData>
            <ParameterCode>CO2C</ParameterCode>
            <UnadjustedHourlyValue>12.700</UnadjustedHourlyValue>
            <AdjustedHourlyValue/>
            <MODCCode>01</MODCCode>
            <MonitoringSystemID>104</MonitoringSystemID>
            <ComponentID>014</ComponentID>
            <PercentAvailable>86.8</PercentAvailable>
            <MoistureBasis/>
         </MonitorHourlyValueData>
         <MonitorHourlyValueData>
            <ParameterCode>FLOW</ParameterCode>
            <UnadjustedHourlyValue>15177000.000</UnadjustedHourlyValue>
            <AdjustedHourlyValue>15420000.000</AdjustedHourlyValue>
            <MODCCode>01</MODCCode>
            <MonitoringSystemID>103</MonitoringSystemID>
            <ComponentID>013</ComponentID>
            <PercentAvailable>99.9</PercentAvailable>
            <MoistureBasis/>
         </MonitorHourlyValueData>
         <MonitorHourlyValueData>
            <ParameterCode>NOXC</ParameterCode>
            <UnadjustedHourlyValue>107.900</UnadjustedHourlyValue>
            <AdjustedHourlyValue/>
            <MODCCode>01</MODCCode>
            <MonitoringSystemID/>
            <ComponentID>015</ComponentID>
            <PercentAvailable/>
            <MoistureBasis/>
         </MonitorHourlyValueData>
         <MonitorHourlyValueData>
            <ParameterCode>SO2C</ParameterCode>
            <UnadjustedHourlyValue>51.800</UnadjustedHourlyValue>
            <AdjustedHourlyValue>51.800</AdjustedHourlyValue>
            <MODCCode>01</MODCCode>
            <MonitoringSystemID>102</MonitoringSystemID>
            <ComponentID>012</ComponentID>
            <PercentAvailable>86.8</PercentAvailable>
            <MoistureBasis/>
         </MonitorHourlyValueData>
         <DerivedHourlyValueData>
            <ParameterCode>CO2</ParameterCode>
            <UnadjustedHourlyValue/>
            <AdjustedHourlyValue>111.6000</AdjustedHourlyValue>
            <MODCCode/>
            <MonitoringSystemID/>
            <FormulaIdentifier>401</FormulaIdentifier>
            <PercentAvailable/>
            <OperatingConditionCode/>
            <SegmentNumber/>
            <FuelCode/>
         </DerivedHourlyValueData>
         <DerivedHourlyValueData>
            <ParameterCode>HI</ParameterCode>
            <UnadjustedHourlyValue/>
            <AdjustedHourlyValue>1064.3000</AdjustedHourlyValue>
            <MODCCode/>
            <MonitoringSystemID>104</MonitoringSystemID>
            <FormulaIdentifier>801</FormulaIdentifier>
            <PercentAvailable/>
            <OperatingConditionCode/>
            <SegmentNumber/>
            <FuelCode/>
         </DerivedHourlyValueData>
         <DerivedHourlyValueData>
            <ParameterCode>NOXR</ParameterCode>
            <UnadjustedHourlyValue>0.187</UnadjustedHourlyValue>
            <AdjustedHourlyValue>0.1870</AdjustedHourlyValue>
            <MODCCode>01</MODCCode>
            <MonitoringSystemID>105</MonitoringSystemID>
            <FormulaIdentifier>501</FormulaIdentifier>
            <PercentAvailable>78.4</PercentAvailable>
            <OperatingConditionCode/>
            <SegmentNumber/>
            <FuelCode/>
         </DerivedHourlyValueData>
         <DerivedHourlyValueData>
            <ParameterCode>SO2</ParameterCode>
            <UnadjustedHourlyValue/>
            <AdjustedHourlyValue>132.6000</AdjustedHourlyValue>
            <MODCCode/>
            <MonitoringSystemID/>
            <FormulaIdentifier>201</FormulaIdentifier>
            <PercentAvailable/>
            <OperatingConditionCode/>
            <SegmentNumber/>
            <FuelCode/>
         </DerivedHourlyValueData>
   </HourlyOperatingData>
   <HourlyOperatingData>
         <UnitID>001</UnitID>
         <Date>2009-03-31</Date>
         <Hour>23</Hour>
         <OperatingTime>1.00</OperatingTime>
         <HourLoad>89</HourLoad>
         <LoadUnitsOfMeasureCode>MW</LoadUnitsOfMeasureCode>
         <LoadRange>9</LoadRange>
         <CommonStackLoadRange/>
         <FcFactor>1840.0</FcFactor>
         <FdFactor/>
         <FwFactor/>
         <FuelCode/>
         <MonitorHourlyValueData>
            <ParameterCode>NOXC</ParameterCode>
            <UnadjustedHourlyValue>108.800</UnadjustedHourlyValue>
            <AdjustedHourlyValue/>
            <MODCCode>01</MODCCode>
            <MonitoringSystemID/>
            <ComponentID>015</ComponentID>
            <PercentAvailable/>
            <MoistureBasis/>
          </MonitorHourlyValueData>
          <MonitorHourlyValueData>
            <ParameterCode>SO2C</ParameterCode>
            <UnadjustedHourlyValue>57.000</UnadjustedHourlyValue>
            <AdjustedHourlyValue>57.000</AdjustedHourlyValue>
            <MODCCode>01</MODCCode>
            <MonitoringSystemID>102</MonitoringSystemID>
            <ComponentID>012</ComponentID>
            <PercentAvailable>86.8</PercentAvailable>
            <MoistureBasis/>
          </MonitorHourlyValueData>
          <DerivedHourlyValueData>
            <ParameterCode>SO2</ParameterCode>
            <UnadjustedHourlyValue/>
            <AdjustedHourlyValue>144.2000</AdjustedHourlyValue>
            <MODCCode/>
            <MonitoringSystemID/>
            <FormulaIdentifier>201</FormulaIdentifier>
            <PercentAvailable/>
            <OperatingConditionCode/>
            <SegmentNumber/>
            <FuelCode/>
         </DerivedHourlyValueData>
      </HourlyOperatingData>
</Emissions>
[+][-]04/28/09 01:11 PM, ID: 24254728Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04/29/09 08:49 AM, ID: 24261788Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/29/09 02:24 PM, ID: 24264951Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/29/09 04:08 PM, ID: 24265573Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/29/09 04:16 PM, ID: 24265617Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04/30/09 11:53 AM, ID: 24273187Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/04/09 09:35 AM, ID: 24296749Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05/14/09 09:30 AM, ID: 24386671Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: .Net Application Servers
Tags: VB.Net, XML
Sign Up Now!
Solution Provided By: abcserve
Participating Experts: 2
Solution Grade: A
 
[+][-]05/14/09 11:03 AM, ID: 24387606Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 - Hierarchy / EE_QW_3_20080625