Results 1 to 3 of 3

Thread: Reading XML files

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    108

    Reading XML files

    I am making a program that stores information for my applications. There are 4 main things I need in the XML file, the login information (User name and password), Application names and keys, and the owner of the application (who bought it). The program allows the user to enter as many applications and owners as they want and once login information is correct it loads the data. Then on exit all the data saves to a XML file.

    My XML file looks like this

    <Data>
    <Login>
    <UserName> (UserName) </UserName>
    <Password> (Password </Password>
    </Login>
    <Applications>
    <Name> (Application Name) </Name>
    <Key> (Application Key) </Key>
    <Name> (Application Name) </Name>
    <Key> (Application Key) </Key>
    </Applications>
    <Owners>
    <Name> (Application Owner) </Name>
    <Name> (Application Owner) </Name>
    </Owners>
    </Data>

    I can get the login information to work but I am having trouble with the App Names/Keys and Owners. Here is what I have right now:


    Code:
        Shared Sub LoadData()
    
            ReDim Preserve AppName(AppCount)
            ReDim Preserve AppKey(AppCount)
            ReDim Preserve Owner(OwnerCount)
    
            '//Create XML reader
            Dim DataIn As XmlReader = New XmlTextReader("ProData.xml")
    
            '//Read Application names and keys
            Try
                '//Pass through Login information, is there an easier way to do this?
                DataIn.ReadStartElement()
                DataIn.ReadStartElement()
                DataIn.ReadString()
                DataIn.ReadEndElement()
                DataIn.ReadStartElement()
                DataIn.ReadString()
                DataIn.ReadEndElement()
                DataIn.ReadEndElement()
    
                '//Read Application name and key
                DataIn.ReadStartElement()
                Do Until DataIn.IsStartElement.Equals("Owners")
                    DataIn.ReadStartElement()
                    AppName(AppCount) = DataIn.ReadString()
                    DataIn.ReadEndElement()
                    DataIn.ReadStartElement()
                    AppKey(AppCount) = DataIn.ReadString()
                    DataIn.ReadEndElement()
                    AppCount += 1
                Loop
                DataIn.ReadEndElement()
            Catch
            End Try
    
            '//Read owners
            Try
                Do While DataIn.IsStartElement()
                    DataIn.ReadStartElement()
                    Owner(OwnerCount) = DataIn.ReadString()
                    DataIn.ReadEndElement()
                    OwnerCount += 1
                Loop
            Catch
            End Try
            DataIn.Close()
        End Sub

    Once I read all that the only thing I get is one application and no owners. How do I make it read all of the Apps then stop at the end of the Application Element?

  2. #2
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: Reading XML files

    Do you really want a username or password stored in a plaintext format?
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Posts
    108

    Re: Reading XML files

    No, I'm going to encrypt the whole file. Just for now I want to be able to read it, I'm just testing it for now.

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