當前位置: 首頁>>代碼示例>>C#>>正文


C# XPathDocument.ToString方法代碼示例

本文整理匯總了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();
 }
開發者ID:Qorpent,項目名稱:comdiv.oldcore,代碼行數:12,代碼來源:FilePathResolverXmlExtensions.cs

示例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)
                    {
//.........這裏部分代碼省略.........
開發者ID:kamilion,項目名稱:WISP,代碼行數:101,代碼來源:Template.cs


注:本文中的System.Xml.XPath.XPathDocument.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。