Parse xml (having namespace) using linq to xml

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
hello,
i have restful web service and its output is this. i want to parse this xml using linq to xml.
but if i remove namespaces from <invoices> tag its working fine otherwise it return nothing. could u please suggest me where i m make mistake. below is xml and code.
<span style="color:#0000ff <span><?<span>xml version="1.0" encoding="UTF-8" standalone="yes"
<span>?>

<div style="text-indent:-2em http://ds9.ceclabs.com:30000/invoices# <span style="font-family:Courier New; color:#ff0000 -
<span><span style="color:#0000ff <<span><span style="color:#990000 invoices<span><span style="color:#ff0000 xmlns<span><span style="color:#0000ff = <span style="color:#ff0000 http://www.test.com/model/1.0 http://www.test.com/model/1.0 <span style="color:#0000ff <span> <span>>


<div style="text-indent:-2em http://ds9.ceclabs.com:30000/invoices# <span style="font-family:Courier New; color:#ff0000 -
<span><span style="color:#0000ff <<span><span style="color:#990000 invoice<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 accountReference<span><span style="color:#0000ff ><span> 1234567890 <span><span style="color:#0000ff </<span><span style="color:#990000 accountReference<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 amount<span><span style="color:#0000ff ><span> 15.0 <span><span style="color:#0000ff </<span><span style="color:#990000 amount<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 configurationId<span><span style="color:#0000ff ><span> COM <span><span style="color:#0000ff </<span><span style="color:#990000 configurationId<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 currencyCode<span><span style="color:#0000ff ><span> USD <span><span style="color:#0000ff </<span><span style="color:#990000 currencyCode<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 customerReference<span><span style="color:#0000ff ><span> ORD#12345 <span><span style="color:#0000ff </<span><span style="color:#990000 customerReference<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 description<span><span style="color:#0000ff ><span style="color:#000000 <span> UABC <span><span style="color:#0000ff </<span><span style="color:#990000 description<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 dueDate<span><span style="color:#0000ff ><span> 2011-06-03T06:07:03.161-04:00 <span><span style="color:#0000ff </<span><span style="color:#990000 dueDate<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 id<span><span style="color:#0000ff ><span> 4de8b247fc0fd29af98a226d <span><span style="color:#0000ff </<span><span style="color:#990000 id<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 invoiceDate<span><span style="color:#0000ff ><span> 2011-06-03T06:07:03.161-04:00 <span><span style="color:#0000ff </<span><span style="color:#990000 invoiceDate<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 invoiceReference<span><span style="color:#0000ff ><span> INV#12345 <span><span style="color:#0000ff </<span><span style="color:#990000 invoiceReference<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 invoiceType<span><span style="color:#0000ff ><span> B <span><span style="color:#0000ff </<span><span style="color:#990000 invoiceType<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 paymentTerms<span><span style="color:#0000ff ><span> Due upon receipt <span><span style="color:#0000ff </<span><span style="color:#990000 paymentTerms<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 status<span><span style="color:#0000ff ><span> PENDING <span><span style="color:#0000ff </<span><span style="color:#990000 status<span><span style="color:#0000ff >


<div style="text-indent:-2em <span> <span style="font-family:Courier New; color:#ff0000
<span><span style="color:#0000ff <<span><span style="color:#990000 title<span><span style="color:#0000ff ><span> Buy.com order #12345 <span><span style="color:#0000ff </<span><span style="color:#990000 title<span><span style="color:#0000ff >

<span><span style="color:#0000ff </<span><span style="color:#990000 invoice<span><span style="color:#0000ff >
<span><span style="color:#0000ff <span><span style="color:#0000ff </<span><span style="color:#990000 invoices<span><span style="color:#0000ff >
<span><span style="color:#0000ff <span><span style="color:#0000ff
<span><span style="color:#0000ff <span><span style="color:#0000ff Code:--Linq to xml
<span><span style="color:#0000ff <span>
<span><span style="color:#0000ff <span> <span><span style="color:#0000ff <span><span style="color:#0000ff <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small string<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="color:#000000 strOutput
= e.Result;
<span><span style="color:#0000ff <span> <span><span style="color:#0000ff <span><span style="color:#0000ff <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="color:#000000 <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small XDocument<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
loaded = <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small XDocument<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small .Parse(strOutput);
<span><span style="color:#0000ff <span> <span><span style="color:#0000ff <span><span style="color:#0000ff <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="color:#000000 <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small var<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
q = <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small from<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
c <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small in<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
loaded.Descendants(<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "invoice"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small )
<span><span style="color:#0000ff
<span><span style="color:#0000ff
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small
<span style="color:#000000
<span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small select<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small new<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; color:#2b91af; font-size:x-small Invoice_ItemViewModel<span style="font-family:Consolas; color:#2b91af; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small {
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small Amount = (<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small string<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small )c.Element(<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "amount"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ),
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small Title = (<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small string<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small )c.Element(<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "title"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ),
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small Description = (<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small string<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small )c.Element(<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "description"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ),
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small Status = (<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small string<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small )c.Element(<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "status"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ),
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ConfigurationId = (<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small string<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small )c.Element(<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "configurationId"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ),
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small DueDate = (<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small string<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small )c.Element(<span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small <span style="font-family:Consolas; color:#a31515; font-size:x-small "dueDate"<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small ),
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small };
<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small foreach<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
(<span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small var<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
invoiceinfo <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small <span style="font-family:Consolas; color:#0000ff; font-size:x-small in<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small q)
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small {
<span><span style="color:#0000ff <span><span style="color:#0000ff <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="color:#000000 <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small --Add
element
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small }
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small Please give ur view.thanks in advance.







<span><span style="color:#0000ff <span><span style="color:#0000ff <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span style="color:#000000 <span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small <span><span style="color:#0000ff <span><span style="color:#0000ff
<span><span style="color:#0000ff





<br/>

View the full article
 

Similar threads

A
Replies
0
Views
162
ANIL AYDINALP
A
K
Replies
0
Views
224
Khan345
K
I
Replies
0
Views
153
Innovators World Wide
I
P
Replies
0
Views
126
programmervb.net
P
Back
Top