Jump to content

[VB.NET 2005] Acesso e manipulação de files XML


AriOps
 Share

Recommended Posts

Boas,

Estou a criar uma aplicação em vb.net 2005 e surgiu a necessidade de desenvolver  um  sistema de profiles. Pensei logo em usar XML por pensar ser a mais funcional e também porque gostava de aprender a trabalhar com estes ficheiros. Já criei um ficheiro XML, agora o que eu não sei é:

- Como aceder

- Como manipular

Se alguém pudesse ajudar agradecia, também já vi o Nazgulled a falar sobre isto algures :)

Cumps

Daniel Correia

Link to comment
Share on other sites

alguns exemplos usando o SYSTEM.XML

system.xml

    'Reading xml
    Private Sub Read_XML()
        Dim XMLReader As Xml.XmlReader
        XMLReader = New Xml.XmlTextReader("List.xml")
        While XMLReader.Read
            Select Case XMLReader.NodeType
                Case Xml.XmlNodeType.Element
                    If XMLReader.AttributeCount > 0 Then
                        While XMLReader.MoveToNextAttribute
                            If XMLReader.Name = "File" Then
                                ListBox1.Items.Add(XMLReader.Value)
                            ElseIf XMLReader.Name = "Title" Then
                                ListBox2.Items.Add(XMLReader.Value)
                            Else
                                ' Do Nothing
                            End If
                        End While
                    End If
            End Select
        End While
        XMLReader.Close()
    End Sub


    'Writing xml
    Private Sub Write_XML()
        Dim XMLobj As Xml.XmlTextWriter
        Dim ue As New System.[Text].UnicodeEncoding()
        XMLobj = New Xml.XmlTextWriter("List.xml", ue)

        XMLobj.Formatting = Xml.Formatting.Indented
        XMLobj.Indentation = 3
        XMLobj.WriteStartDocument()

        XMLobj.WriteStartElement("List")

        Dim i As Integer
        For i = 0 To ListBox1.Items.Count - 1
            XMLobj.WriteStartElement("MP3_File")
            Dim temp As String = ""
            Dim temp1 As String = ""
            ListBox1.SetSelected(i, True)
            ListBox2.SetSelected(i, True)
            temp = ListBox1.SelectedItem
            temp1 = ListBox2.SelectedItem
            XMLobj.WriteAttributeString("File", temp)
            XMLobj.WriteAttributeString("Title", temp1)
            XMLobj.WriteEndElement()
        Next
        XMLobj.WriteEndElement()
        XMLobj.Close()
    End Sub
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.