I want to get the value of a node <abc>
from xmldata column.
XML data looks like:
<data id="d4E8121C9636942F18AC77F3EECD13ABA">
<d id="pDF21A1781B684FAD8D476BF14F78D52D">
<abc>ABC</abc>
</d>
</data>
Here is the code:
using (var exampleSource = new ExampleDataSource())
{
var xmlData = exampleSource.queue
.Where(a => a.QueueID == queueID)
.Select(a => a.XMLData)
.FirstOrDefault();
var messages = from m in xmlData
select XElement.Parse("abc");
}
XElement.Parse()
is for turning a string into an XElement.
I think you simply want xmlData.Descendents("d").Descendents("abc")
.
正如您所说的XMLData
是一个string
,您需要对此进行解析,然后像这样获取abc
的值:
var abc = (string)XElement.Parse(xmlData).Descendants("abc").Single();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.