Reputation: 4663
I'm pretty new to Linq to SQL & Linq to XML but have cobbled together some code together that put the XML results from a stored proc into an XElement. However, it's started failing, apparently now that the XML data is getting larger (2K+) and my .Parse is reading truncated XML (the XML data comes back in two rows). Before i start fumbling into the weeds using xmlReaders and all that, maybe i'm looking at this wrong and there are better approaches.
My exact problem is below, but i'm also curious about any standard Linq idioms for doing this type of thing.
The specific error i'm getting is
System.Xml.XmlException: Unexpected end of file while parsing Name has occurred. Line 1, position 2034.
My C# code is something like this
XDocument orders = new XDocument(from b in db.GetUserOrders(userid)
select XElement.Parse(b.XML_F52E5B62_58B1_21e2_B105_00805A49AB12));
The stored proc looks like
select * from orders where userid = @userid order by tscreated
for xml raw('order'), ROOT('orders')
The XML returned from the stored proc looks like
<orders>
<order OrderId="123" UserId="bob" tscreated="2010-07-16T16:46:46.173">
<morexml>
<element1>
<element2>abc</element2>
<!--more stuff-->
</element1>
</morexml>
</order>
<!--lots more orders-->
</orders>
Upvotes: 2
Views: 949
Reputation: 4663
I had forgotten to update this with an answer, but given @EthanTowne's comment, I dug up what I'm doing in this code now:
var o = from ords in cfg.db.OsGetUserOrders(userid)
select ords.XML_F52E5B62_58B1_21e2_B105_00805A49AB12;
StringBuilder sb = new StringBuilder();
sb.AppendFormat("<orders>{0}</orders>", string.Join("", o.ToArray()));
XElement xe = XElement.Parse(sb.ToString());
Basically, the stored proc returns several order
elements, and this code coverts them to an array then joins them into a string. Then I parse it into an XElement. There's probably a better way, and I'm open to other solutions.
Upvotes: 1