<?xml version="1.0"?>
<AppXmlLogWritter>
<LogData>
<LogID>5678201301161640382919</LogID>
<LogDateTime>20130114164038</LogDateTime>
</LogData>
<LogData>
<LogID>5678201301161640382920</LogID>
<LogDateTime>20130115154040</LogDateTime>
</LogData>
<LogData>
<LogID>5678201301161640382921</LogID>
<LogDateTime>20130116164042</LogDateTime>
</LogData>
</AppXmlLogWritter>
删除我在xpath查询
下面使用的一个节点string xpathQuery = "/AppXmlLogWritter/LogData[LogDateTime ='" + txtToDate.Text.Trim() + "']";
XmlNodeList objxmlNodeList = objXmldoc.SelectNodes(xpathQuery);
for (int i = 0; i <= objxmlNodeList.Count - 1; i++)
{
objxmlNodeList[i].ParentNode.RemoveChild(objxmlNodeList[i]);
lblMessage.Text = "Record deleted sucessfully.";
}
我正在编写各种应用程序的XML文件。用户可以在LogDateTime的范围之间删除日志.How是我的XPath查询,用于删除LogDateTime范围之间的日志。
示例:如果我必须删除日期时间范围20130116164038到20130116164040之间的日志。
答案 0 :(得分:2)
试试这个:
strXpathQuery = "/AppXmlLogWritter/LogData[LogDateTime >='" + txtFromDate.Text.Trim() + "' and LogDateTime <='" + txtToDate.Text.Trim() +"']";
要在指定日期获取所有logdata,您可以使用:
strXpathQuery = "/AppXmlLogWritter/LogData[starts-with(LogDateTime, '20130116')]";
要获得logdata
范围内从{20130114'到'20130116'的所有LogDateTime
,您可以使用此功能:
strXpathQuery = "/AppXmlLogWritter/LogData[substring(LogDateTime, 1, 8) >='20130114' and substring(LogDateTime, 1, 8) <='20130116']";