我有一个 xml 字符串,其中包含我想要屏蔽的某些值。我还有一个黑名单列表,其中包含我要屏蔽的元素或属性的名称。如何使用 Linq 做到这一点?
var BlackList=new List<string>{"ssn", "dateofbirth"};
var xml=@"<Rows><Row><SSN>123-12-1234</SSN><Address>123 Somewhere Street</Address><DateOfBirth>12-12-2012</DateOfBirth></Row><Row><SSN value=""123-12-1234""/><Address value=""123 Somewhere Street""/><DateOfBirth value=""12-12-2012""/></Row></Rows>";
结果集如下所示:
"<Rows><Row><SSN>RemovedForSecurity</SSN><Address>123 Somewhere Street</Address><DateOfBirth>RemovedForSecurity</DateOfBirth></Row><Row><SSN value="RemovedForSecurity"/><Address value="123 Somewhere Street"/><DateOfBirth value="RemovedForSecurity"/></Row></Rows>"