.net - Parsing XML using XmlDocument -


i trying parse below xml. have multiple invoice tags:

<invoices>     <invoice>         <invoice_id>1234</invoice_id>         <billing>             <name> abc </name>             <address1>1 main street</address1>             <city> city </city>             <state>state </state             <zip>00000</zip>             <amount>                 <baseamt>35</baseamt>                 <tax>3</tax>                 <total>28<total>             <amount>         </billing>               <item>                  <name> pen </name>                  <qty> 5 </qty>                  <amount> 10 </amount>         </item>          <item>             <name> paper </name>                  <qty> 3 </qty>                  <amount> 20 </amount>         </item>                                          </invoice> </invoices> 

below code :

dim xmldoc xmldocument = new xmldocument() xmldoc.load(filename) dim invnum integer = 0 dim nodelst xmlnodelist = xmldoc.selectnodes("/invoices/invoice") invnum = nodelst.count  each invdetail xmlelement in nodelst     dim invid string = invdetail("invoice_id").innertext.tostring() next 

i need value remaining tags i.e child nodes billing/name , billing/name/amount , items/items/name

if accessing value of direct-child element, invoice_id, can use indexer access child element name, doing, this:

invdetail("invoice_id") 

however, if want go deeper value of lower descendant, can use selectsinglenode or selectnodes access node via xpath. xpath relative current node. instance:

for each invdetail xmlelement in nodelst     dim invid string = invdetail("invoice_id").innertext     dim name string = invdetail.selectsinglenode("billing/name").innertext     ' etc.     each item xmlelement in invdetail.selectnodes("item")         dim itemname string = item("name").innertext         ' etc.     next next 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -