我正在尝试获取数据,其中所有单词以A开头并使用xml将其显示在列表框中,但是我在这里无法获得的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开头
答案 0 :(得分:1)
试试这个:
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;