3
<?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 范围之间的日志。我的 XPath 查询如何删除 LogDateTime 范围之间的日志。

示例:如果我必须删除日期时间范围 20130116164038 到 20130116164040 之间的日志。

4

1 回答 1

2

试试这个:

strXpathQuery = "/AppXmlLogWritter/LogData[LogDateTime >='" + txtFromDate.Text.Trim() + "' and LogDateTime <='" + txtToDate.Text.Trim() +"']";

要在指定日期获取所有日志数据,您可以使用以下命令:

strXpathQuery = "/AppXmlLogWritter/LogData[starts-with(LogDateTime, '20130116')]";

要获得从 '20130114' 到 '20130116' 范围内的所有内容,您可以使用以下命令logdataLogDateTime

strXpathQuery = "/AppXmlLogWritter/LogData[substring(LogDateTime, 1, 8) >='20130114' and substring(LogDateTime, 1, 8) <='20130116']";
于 2013-01-18T06:55:57.667 回答