Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Parsing - Cant read attribute line.

Status
Not open for further replies.

coorsman

Technical User
Nov 25, 2008
1,113
US
Hi All,

I'm reading in an XML file from one of our customers.
Everything reads in ok but I can't get a field that is an attribute.

The attribute is MDID = 4 just above the #text - Brushetta item.

This is some of my code.

If FileNameToOpen1 = "" Then
FileNameToOpen1 = "c:\users\kevin\desktop\Invoice.XML"
FileNameToOpen2 = "c:\users\kevin\desktop\I-draft.CSV"
End If

Dim reader As New XmlTextReader(FileNameToOpen1)
FileOpen(2, FileNameToOpen2, OpenMode.Output)

' parse the XML file
IsTime = 0
HereWeGo = 0
IsCategory = 0
IsDivision = 0
While reader.Read()
Select Case reader.NodeType
Case XmlNodeType.Element

Select Case reader.Name

Case "InvoiceDetail" ' this fileld is the beginning of the invoice.
Console.WriteLine(reader.Name)
ISInvoice = 1 ' it's and invoce.
HereWeGo = 1 ' go get the invoice.
Exit Select
Case "Description"
Console.WriteLine(reader.Name)
If HereWeGo Then IsDescription = 1 ' get the item
Exit Select
Case "MDID"
Stop

Case "Division" ' get the division
IsDivision = 1
Exit Select
Case "Quantity" ' get the Quantity sold
IsQuantity = 1
Exit Select
Case "TimeOrdered" ' get the time.
IsTime = 1
Exit Select
Case "FoodCost" ' get the time.
IsFoodCost = 1
Exit Select

Case "Discount" ' its a discount :( skip it
HereWeGo = 0 ' skip parsing
Case "MealType" ' all done with this check.
HereWeGo = 1 ' end of the fields so reset for parsing.
ISInvoice = 1

'Case "FiscalDate"
' FiscalDate = 1
Case Else
Console.WriteLine(reader.Name)

IsTime = 0
End Select

Case XmlNodeType.Text

If HereWeGo Then
If IsDescription Then
[highlight #FCE94F]Test = reader.GetAttribute("MDID")[/highlight]
Items = reader.Value
IsDescription = 0 ' get the item description.
End If
If IsDivision Then Division = reader.Value : IsDivision = 0 ' get the division for this item.
If IsMode Then Mode = reader.Value : IsMode = 0 ' get the mode for this item.
If IsQuantity Then Quantity = reader.Value : IsQuantity = 0 ' get the quantity
If IsFoodCost Then FoodCost = reader.Value : IsFoodCost = 0
If IsTime Then
TimeOrdered = reader.Value
TimeOrdered = 0
IsTime = 0 'reset
ISInvoice = 0 'reset
IsMode = 0
IsDescription = 0 'reset
End If

End If
Exit Select

Case XmlNodeType.EndElement
Exit Select
End Select
End While
End Sub
End Module


Cheers,
Coorsman

 
 http://files.engineering.com/getfile.aspx?folder=b86ddd7e-2f05-4fd0-b0fc-71395499f9e8&file=Screenshot_-_1_18_2017_,_2_49_22_PM.png
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top