Need help parsing XML file

o9z

Member
Joined
Aug 8, 2007
Messages
6
Programming Experience
Beginner
I have an XML file that I need to parse to generate a few reports. What needs to be done is pretty simple, but I have no clue where to start with parsing the XML.
The application will do this:
Click a button to browse to an XML file where the format is static. Once the file is loaded, parse the file and generate a report using specific fields from the XML file. Criteria will be based on State(completed or incomplete), activity(Inspection, sample, etc). Here is 1 record of the XML file. Each consecutive record uses the exact same format.
Any gurus that can lead me on the right path would be awesome!

VB.NET:
<AsBuiltXML xmlns:lx="http://www.***.coml" version="1.0" date="10/20/2010" time="8:07:52 AM">
  <Project name="S. 88th Street" desc="" />
 <Units>
  <Imperial linearUnit="foot" areaUnit="squareFoot" volumeUnit="cubicYard" angularUnit="radians" />
  </Units>
  <Application name="OnS" manufacturer="BSI" version="1.0" manufacturerURL="www.***.com" />
 <AsBuiltRecords>
 <AsBuiltRecord InternalUniqueId="1" UserName="Administrator" Time="10/7/2010 9:19:29 AM" State="Completed" Activity="Inspection" GeometryType="Point">
 <Coord>
  <X>1552039.24697401</X>
  <Y>559892.526462774</Y>
  <Z>930.565482293085</Z>
  </Coord>
 <SurveyInstrumentType Name="Instrument Type">
  <SurveyInstrumentValue>GPS</SurveyInstrumentValue>
  </SurveyInstrumentType>
 <MeasureStation_and_Offset Name="Station - Offset">
  <StationLabel>Sta =</StationLabel>
  <StationValue>2963+04.79</StationValue>
  <OffsetLabel>Off =</OffsetLabel>
  <OffsetValue>-54.6515987541061</OffsetValue>
  <AlignmentLabel>Alg =</AlignmentLabel>
  <NameValue>88TH</NameValue>
  </MeasureStation_and_Offset>
 <ShotInfoSatteliteNumber Name="Satellites Number [1]">
  <CountValue>10</CountValue>
  </ShotInfoSatteliteNumber>
 <ShotInfoSolutionType Name="Solution Type [1]">
  <SolutionTypeValue>Fixed</SolutionTypeValue>
  </ShotInfoSolutionType>
 <ShotInfoHorizontalAccuracy Name="Horizontal Accuracy [1]">
  <AccuracyValue>N/A</AccuracyValue>
  </ShotInfoHorizontalAccuracy>
 <ShotInfoVerticalAccuracy Name="Vertical Accuracy [1]">
  <AccuracyValue>N/A</AccuracyValue>
  </ShotInfoVerticalAccuracy>
 <ShotInfoRodHeight Name="Rod Height [1]">
  <HeightValue>6</HeightValue>
  </ShotInfoRodHeight>
 <ShotInfoPDOP Name="PDOP [1]">
  <X_DOPValue>1.70</X_DOPValue>
  </ShotInfoPDOP>
 <TotalCountType Name="Total Count">
  <CountValue>1</CountValue>
  </TotalCountType>
 <ActiveAlignmentInfo Name="Active Align">
  <NameValue>88TH</NameValue>
  <StationLabel>Sta:</StationLabel>
  <StationValue>2963+04.79</StationValue>
  <OffsetLabel>Off:</OffsetLabel>
  <OffsetValue>-54.65</OffsetValue>
  </ActiveAlignmentInfo>
  </AsBuiltRecord>

vb.net code:
VB.NET:
        Dim filtStr As String
        filtStr = Me.cboFilter.Text
        OpenFileDialog1.ShowDialog()
        Dim filePath As String
        filePath = OpenFileDialog1.FileName

        dsXML.ReadXml(filePath)

        With (dgvTest)
            .DataSource = dsXML
            .DataMember = "AsBuiltRecord"
        End With

My DS is declared elsewhere.

Now looking at the XML, the following code returns in my DataGridView just the data in the AsBuiltRecord area. (ID, username, Time, and State). None of the rest appears. I want to include everything, including the Coords, InstrumentType, MeasureStation, etc. Is there an easy way to handle this in one DS?
 
All of the information is already in 1 DataSet.

VB.NET:
        Dim ds As New DataSet
        ds.ReadXml("C:\Temp\AsBuilt.xml")

        DataGridView1.DataSource = ds.Tables("AsBuiltXML")
        DataGridView2.DataSource = ds.Tables("Project")
        DataGridView3.DataSource = ds.Tables("AsBuiltRecord")

Put a break point in after the ReadXml call and hover your mouse over dsXML. Click on the magnifying glass to open the DataSet Visualizer then click on the Table drop down to navigate all of the DataTables that were created for you.
 
Is the easiest thing to do just to do a merge?

Something like this?

VB.NET:
        dsXML.Tables(0).Merge(dsXML.Tables(1))
        dt = dsXML.Tables(0)

I am not sure how I would merge the 20+ tables though.
 
Back
Top