XML and VB.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cday119
    New Member
    • Mar 2008
    • 29

    XML and VB.net

    I have an XML document formatted like so:

    Code:
    <?xml version="1.0"?>
    <BadgeOrders>
      <Order Ordernum="HOL090122114802" OrderDate="1/22/2009 11:48:02 AM">
        <Contact>
          <PersonOrdering>Test1</PersonOrdering>
          <PhoneNumber>Test Phone</PhoneNumber>
          <FaxNumber></FaxNumber>
          <Email>test1@test</Email>
          <StoreNumber></StoreNumber>
        </Contact>
        <Badge BadgeNbr="1">
          <Line1>rety</Line1>
          <PinQuantity>1</PinQuantity>
          <MagQuantity>2</MagQuantity>
          <Price>12.85</Price>
        </Badge>
        <Badge BadgeNbr="2">
          <Line1>rety</Line1>
          <PinQuantity>1</PinQuantity>
          <MagQuantity>2</MagQuantity>
          <Price>10.00</Price>
        </Badge>
        <TotalPrice>$22.85</TotalPrice>
        <SpecialInstructions></SpecialInstructions>
      </Order> 
    </BadgeOrders>
    Im trying to get the Line1 of each Badge and also the sum of PinQuantity and MagQuantity. Then wright Line1 with a streamwriter. I want to take the sum and wright Line1 that number of times. I've been trying to look for the best way to do this and the only ways I found I feel are wrong. Im using VB.net and .net version 2

    Heres the code that Ive come up with,

    Code:
            Dim xmlString As String = ftpsr.ReadToEnd
                
            Dim xmlDataDoc As XmlDocument = New XmlDocument
    
            xmlDataDoc.LoadXml(xmlString)
    I havent done anything with XML and Vb.net.

    THANKS A TON
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    I think your best bet is to use selectSingleNod e(xpath) function. Get the 2 nodes this way, and then use the value function to get the values of the nodes before adding. eg:
    Code:
    xmlDataDoc.selectSingleNode("//Badge[@BadgeNbr=1]/PinQuantity");
    Note the use of braces[] for a conditional find.

    Comment

    Working...