For example I have string value like this:

    <?xml version="1.0"?>
           <Product type="Condom">
                <CondomName>durex</CondomName>
                <ExpDate>False</ExpDate>
                <Type>False</Type>
                <Color>False</Color>
                <Qty>False</Qty>
            </Product>

Since this this is a string value, so we need to convert to xml node to be able to process.
So this is the code:

        Imports System.Xml
        Imports System.Xml.Serialization

        Dim xmlNodeList As System.Xml.XmlNodeList
        Dim xmlNode As System.Xml.XmlNode
        Dim XmlDoc As New XmlDocument

	Dim _condomName as String
	Dim _ExpDate as String
	Dim _Type as String
	Dim _color as String
	Dim _qty as String

        XmlDoc.LoadXml(result)
	'Select the 1st Xml Element
        xmlNodeList = XmlDoc.GetElementsByTagName("Product")
	'Because only 1 Product Element, so select index by 0
        xmlNode = xmlNodeList.Item(0)

        _condomName = xmlNode.SelectSingleNode("CondomName").InnerText
        _ExpDate = xmlNode.SelectSingleNode("ExpDate").InnerText
        _Type = xmlNode.SelectSingleNode("Type").InnerText
        _color = xmlNode.SelectSingleNode("Color").InnerText
        _qty = False 'xmlNode.SelectSingleNode("Qty").InnerText

If you have more than 1 product, you need to loop the xmlList:

For Each xmlNode As XmlNode In xmlNodeList
        _condomName = xmlNode.SelectSingleNode("CondomName").InnerText
        _ExpDate = xmlNode.SelectSingleNode("ExpDate").InnerText
        _Type = xmlNode.SelectSingleNode("Type").InnerText
        _color = xmlNode.SelectSingleNode("Color").InnerText
        _qty = False 'xmlNode.SelectSingleNode("Qty").InnerText
Next

  • Share/Bookmark