I have a class project where I am using a VB.Net form to search the XML document based on data entered into a text box and I need to return the values of the other items in the child tags. An example of the XML info is below. In the VB form, the user enters an account number and based on the account number matching one in the XML document, the remainder of the form, name, dob, etc populates form the XML into text boxes.
I’m not sure how to code this. I have attached the XML document to the VB form code with:
Dim doc = XDocument.Load("CreditApp.xml")
Dim xdoc = doc.Descendants("custData").FirstOrDefault()
I have also assigned variables to the text boxes receiving the search input from the user. The search is activated by clicking on a “Search” button in the VB form.
txtAcctNum.Text = xdoc.Element("AcctNum").Value
txtSSN.Text = xdoc.Element("SSN").Value
XML Sample:
<custData>
<FName>Ben</FName>
<LName>Dover</LName>
<Gender>Male</Gender>
<Address>21 Jump Street</Address>
<City>Beverly Hills</City>
<State>CA</State>
<Zip>90210</Zip>
<Phone>3108591212</Phone>
<Email>yourex@stalkermail.com</Email>
<SSN>000001233</SSN>
<AcctNum>5695847185978954</AcctNum>
<PassCode>What</PassCode>
<AccountAvail>75000</AccountAvail>
<AcctBal>25000</AcctBal>
<LPmtDate>3/28/2012</LPmtDate>
<LPmtAmt>7500</LPmtAmt>
<CreditLimit>100000</CreditLimit>
<IntRate>15.499</IntRate>
<MinPayment>1250</MinPayment>
<PmtDueDate>4/28/2012</PmtDueDate>
<Note></Note>
</custData>
<custData>
<FName>Al</FName>
<LName>Caholic</LName>
<Gender>Male</Gender>
<Address>8585 Milky Way</Address>
<City>Palm Springs</City>
<State>CA</State>
<Zip>90561</Zip>
<Phone>2029867411</Phone>
<Email>screaming@silentmail.com</Email>
<SSN>951855589</SSN>
<AcctNum>9812020274912689</AcctNum>
<PassCode>Glover</PassCode>
<AccountAvail>0</AccountAvail>
<AcctBal>55000</AcctBal>
<LPmtDate>4/1/2012</LPmtDate>
<LPmtAmt>15</LPmtAmt>
<CreditLimit>55000</CreditLimit>
<IntRate>18.995</IntRate>
<MinPayment>95000</MinPayment>
<PmtDueDate>5/1/2012</PmtDueDate>
<Note></Note>
</custData>
Any help would be great!
Try using xml to linq i think it would work good for you
/// custDtatas it the top wrapping element of the whole document yours can be different