Results 1 to 3 of 3

Thread: [2008] XmlReader

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    [2008] XmlReader

    Hi!!!

    I have this Xml File:
    HTML Code:
    <?xml version="1.0" encoding="utf-8"?>
    <Sudoku>
        <Casa name="A1">1</Casa>
        <Casa name="C1">7</Casa>
        <Casa name="H1">2</Casa>
        <Casa name="A2">8</Casa>
        <Casa name="B2">2</Casa>
        <Casa name="F2">9</Casa>
        <Casa name="H2">1</Casa>
        <Casa name="C3">9</Casa>
        <Casa name="F3">2</Casa>
        <Casa name="G3">5</Casa>
        <Casa name="A4">5</Casa>
        <Casa name="D4">2</Casa>
        <Casa name="F4">8</Casa>
        <Casa name="H4">3</Casa>
        <Casa name="B6">1</Casa>
        <Casa name="D6">7</Casa>
        <Casa name="F6">5</Casa>
        <Casa name="I6">2</Casa>
        <Casa name="C7">5</Casa>
        <Casa name="D7">8</Casa>
        <Casa name="G7">2</Casa>
        <Casa name="B8">3</Casa>
        <Casa name="D8">1</Casa>
        <Casa name="H8">5</Casa>
        <Casa name="I8">4</Casa>
        <Casa name="B9">7</Casa>
        <Casa name="G9">6</Casa>
        <Casa name="I9">3</Casa>
    </Sudoku>
    Which I want to read. I have this code:
    Code:
                Using SudokuReader As XmlReader = XmlReader.Create(Path)
                    While SudokuReader.Read
                        SudokuReader.ReadToFollowing("Casa")
                        MsgBox(SudokuReader.GetAttribute("name"))
                        MsgBox(SudokuReader.ReadElementContentAsString)
                    End While
                End Using
    Which works good from the exception that It jumps I mean it reads A1 but it then goes right to H1 without reading the C1. Why?

    PS: the MsgBoxes are just to for the post the original code is diferent
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: [2008] XmlReader

    If you take a look at the documentation for the XmlReader.ReadToFollowing method, it contains an example that suggests to me that you should be calling ReadToFollowing once only, then calling ReadToNextSibling inside the loop.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: [2008] XmlReader

    try this. it is possible to achieve what you wanted using ReadToFollowing

    vb Code:
    1. Using SudokuReader As XmlReader = XmlReader.Create(Path)
    2.     While Not SudokuReader.EOF
    3.  
    4.          SudokuReader.ReadToFollowing("Casa")
    5.          If SudokuReader.GetAttribute("name") = String.Empty Then
    6.              Exit While
    7.          End If
    8.          MsgBox(SudokuReader.GetAttribute("name"))
    9.          MsgBox(SudokuReader.ReadElementContentAsString)
    10.  
    11.     End While
    12. End Using
    Last edited by .paul.; Sep 14th, 2008 at 09:56 PM.

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