วันอาทิตย์ที่ 20 กันยายน พ.ศ. 2558

การใช้ XMLDocument เพื่อเรียกค่าข้อมูลในรูปแบบ XML

Imports System.Xml
----------------------------------------------------------------------------------------------------------
Function doGetXML(AuctionNote_reply As String) As String
        Dim xml As String = <replys>
                                <reply id='1'>
                                    <img>aaaa@gmail.com</img>
                                    <usertype>ลูกค้า</usertype>
                                    <curdate>2014-09-22 20:54:17.460</curdate>
                                    <detial>ค่ะ ขอบคุณค่ะ ส่งให้ทางไหนค่ะ คือ เพิ่งใช้ระบบนี้เหมือนกันค่ะ</detial>
                                </reply>
                                <reply id='2'>
                                    <img>bbbb@hotmail.com</img>
                                    <usertype>นักแปล</usertype>
                                    <curdate>2014-09-22 20:54:17.460</curdate>
                                    <detial>ขอบคุณที่ไว้วางใจครับ</detial>
                                </reply>
                            </replys>

        Dim doc As New XmlDocument
        doc.LoadXml(xml)

        Dim node As XmlNode = doc.SelectSingleNode("replys")
        If node IsNot Nothing Then
            Dim addStatus As String = node.InnerText.Trim()
            Dim addNode As XmlNode = doc.SelectSingleNode("replys")
            Dim htmlX As New StringBuilder

            For Each ele As XmlElement In addNode.ChildNodes
                Dim img As String = ele.SelectSingleNode("img").InnerText   'ele.InnerText
                Dim detial As String = ele.SelectSingleNode("detial").InnerText
                Dim usertype As String = ele.SelectSingleNode("usertype").InnerText
                Dim curdate As String = ele.SelectSingleNode("curdate").InnerText
            Next

        End If
    End Function

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

การใช้ WebClient สำหรับเรียก URL

Dim _url As String = " https :// www . MyDomain . com /?q=ทดสอบ " Dim wc As New System . Net . WebClient () wc . Encodin...