我有一个XML文件
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<File>
<Cars>
<Car>
<Color>Blue</Color>
<Year>1988</Year>
</Car>
<Car>
<Color>Green</Color>
<Year>1989</Year>
</Car>
<Car>
<Color>Yellow</Color>
<Year>1989</Year>
</Car>
</Cars>
</File>
我想用这个对象在这个文件上创建一个过滤器:
public class condition
{
public string color { get; set; }
public string year { get; set; }
}
List<condition> c = new List<condition>
{
new condition()
{
color = "Green",
year = "1989"
},
new condition()
{
color = "Blue",
year = "1988"
}
};
我想只带(color = Green and year = 1989) OR (color = blue and year = 1988)
但我不知道如何做到这一点。也许使用XDocument和Linq.Dynamic?
答案 0 :(得分:0)
您可以使用XDocument
轻松过滤linq中的xml。此函数将使用Remove()
扩展方法基于过滤器删除所有节点。
private void RemoveCars(string color, string year)
{
var doc = XDocument.Load("<myxml>...</myxml>");
doc.Element("File")
.Element("Cars")
.Elements("Cars")
.Where(c=> c.Element("color").Value == color
&& c.Element("Year").Value == year)
.Remove();
doc.Save("c:\\mypath\\my.xml");
}
答案 1 :(得分:0)
您可以使用Linq to xml的另一个选项
import UIKit
class MyTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl?.enabled = true
self.refreshControl?.userInteractionEnabled = true
print("MyTableViewController",self.refreshControl!, self.refreshControl?.enabled)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func refresh(sender:AnyObject) {
// Code to refresh table view
print("Refresing contents...")
self.refreshControl?.endRefreshing()
}
}