-
Notifications
You must be signed in to change notification settings - Fork 1
/
XPathProcessorResult.cs
67 lines (60 loc) · 1.94 KB
/
XPathProcessorResult.cs
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
using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.XPath;
namespace XPathQuery
{
public class XPathProcessorResult
{
public string Result
{
get
{
if (!string.IsNullOrEmpty(StringResult))
return StringResult;
StringBuilder sb = new StringBuilder();
foreach (XmlNode node in XMLNodeList)
{
StringBuilder sbLocal = new StringBuilder();
using (StringWriter stringWriter = new StringWriter(sbLocal))
using (XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter))
{
xmlTextWriter.Formatting = Formatting.Indented;
node.WriteTo(xmlTextWriter);
}
sb.AppendLine(sbLocal.ToString());
}
return sb.ToString();
}
}
public int Count
{
get
{
if (!string.IsNullOrEmpty(StringResult))
return 1;
else
return XMLNodeList.Count;
}
}
private string StringResult { get; set; }
private XmlNodeList XMLNodeList { get; set; }
public XPathProcessorResult(object value, XPathResultType resultType)
{
switch (resultType)
{
case XPathResultType.NodeSet:
XMLNodeList = (XmlNodeList)value;
break;
case XPathResultType.Boolean:
case XPathResultType.Number:
case XPathResultType.String:
StringResult = value.ToString();
break;
default:
throw new ArgumentOutOfRangeException("Unexpected XPathResultType");
}
}
}
}