Results 1 to 3 of 3

Thread: [RESOLVED] Read XML

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Location
    Devon - UK
    Posts
    214

    Resolved [RESOLVED] Read XML

    HTML Code:
     <way id='27004700' >
        <nd ref='296002937' />
        <nd ref='296003910' />
        <nd ref='296003911' />
        <nd ref='296003912' />
        <nd ref='296003913' />
        <nd ref='296003914' />
        <nd ref='296003916' />
          <tag k='wires' v='single' />
        <tag k='cables' v='3' />
        <tag k='power' v='line' />
      </way>
    I'm reading an XML file using a XmlTextReader:-

    HTML Code:
      Dim strDir As String = "d:\map.osm"
                Dim xReader As XmlTextReader = New XmlTextReader(strDir)
    
               Do While xReader.Read()
    
                Select Case xReader.Name
    
                   case "way"
    How do I read all the nd refs and tags for the way?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,423

    Re: Read XML

    you can read your xml with LINQ:

    vb Code:
    1. Dim xml As XDocument = XDocument.Parse(IO.File.ReadAllText("xml3.txt"))
    2. Dim values = (From item In xml...<way> _
    3.               Select New With { _
    4.               .id = item.Attribute("id").Value, _
    5.               .refs = (From a In item...<nd>.Attributes("ref") _
    6.                       Select a.Value).ToArray, _
    7.               .k = (From a In item...<tag>.Attributes("k") _
    8.                       Select a.Value).ToArray, _
    9.               .v = (From a In item...<tag>.Attributes("v") _
    10.                       Select a.Value).ToArray}).ToList
    11.  
    12. For Each v In values
    13.     Debug.Print(v.id & Environment.NewLine & String.Join(",", v.refs) & Environment.NewLine & String.Join(",", v.k) & Environment.NewLine & String.Join(",", v.v) & Environment.NewLine)
    14. Next

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Location
    Devon - UK
    Posts
    214

    Re: Read XML

    Great - that did it thanks very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width