我有一个类项目,我使用VB.Net表单根据输入到文本框中的数据搜索XML文档,我需要返回子标记中其他项的值。下面是XML信息的示例。在VB表单中,用户输入一个帐号,并根据XML文档中匹配的帐号,表单,名称,dob等的其余部分填充XML到文本框中。
我不确定如何编码。我已将XML文档附加到VB表单代码:
Dim doc = XDocument.Load("CreditApp.xml")
Dim xdoc = doc.Descendants("custData").FirstOrDefault()
我还为接收用户搜索输入的文本框分配了变量。通过单击VB表单中的“搜索”按钮激活搜索。
txtAcctNum.Text = xdoc.Element("AcctNum").Value
txtSSN.Text = xdoc.Element("SSN").Value
XML示例:
<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>
任何帮助都会很棒!
答案 0 :(得分:1)
尝试使用xml来linq我觉得它对你有用
/// custDtatas它是整个文档的顶部包装元素你可以是不同的
Dim q = (From c In xDoc.Descendants("custDtatas")
From view In c.Elements("custData")
Where view.Element("SSN") = '000001233'
AndAlso view.Element("AcctNum") = '5695847185978954' view).ToList()
// fill the specific part of the form with specific item
For Each item As var In q
Next