我正在使用Xelements创建XDocument
XDocument document = new XDocument(element);
我尝试用
删除不需要的节点List<string> eNames = new List<string> { "Name", "Price", "Year", "Model"};
document.XPathSelectElements("s0:Customer/s0:Loan/s0:Vehicle/*", namespaceManager)
.Where(x => (!eNames.Contains(x.Name.LocalName)))
.Remove();
IT工作正常,但有不需要的空白区域。删除后如何删除节点之间不需要的空格?
输出看起来像
</Vehicle>
<Vehicle>
<Name>Toyota</Name>
<Year>2012</Year>
<Make>TOYOTA</Make>
<Model>CAMRY L/LE/SE/XLE</Model>
</Vehicle>
答案 0 :(得分:0)
试试这个
XDocument document = new XDocument();
foreach (XElement element in document.Elements())
{
element.Value = element.Value.Trim();
}