Issue to read some part of XML file.
Here is my XML file:
<Report>
<orders>
<order savedby="manager" time="12:33:09">
<header saledate="04/Oct/2013" saletime="12:33:09" reqtime="12:33:09" />
<customer name="-" accname="123465" />
<payments>
<payment transid="1" method="7" vposuser="manager" cardtype="" value="2.95"></payment>
</payments>
<totals deliverycharge="" splitdelchgstore="" splitdelchgdriver="" sercharge="0.00" />
<products>
<product type="cookbook" qty="1" prodid="10000564" listprice="0.00" sellprice="10.00">
<stock />
<vat />
<discount>
<discountitem discvalue="10.00" name="Quick On Screen Discount" />
</discount>
</product>
<product type="" qty="1" description="Crispy Fries" prodid="10000093" listprice="0.00" sellprice="2.95">
<stock />
<vat />
<discount />
</product>
</products>
</order>
<orders>
<order savedby="manager" time="12:33:09">
<header saledate="04/Oct/2013" saletime="12:33:09" reqtime="12:33:09" />
<customer name="-" accname="123465" />
<payments>
<payment transid="1" method="7" vposuser="manager" cardtype="" value="2.95"></payment>
</payments>
<totals deliverycharge="" splitdelchgstore="" splitdelchgdriver="" sercharge="0.00" />
<products>
<product type="cookbook" qty="1" prodid="10000564" listprice="0.00" sellprice="10.00">
<stock />
<vat />
<discount>
<discountitem discvalue="10.00" name="Quick On Screen Discount" />
</discount>
</product>
<product type="" qty="1" description="Crispy Fries" prodid="10000093" listprice="0.00" sellprice="2.95">
<stock />
<vat />
<discount />
</product>
</products>
</order>
</orders>
</Report>
I need to get access to:
1) <header saledate="04/Oct/2013" saletime="12:33:09" reqtime="12:33:09" />
2) <customer name="-" accname="123465" />
3) <payment transid="1" method="7" vposuser="manager" cardtype="" value="2.95">
However code that I have cannot read the PAYMENT value, it's empty instead. Here is the code:
Can you help me? This is first time that I am reading XML this way.
Dim settings1 As New XmlReaderSettings()
settings1.ConformanceLevel = ConformanceLevel.Fragment
settings1.IgnoreWhitespace = True
settings1.IgnoreComments = True
Dim reader1 As XmlReader = XmlReader.Create(filePath, settings1)
Dim tempOrderNumber As String = Nothing
While reader1.Read()
Select Case reader1.NodeType
Case XmlNodeType.Element
If reader1.Name = "order" Then
Dim reader2 As XmlReader = reader1
While reader1.NodeType <> XmlNodeType.EndElement
reader1.Read()
If reader1.Name = "header" Then
salenum = reader1.GetAttribute("ordnum")
temp_salenum = salenum
attendant = reader1.GetAttribute("vposuser")
saledate = reader1.GetAttribute("reqdate")
saletime = reader1.GetAttribute("reqtime")
End If
reader1.Read()
If reader1.Name = "payment" Then
Try
saletotalnat = reader1.GetAttribute("value")
salesubtotalnat = reader1.GetAttribute("value")
paidvalue = FormatNumber(reader1.GetAttribute("value") / VAT, 2)
Catch ex As Exception
End Try
End If
If reader2.NodeType = XmlNodeType.EndElement Then
MsgBox("saledate: " & startdate _
& vbCrLf & "saletime: " & starttime _
& vbCrLf & "sellprice: " & sellprice)
End If
End While
End If
End Select
End While