NewsFeed   -
KỸ THUẬT LẬP TRÌNH
S  M  L
Create - Read - Write XML file - VB
'Create XML file, add element to existing file:

Dim strFile = Server.MapPath("YouTube.xml")
        If Not File.Exists(strFile) Then
            Dim writer As New XmlTextWriter(strFile, System.Text.Encoding.UTF8)
            writer.WriteStartDocument(True)
            writer.Formatting = Formatting.Indented
            writer.Indentation = 2
            writer.WriteStartElement("Table")
            createNode(txtYouTubeLink.Text, writer)
            'createNode(2, "Product 2", "2000", writer)
            writer.WriteEndElement()
            writer.WriteEndDocument()
            writer.Close()
            lblYoutubeMessage.Text = "Successfully Created!"

        Else

            Dim myXmlDocument As XmlDocument = New XmlDocument()
            myXmlDocument.Load(strFile)

            Dim rootNode As XmlElement = myXmlDocument.DocumentElement("YouTube")
            Dim newAppPathElement As XmlElement = myXmlDocument.CreateElement("webLink")
            newAppPathElement.InnerXml = txtYouTubeLink.Text
            rootNode.AppendChild(newAppPathElement)

            myXmlDocument.Save(strFile)
            myXmlDocument = Nothing

       End If

-- READ XML File to display:
Try
                Dim m_xmlr As XmlTextReader
                'Create the XML Reader
                Dim strFile = Server.MapPath("YouTube.xml")
                Dim ThisLink As String = ""
                m_xmlr = New XmlTextReader(strFile)

                'Disable whitespace so that you don't have to read over whitespaces
                m_xmlr.WhitespaceHandling = WhitespaceHandling.None
                'read the xml declaration and advance to family tag

                m_xmlr.Read() 'read the family tag
                m_xmlr.Read() 'Load the Loop

                While Not m_xmlr.EOF
                    'Go to the name tag
                    m_xmlr.Read()
                    'if not start element exit while loop
                    If Not m_xmlr.IsStartElement() Then
                        Exit While
                    End If

                    Dim ColumnAttribute = m_xmlr.GetAttribute("Youtube")

                    m_xmlr.Read()

                    ThisLink = m_xmlr.ReadElementString("webLink")
                    If ThisLink <> "" Then Exit While
                End While
                'close the reader
                m_xmlr.Close()

                If ThisLink <> "" Then
                    litYouTube.Text = GetYouTubeScript(ThisLink)
                Else
                    litYouTube.Text = ""
                End If
            Catch
            End Try
- 06/18/2011
Search:
NGHỆ THUẬT - PHIM - ẢNH

HÌNH ẢNH ĐẸP

Photo

Album: Royal Wedding
< August 2011 >
Sun Mon Tue Wed Thu Fri Sat
31 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 1 2 3
4 5 6 7 8 9 10
More... (All Collections)
H2O NEWS

Everything Meaning To You!

Email: [email protected]

Website: emty.org

Liên hệ

Đặt làm trang chủ

@