INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

XML Parsing - Cant read attribute line.

XML Parsing - Cant read attribute line.

(OP)
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
Test = reader.GetAttribute("MDID")
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close