XML到linq查询,在Windows phone中字母以a开头
本文关键字:开头 phone Windows linq 查询 XML | 更新日期: 2023-09-27 18:11:58
我试图获取数据,其中所有单词以A开头,并使用xml向LINQ显示它的列表框,但Startwith属性我无法在这里实现是我试图获取的代码
XDocument loadedCustomData = XDocument.Load("accounts.xml");
var filteredData =
from c in loadedCustomData.Descendants("record")
where (string)c.Element("main") == "Above the Line"
// i want here something like
//where (string)c.element("main").startwith ==a
//so how to ACHIEVE THIS????
select new words()
{
PON = "Post Office: " + (string)c.Element("main"),
PIN = "Pincode (Postal Code): " + (string)c.Element("def"),
};
listBox1.ItemsSource = filteredData;
这里是XML格式
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<record>
<main>Above the Line</main>
<def>Above the line items are those revenue and expense items that directly affect
</record>
那么如何实现以字母A开头的查询呢
Try This:
XDocument loadedCustomData = XDocument.Load("accounts.xml");
var filteredData =
from c in loadedCustomData.Descendants("record")
where ((string)c.Element("main")).StartsWith("A")
select new words()
{
PON = "Post Office: " + (string)c.Element("main"),
PIN = "Pincode (Postal Code): " + (string)c.Element("def"),
};
listBox1.ItemsSource = filteredData;