本文整理汇总了C#中System.Xml.XPath.XPathDocument.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# XPathDocument.ToString方法的具体用法?C# XPathDocument.ToString怎么用?C# XPathDocument.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathDocument
的用法示例。
在下文中一共展示了XPathDocument.ToString方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getValue
private static string getValue(string result, string xpath){
var res = new XPathDocument(new StringReader(result)).CreateNavigator().Evaluate(xpath);
if (res is XPathNodeIterator){
if (((XPathNodeIterator) res).MoveNext()){
res = ((XPathNodeIterator) res).Current.Value;
}
else{
return String.Empty;
}
}
return null == res ? String.Empty : res.ToString();
}
示例2: LoadTemplate
public static bool LoadTemplate(XPathDocument docNav)
{
Template t = new Template();
bool isValidTemplate = false;
try
{
// Create a navigator to query with XPath.
XPathNavigator nav = docNav.CreateNavigator();
XPathNavigator root = nav.SelectSingleNode("//Item");
t.Description = root.GetAttribute("Name", "");
t.Class = root.GetAttribute("Class", "");
bool isStatic = true;
if (!bool.TryParse(root.GetAttribute("IsStatic", ""), out isStatic))
{
isStatic = true; // default to static item
}
t.IsStatic = isStatic;
bool isTransient = true;
if (!bool.TryParse(root.GetAttribute("IsTransient", ""), out isTransient))
{
isTransient = true; // default to Transient, non-persisting item
}
t.IsTransient = isTransient;
int stackCount = 1;
if (!int.TryParse(root.GetAttribute("StackCount", ""), out stackCount))
{
stackCount = 1; // default to Transient, non-persisting item
}
t.StackCount = stackCount;
if (t.Class.Length < 1)
{
Log.LogMsg("Failed to load template [" + docNav.ToString() + "] - [Class (fully qualified type name) could not be determined. Make sure that the Class attribute is defined.]");
goto bailout;
}
GOT got = GOT.None;
string gotStr = root.GetAttribute("GOT", "");
try
{
got = (GOT)Enum.Parse(typeof(GOT), gotStr);
}
catch { }
if (got == GOT.None)
{
Log.LogMsg("Failed to load template [" + docNav.ToString() + "] - [GOT (Game object type) could not be determined. Make sure that GOT value exists in GOT enum cs file.]");
goto bailout;
}
t.GameObjectType = got;
string strExpression = "//Item/Properties/*";
XPathNodeIterator NodeIter = nav.Select(strExpression);
//Iterate through the results showing the element value.
while (NodeIter.MoveNext())
{
string name = NodeIter.Current.GetAttribute("Name", "");
if (name.Length < 1)
{
Log.LogMsg("Failed to load template [" + docNav.ToString() + "] - [Property Name attribute is missing.]");
goto bailout;
}
string stringValue = NodeIter.Current.GetAttribute("StringValue", "");
string intValue = NodeIter.Current.GetAttribute("IntValue", "");
string floatValue = NodeIter.Current.GetAttribute("FloatValue", "");
string longValue = NodeIter.Current.GetAttribute("LongValue", "");
if (stringValue.Length < 1 && intValue.Length < 1 && floatValue.Length < 1 && longValue.Length < 1)
{
Log.LogMsg("Failed to load template [" + docNav.ToString() + "] - [Must set either StringValue, IntValue, FloatValue or LongValue for property " + name + ".]");
goto bailout;
}
if (stringValue.Length > 0)
{
t.Properties.SetProperty(name, stringValue);
}
else if (floatValue.Length > 1)
{
try
{
float val = float.Parse(floatValue);
t.Properties.SetProperty(name, val);
}
catch
{
Log.LogMsg("Failed to load template [" + docNav.ToString() + "] - [Must specify a valid number for FloatValue for property " + name + ".]");
goto bailout;
}
}
else if (intValue.Length > 0)
{
//.........这里部分代码省略.........