利用XPath操作XML文档。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
//下面列出了最有用的路径表达式:
//  nodename	 选取此节点的所有子节点。
//  /            从根节点选取。
//  //	         从匹配选择的当前节点选择文档中的节点,而不考虑它们的位置。
//  .	         选取当前节点。
//  ..	         选取当前节点的父节点。
//  @	         选取属性

///<summary>
/// xml解析工具
///</summary>
public class XmlTool
{
    #region XML文档节点查询和读取
    ///<summary>
    /// 选择匹配XPath表达式的第一个节点XmlNode.
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名")</param>
    ///<returns>返回XmlNode</returns>
    public static XmlNode GetXmlNodeByXpath(string xmlFileName, string xpath)
    {
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            //加载XML文档
            xmlDoc.Load(xmlFileName);
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            return xmlNode;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数GetXmlNodeByXpath,总参数2,错误信息->" + ex.Message);
            log.Error("函数GetXmlNodeByXpath,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数GetXmlNodeByXpath,参数2,xpath->" + xpath);
            return null;
        }
    }

    ///<summary>
    /// 选择匹配XPath表达式的节点列表XmlNodeList.
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名")</param>
    ///<returns>返回XmlNodeList</returns>
    public static XmlNodeList GetXmlNodeListByXpath(string xmlFileName, string xpath)
    {
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(xmlFileName); //加载XML文档
            XmlNodeList xmlNodeList = xmlDoc.SelectNodes(xpath);
            return xmlNodeList;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数GetXmlNodeListByXpath,总参数2,错误信息->" + ex.Message);
            log.Error("函数GetXmlNodeListByXpath,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数GetXmlNodeListByXpath,参数2,xpath->" + xpath);
            return null;
        }
    }

    ///<summary>
    /// 选择匹配XPath表达式的第一个节点的匹配xmlAttributeName的属性XmlAttribute.
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
    ///<param name="xmlAttributeName">要匹配xmlAttributeName的属性名称</param>
    ///<returns>返回xmlAttributeName</returns>
    public static XmlAttribute GetXmlAttribute(string xmlFileName, string xpath, string xmlAttributeName)
    {
        XmlDocument xmlDoc = new XmlDocument();
        XmlAttribute xmlAttribute = null;
        try
        {
            //加载XML文档
            xmlDoc.Load(xmlFileName);
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            if (xmlNode != null)
            {
                if (xmlNode.Attributes.Count > 0)
                {
                    xmlAttribute = xmlNode.Attributes[xmlAttributeName];
                }
            }
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数GetXmlAttribute,总参数3,错误信息->" + ex.Message);
            log.Error("函数GetXmlAttribute,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数GetXmlAttribute,参数2,xpath->" + xpath);
            log.Error("函数GetXmlAttribute,参数3,xmlAttributeName->" + xmlAttributeName);
            return null;
        }
        return xmlAttribute;
    }

    public static XmlAttribute GetSpecialAttributeValue(string xmlFileName, string attributeName)
    {
        XmlDocument xmlDoc = new XmlDocument();
        XmlAttribute xmlAttribute = null;
        try
        {
            //加载XML文档
            xmlDoc.Load(xmlFileName);
            XmlNode xmlNode = xmlDoc.SelectSingleNode("/");
            if (xmlNode != null)
            {
                XmlNode node = xmlNode.LastChild;
                if (node.Attributes.Count > 0)
                {
                    xmlAttribute = node.Attributes[attributeName];
                }
            }
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数GetSpecialAttributeValue,总参数2,错误信息->" + ex.Message);
            log.Error("函数GetSpecialAttributeValue,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数GetSpecialAttributeValue,参数2,attributeName->" + attributeName);
            return null;
        }
        return xmlAttribute;
    }

    #endregion

    #region XML文档创建和节点或属性的添加、修改
    ///<summary>
    /// 创建一个XML文档
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="rootNodeName">XML文档根节点名称(须指定一个根节点名称)</param>
    ///<param name="version">XML文档版本号(必须为:"1.0")</param>
    ///<param name="encoding">XML文档编码方式</param>
    ///<param name="standalone">该值必须是"yes"或"no",如果为null,Save方法不在XML声明上写出独立属性</param>
    ///<returns>成功返回true,失败返回false</returns>
    public static bool CreateXmlDocument(string xmlFileName, string rootNodeName, string version, string encoding, string standalone)
    {
        // 文件路径,版本号,根节点名不能为空
        if (string.IsNullOrEmpty(xmlFileName) ||
                string.IsNullOrEmpty(rootNodeName) ||
                string.IsNullOrEmpty(version))
        {
            return false;
        }

        bool isSuccess = false;
        try
        {
            XmlDocument xmlDoc = new XmlDocument();
            XmlDeclaration xmlDeclaration = xmlDoc.CreateXmlDeclaration(version, encoding, standalone);
            XmlNode root = xmlDoc.CreateElement(rootNodeName);
            xmlDoc.AppendChild(xmlDeclaration);
            xmlDoc.AppendChild(root);
            xmlDoc.Save(xmlFileName);
            isSuccess = true;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数CreateXmlDocument,总参数5,错误信息->" + ex.Message);
            log.Error("函数CreateXmlDocument,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数CreateXmlDocument,参数2,rootNodeName->" + rootNodeName);
            log.Error("函数CreateXmlDocument,参数3,version->" + version);
            log.Error("函数CreateXmlDocument,参数4,encoding->" + encoding);
            log.Error("函数CreateXmlDocument,参数5,standalone->" + standalone);
        }
        return isSuccess;
    }


    /// <summary>
    /// 依据匹配XPath表达式的第一个节点来创建它的子节点(如果此节点已存在则追加一个新的同名节点)
    /// </summary>
    /// <param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    /// <param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
    /// <param name="xmlNodeName">要匹配xmlNodeName的节点名称</param>
    /// <param name="innerText">节点文本值</param>
    /// <param name="listAttribute">要添加的xmlAttributeName的属性</param>
    /// <returns>成功返回true,失败返回false</returns>
    public static bool CreateXmlNodeByXPath(string xmlFileName, string xpath, string xmlNodeName, string innerText, List<KeyValuePair<string, string>> listAttribute)
    {
        if(string.IsNullOrEmpty(xmlFileName) ||
                string.IsNullOrEmpty(xpath) ||
                string.IsNullOrEmpty(xmlNodeName))
        {
            return false;
        }

        bool isSuccess = false;
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            //加载XML文档
            xmlDoc.Load(xmlFileName);
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            if (xmlNode != null)
            {
                //存不存在此节点都创建
                XmlElement subElement = xmlDoc.CreateElement(xmlNodeName);
                subElement.InnerText = (innerText == null ? "" : innerText);

                //如果属性和值参数都不为空则在此新节点上新增属性
                if (null != listAttribute)
                {
                    foreach (KeyValuePair<string, string> xmlAttr in listAttribute)
                    {
                        if (!string.IsNullOrEmpty(xmlAttr.Key) && !string.IsNullOrEmpty(xmlAttr.Value))
                        {
                            XmlAttribute xmlAttribute = xmlDoc.CreateAttribute(xmlAttr.Key);
                            xmlAttribute.Value = xmlAttr.Value;
                            subElement.Attributes.Append(xmlAttribute);
                        }
                    }
                }
                xmlNode.AppendChild(subElement);
            }
            //保存到XML文档
            xmlDoc.Save(xmlFileName);
            isSuccess = true;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数CreateXmlNodeByXPath,总参数5,错误信息->" + ex.Message);
            log.Error("函数CreateXmlNodeByXPath,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数CreateXmlNodeByXPath,参数2,xpath->" + xpath);
            log.Error("函数CreateXmlNodeByXPath,参数3,xmlNodeName->" + xmlNodeName);
            log.Error("函数CreateXmlNodeByXPath,参数4,innerText->" + innerText);
            log.Error("函数CreateXmlNodeByXPath,参数5,listAttribute为list");
        }
        return isSuccess;
    }

    ///<summary>
    /// 依据匹配XPath表达式的第一个节点来创建或更新它的子节点(如果节点存在则更新,不存在则创建)
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
    ///<param name="xmlNodeName">要匹配xmlNodeName的节点名称</param>
    ///<param name="innerText">节点文本值</param>
    ///<returns>成功返回true,失败返回false</returns>
    public static bool CreateOrUpdateXmlNodeByXPath(string xmlFileName, string xpath, string xmlNodeName, string innerText)
    {
        if (string.IsNullOrEmpty(xmlFileName) ||
                string.IsNullOrEmpty(xpath) ||
                string.IsNullOrEmpty(xmlNodeName))
        {
            return false;
        }

        bool isSuccess = false;
        //标识节点是否存在
        bool isExistsNode = false;
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(xmlFileName);
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            if (xmlNode != null)
            {
                //遍历xpath节点下的所有子节点
                foreach (XmlNode node in xmlNode.ChildNodes)
                {
                    if (node.Name.ToLower() == xmlNodeName.ToLower())
                    {
                        //存在此节点则更新
                        node.InnerText = (innerText == null ? "" : innerText);
                        isExistsNode = true;
                        break;
                    }
                }

                if (!isExistsNode)
                {
                    //不存在此节点则创建
                    XmlElement subElement = xmlDoc.CreateElement(xmlNodeName);
                    subElement.InnerXml = innerText;
                    xmlNode.AppendChild(subElement);
                }
            }
            xmlDoc.Save(xmlFileName); //保存到XML文档
            isSuccess = true;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数CreateXmlNodeByXPath,总参数4,错误信息->" + ex.Message);
            log.Error("函数CreateXmlNodeByXPath,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数CreateXmlNodeByXPath,参数2,xpath->" + xpath);
            log.Error("函数CreateXmlNodeByXPath,参数3,xmlNodeName->" + xmlNodeName);
            log.Error("函数CreateXmlNodeByXPath,参数4,innerText->" + innerText);
        }
        return isSuccess;
    }

    ///<summary>
    /// 依据匹配XPath表达式的第一个节点来创建或更新它的属性(如果属性存在则更新,不存在则创建)
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
    ///<param name="xmlAttributeName">要匹配xmlAttributeName的属性名称</param>
    ///<param name="value">属性值</param>
    ///<returns>成功返回true,失败返回false</returns>
    public static bool CreateOrUpdateXmlAttributeByXPath(string xmlFileName, string xpath, string xmlAttributeName, string value)
    {
        if (string.IsNullOrEmpty(xmlFileName) ||
                string.IsNullOrEmpty(xpath) ||
                string.IsNullOrEmpty(xmlAttributeName))
        {
            return false;
        }

        bool isSuccess = false;
        bool isExistsAttribute = false;//标识属性是否存在
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(xmlFileName); //加载XML文档
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            if (xmlNode != null)
            {
                //遍历xpath节点中的所有属性
                foreach (XmlAttribute attribute in xmlNode.Attributes)
                {
                    if (attribute.Name.ToLower() == xmlAttributeName.ToLower())
                    {
                        //节点中存在此属性则更新
                        attribute.Value = value;
                        isExistsAttribute = true;
                        break;
                    }
                }
                if (!isExistsAttribute)
                {
                    //节点中不存在此属性则创建
                    XmlAttribute xmlAttribute = xmlDoc.CreateAttribute(xmlAttributeName);
                    xmlAttribute.Value = value;
                    xmlNode.Attributes.Append(xmlAttribute);
                }
            }
            xmlDoc.Save(xmlFileName); //保存到XML文档
            isSuccess = true;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数CreateOrUpdateXmlAttributeByXPath,总参数4,错误信息->" + ex.Message);
            log.Error("函数CreateOrUpdateXmlAttributeByXPath,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数CreateOrUpdateXmlAttributeByXPath,参数2,xpath->" + xpath);
            log.Error("函数CreateOrUpdateXmlAttributeByXPath,参数3,xmlAttributeName->" + xmlAttributeName);
            log.Error("函数CreateOrUpdateXmlAttributeByXPath,参数4,value->" + value);
        }
        return isSuccess;
    }

    ///<summary>
    /// 修改匹配XPath表达式的第一个节点中的对应得属性
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
    ///<returns>成功返回true,失败返回false</returns>
    public static bool ModifyXmlAttributeByXPath(string xmlFileName, string xpath, string attributeName, string attributeValue)
    {
        if (string.IsNullOrEmpty(xmlFileName) || string.IsNullOrEmpty(xpath) || string.IsNullOrEmpty(attributeName))
        {
            return false;
        }

        bool isSuccess = false;
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(xmlFileName); //加载XML文档
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            if (xmlNode != null)
            {
                xmlNode.Attributes[attributeName].Value = attributeValue;
            }
            xmlDoc.Save(xmlFileName); //保存到XML文档
            isSuccess = true;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数ModifyXmlAttributeByXPath,总参数2,错误信息->" + ex.Message);
            log.Error("函数ModifyXmlAttributeByXPath,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数ModifyXmlAttributeByXPath,参数2,xpath->" + xpath);
        }
        return isSuccess;
    }

    #endregion

    #region XML文档节点或属性的删除
    ///<summary>
    /// 删除匹配XPath表达式的第一个节点(节点中的子元素同时会被删除)
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
    ///<returns>成功返回true,失败返回false</returns>
    public static bool DeleteXmlNodeByXPath(string xmlFileName, string xpath)
    {
        if (string.IsNullOrEmpty(xmlFileName) || string.IsNullOrEmpty(xpath))
        {
            return false;
        }

        bool isSuccess = false;
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(xmlFileName); //加载XML文档
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            if (xmlNode != null)
            {
                //删除节点
                xmlNode.ParentNode.RemoveChild(xmlNode);
            }
            xmlDoc.Save(xmlFileName); //保存到XML文档
            isSuccess = true;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数DeleteXmlNodeByXPath,总参数2,错误信息->" + ex.Message);
            log.Error("函数DeleteXmlNodeByXPath,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数DeleteXmlNodeByXPath,参数2,xpath->" + xpath);
        }
        return isSuccess;
    }

    ///<summary>
    /// 删除匹配XPath表达式的第一个节点中的匹配参数xmlAttributeName的属性
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
    ///<param name="xmlAttributeName">要删除的xmlAttributeName的属性名称</param>
    ///<returns>成功返回true,失败返回false</returns>
    public static bool DeleteXmlAttributeByXPath(string xmlFileName, string xpath, string xmlAttributeName)
    {
        if (string.IsNullOrEmpty(xmlFileName) || string.IsNullOrEmpty(xpath) || string.IsNullOrEmpty(xpath))
        {
            return false;
        }

        bool isSuccess = false;
        bool isExistsAttribute = false;
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(xmlFileName); //加载XML文档
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            XmlAttribute xmlAttribute = null;
            if (xmlNode != null)
            {
                //遍历xpath节点中的所有属性
                foreach (XmlAttribute attribute in xmlNode.Attributes)
                {
                    if (attribute.Name.ToLower() == xmlAttributeName.ToLower())
                    {
                        //节点中存在此属性
                        xmlAttribute = attribute;
                        isExistsAttribute = true;
                        break;
                    }
                }
                if (isExistsAttribute)
                {
                    //删除节点中的属性
                    xmlNode.Attributes.Remove(xmlAttribute);
                }
            }
            xmlDoc.Save(xmlFileName); //保存到XML文档
            isSuccess = true;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数DeleteXmlAttributeByXPath,总参数3,错误信息->" + ex.Message);
            log.Error("函数DeleteXmlAttributeByXPath,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数DeleteXmlAttributeByXPath,参数2,xpath->" + xpath);
            log.Error("函数DeleteXmlAttributeByXPath,参数3,xmlAttributeName->" + xmlAttributeName);
        }
        return isSuccess;
    }

    ///<summary>
    /// 删除匹配XPath表达式的第一个节点中的所有属性
    ///</summary>
    ///<param name="xmlFileName">XML文档完全文件名(包含物理路径)</param>
    ///<param name="xpath">要匹配的XPath表达式(例如:"//节点名//子节点名</param>
    ///<returns>成功返回true,失败返回false</returns>
    public static bool DeleteAllXmlAttributeByXPath(string xmlFileName, string xpath)
    {
        if (string.IsNullOrEmpty(xmlFileName) || string.IsNullOrEmpty(xpath))
        {
            return false;
        }

        bool isSuccess = false;
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(xmlFileName); //加载XML文档
            XmlNode xmlNode = xmlDoc.SelectSingleNode(xpath);
            if (xmlNode != null)
            {
                //遍历xpath节点中的所有属性
                xmlNode.Attributes.RemoveAll();
            }
            xmlDoc.Save(xmlFileName); //保存到XML文档
            isSuccess = true;
        }
        catch (Exception ex)
        {
            log4net.ILog log = log4net.LogManager.GetLogger(typeof(XmlTool));
            log.Error("函数DeleteAllXmlAttributeByXPath,总参数2,错误信息->" + ex.Message);
            log.Error("函数DeleteAllXmlAttributeByXPath,参数1,xmlFileName->" + xmlFileName);
            log.Error("函数DeleteAllXmlAttributeByXPath,参数2,xpath->" + xpath);
        }
        return isSuccess;
    }
    #endregion
}