当前位置: 首页>>代码示例>>C#>>正文


C# XmlTextReader.ReadElementContentAsString方法代码示例

本文整理汇总了C#中XmlTextReader.ReadElementContentAsString方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.ReadElementContentAsString方法的具体用法?C# XmlTextReader.ReadElementContentAsString怎么用?C# XmlTextReader.ReadElementContentAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XmlTextReader的用法示例。


在下文中一共展示了XmlTextReader.ReadElementContentAsString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetDialogById

    public List<string> GetDialogById(string id)
    {
        XmlTextReader reader = new XmlTextReader(XMLFileName);
        List<string> texts   = new List<string>();

        while (reader.Read())
        {
            if (reader.NodeType == XmlNodeType.Element && reader.Name == id)
            {
                int i = 0;
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.EndElement && reader.Name == id)
                    {
                        break;
                    }
                    if (reader.NodeType == XmlNodeType.Element && reader.Name == ("text_" + i))
                    {
                        texts.Add(reader.ReadElementContentAsString());
                        i++;
                    }
                }
            }
        }
        reader.Close();

        return texts;
    }
开发者ID:AlexanderMekumyanov,项目名称:SerKnight,代码行数:28,代码来源:DialogSystem.cs

示例2: GetText

    public static string GetText(string key)
    {
        XmlTextReader reader = new XmlTextReader(new StringReader(copySource.text));

        string outString = "";

        // replace "EN" with language code, once implemented

        while(reader.Read()){
            if (reader.IsStartElement(key)){
                reader.ReadToFollowing("EN");
                outString = reader.ReadElementContentAsString("EN", reader.NamespaceURI);
            }
        }

        return outString;
    }
开发者ID:chorgan93,项目名称:selfportraitoftheartist,代码行数:17,代码来源:TextSource.cs

示例3: LoadSets

    public static List<UrlMapSet> LoadSets()
    {
        List<UrlMapSet> sets = new List<UrlMapSet>();

        using (XmlReader reader = new XmlTextReader(new StreamReader(HttpContext.Current.Server.MapPath("~/Config/FileSets.xml"))))
        {
            reader.MoveToContent();
            while (reader.Read())
            {
                if ("set" == reader.Name)
                {
                    string setName = reader.GetAttribute("name");
                    UrlMapSet UrlMapSet = new UrlMapSet();
                    UrlMapSet.Name = setName;

                    while (reader.Read())
                    {
                        if ("url" == reader.Name)
                        {
                            string urlName = reader.GetAttribute("name");
                            string url = reader.ReadElementContentAsString();
                            UrlMapSet.Urls.Add(new UrlMap(urlName, url));
                        }
                        else if ("set" == reader.Name)
                            break;
                    }

                    sets.Add(UrlMapSet);
                }
            }
        }

        return sets;
    }
开发者ID:foxvirtuous,项目名称:MVB2C,代码行数:34,代码来源:CombineScripts.cs

示例4: LoadConfigFile

    void LoadConfigFile()
    {
        try
        {
            XmlTextReader doc = new XmlTextReader("reddit_api.xml");
            while (doc.Read())
            {
                if (doc.NodeType == XmlNodeType.Element)
                {
                    switch (doc.Name)
                    {
                        case "seconds_between_api_calls":
                            m_seconds_between_calls = doc.ReadElementContentAsDouble();
                            break;
                        case "seconds_before_cache_invalid":
                            m_seconds_before_cache_invalid = doc.ReadElementContentAsDouble();
                            break;
                        case "default_content_limit":
                            m_content_limit = doc.ReadElementContentAsInt();
                            break;
                        case "object_mappings":
                            string kind = "", objectname = "";

                            while (doc.MoveToNextAttribute())
                            {

                                if (doc.Name == "kind")
                                {
                                    kind = doc.Value;
                                }
                                else if (doc.Name == "object")
                                {
                                    objectname = doc.Value;
                                }
                            }
                            if (m_object_mapping.ContainsKey(kind))
                                m_object_mapping["kind"] = objectname;
                            else
                                m_object_mapping.Add(kind, objectname);
                            break;
                        case "domain":
                            m_domain = doc.ReadElementContentAsString();
                            break;
                    }
                }
            }
            doc.Close();
        }
        catch (FileNotFoundException)
        {
            StreamWriter s = new StreamWriter("reddit_api.xml");
            s.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
            s.WriteLine("<reddit_api_config>");
            s.WriteLine("<seconds_between_api_calls>2</seconds_between_api_calls>" );
            s.WriteLine("<seconds_before_cache_invalid>30</seconds_before_cache_invalid>");
            s.WriteLine("<default_content_limit>25</default_content_limit>");
            s.WriteLine("<object_mappings kind=\"comment_kind\" object=\"t1\"/>");
            s.WriteLine("<object_mappings kind=\"message_kind\" object=\"t4\"/>");
            s.WriteLine("<object_mappings kind=\"more_kind\" object =\"more\"/>");
            s.WriteLine("<object_mappings kind=\"redditor_kind\" object=\"t2\"/>");
            s.WriteLine("<object_mappings kind=\"submission_kind\" object=\"t3\"/>");
            s.WriteLine("<object_mappings kind=\"subreddit_kind\" object=\"t5\"/>");
            s.WriteLine("<object_mappings kind=\"userlist_kind\" object=\"UserList\"/>");
            s.WriteLine("<domain>http://www.reddit.com/</domain>");
            s.WriteLine("<!--");
            s.WriteLine("message_kind:    t7");
            s.WriteLine("submission_kind: t6");
            s.WriteLine("subreddit_kind:  t5");
            s.WriteLine("  -->");
            s.WriteLine("</reddit_api_config>");
            s.Close();
            LoadConfigFile();
        }
    }
开发者ID:ACReeser,项目名称:rKnightsOfNew,代码行数:74,代码来源:RedditAPI.cs

示例5: ImportStrategy

    public static bool ImportStrategy(string fileName)
    {
        FileStream fileStream = null;
        bool bRet = false;
        try
        {
            int buffSize = 512;
            byte[] automationData;
            fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read);
            XmlTextReader reader = new XmlTextReader(fileStream);
            
            reader.MoveToElement();
            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("Strategy"))
                {                    
                    //读Name
                    reader.Read();
                    reader.MoveToContent();
                    string name = reader.ReadElementContentAsString();
                    //读Comment
                    reader.Read();
                    reader.MoveToContent();
                    string comment = reader.ReadElementContentAsString();

                    Strategy strategyToAdd = new Strategy();
                    //读Event
                    reader.Read();
                    reader.MoveToContent();
                    strategyToAdd.Event = (FSEyeEvent)reader.ReadElementContentAsInt();
                    //读Automation
                    reader.Read();
                    reader.MoveToContent();                    
                    int realLength = 0;
                    automationData = new byte[buffSize];
                    byte[] tempBuff = new byte[buffSize];
                    int readCount = reader.ReadElementContentAsBinHex(tempBuff, 0, buffSize);
                    Array.Copy(tempBuff, 0, automationData, realLength, readCount);
                    realLength +=  readCount;
                    while (tempBuff.Length == readCount)
                    {
                        Array.Resize<byte>(ref automationData, automationData.Length + buffSize);
                        readCount = reader.ReadElementContentAsBinHex(tempBuff, 0, buffSize);
                        Array.Copy(tempBuff, 0, automationData, realLength, readCount);
                        realLength += readCount;                        
                    }
                    Array.Resize<byte>(ref automationData, realLength);
                    strategyToAdd.Automation = AdminServer.TheInstance.AutomationManager.Load(automationData);
                    //读Enable
                    reader.Read();
                    reader.MoveToContent();
                    strategyToAdd.Enabled = reader.ReadElementContentAsInt() == 1 ? true : false;                    
                    AdminServer.TheInstance.StrategyManager.Add(strategyToAdd, name, comment);
                }
            }
            bRet = true;
        }
        catch (Exception)
        {
            bRet = false;
        }
        finally
        {
            if (fileStream != null) fileStream.Close();
        }
        return bRet;
    }    
开发者ID:viticm,项目名称:pap2,代码行数:67,代码来源:WebUtil.cs

示例6: ImportScheduledTask

 public static bool ImportScheduledTask(string fileName)
 {
     FileStream fileStream = null;
     bool bRet = false;
     try
     {
         int buffSize = 512;
         byte[] taskData;
         fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Read);
         XmlTextReader reader = new XmlTextReader(fileStream);
                     
         reader.MoveToElement();
         
         while (reader.Read())
         {
             if (reader.NodeType == XmlNodeType.Element && reader.Name.Equals("Task"))
             {
                 //读Name
                 reader.Read();                    
                 reader.MoveToContent();
                 string name = reader.ReadElementContentAsString();
                 //读Comment
                 reader.Read();
                 reader.MoveToContent();
                 string comment = reader.ReadElementContentAsString();
                 //读Data
                 reader.Read();
                 reader.MoveToContent();
                 
                 int realLength = 0;
                 taskData = new byte[buffSize];                    
                 byte[] tempBuff = new byte[buffSize];
                 int readCount = reader.ReadElementContentAsBinHex(tempBuff, 0, buffSize);
                 Array.Copy(tempBuff, 0, taskData, realLength, readCount);
                 realLength += readCount;
                 while (tempBuff.Length == readCount)
                 {
                     Array.Resize<byte>(ref taskData, taskData.Length + buffSize);
                     readCount = reader.ReadElementContentAsBinHex(tempBuff, 0, buffSize);
                     Array.Copy(tempBuff, 0, taskData, realLength, readCount);
                     realLength += readCount;
                 }
                 Array.Resize<byte>(ref taskData, realLength);
                 MemoryStream taskDataStream = new MemoryStream(taskData);
                 IFormatter formatter = new BinaryFormatter();
                 IScheduledTask task = (IScheduledTask)formatter.Deserialize(taskDataStream);
                 AdminServer.TheInstance.ScheduledTaskManager.Add(task, name, comment);
             }
         }
         bRet = true;
     }
     catch (Exception)
     {
         bRet = false;
     }
     finally
     {
         if (fileStream != null) fileStream.Close();
     }
     return bRet;
 }
开发者ID:viticm,项目名称:pap2,代码行数:61,代码来源:WebUtil.cs

示例7: handleAttribs

 // This handles all the attribute trees in every loader.
 private void handleAttribs(XmlTextReader reader, Player_Character character)
 {
     XmlNodeType nType = reader.NodeType;
     string fullSkill = "";
     string tmp = "";
     do
     {
         reader.Read ();
         nType = reader.NodeType;
         if(nType == XmlNodeType.Element)
         {
             if(reader.Name == "Attribute")
             {
                 fullSkill += reader.GetAttribute("name");
                 tmp = reader.ReadElementContentAsString();
                 if(tmp.StartsWith("+") || tmp.StartsWith("-"))
                 {
                     // We are going to modify the value.
                     if(tmp.StartsWith("+"))
                     {
                         // Going to add it.
                         tmp = tmp.Substring(1);
                         int currentValue = character.getAttrib(fullSkill);
                         if (currentValue > 0)
                             character.setAttrib(fullSkill, currentValue + int.Parse(tmp));
                     }
                     else if (tmp.StartsWith("-"))
                     {
                         // Going to subtract it.
                         tmp = tmp.Substring(1);
                         int currentValue = character.getAttrib(fullSkill);
                         if (currentValue > 0)
                             character.setAttrib(fullSkill, currentValue - int.Parse(tmp));
                     }
                 }
                 else
                 {
                     // We are just going to set the value hard.
                     character.setAttrib(fullSkill, int.Parse(tmp), true);
                 }
                 fullSkill = fullSkill.Remove(fullSkill.LastIndexOf("|") + 1);
             }
             else
             {
                 fullSkill += reader.Name + "|";
             }
         }
         else if(nType == XmlNodeType.EndElement)
         {
             if(fullSkill.IndexOf(reader.Name) >= 0)
                 fullSkill = fullSkill.Remove(fullSkill.IndexOf(reader.Name));
         }
     }while(!(reader.Name == "Attribs" && nType == XmlNodeType.EndElement));
 }
开发者ID:gogolB,项目名称:NuGame,代码行数:55,代码来源:Character_Factory.cs

示例8: handleCharFileElements

    // Handles each of the various elements of the buff table.
    private void handleCharFileElements(XmlTextReader reader, GameObject obj)
    {
        string str;

        // Handle the Characters Root Node.
        if(reader.Name == "Character")
        {
            #if UNITY_EDITOR
                Debug.Log("Character: " + reader.GetAttribute("name"));
            #endif
        }
        // Handle the Name Node.
        else if( reader.Name == "Name")
        {
            str = reader.ReadElementContentAsString();
            obj.name = str;

            #if UNITY_EDITOR
                Debug.Log ("Name: " + str);
            #endif
        }
        // Handle the Main class stuff.
        else if(reader.Name == "MainClass")
        {
            str = reader.ReadElementContentAsString();
            obj.GetComponent<Player_Persona>().MainClass = str;
            handleMainClass(str, obj.GetComponent<Player_Character>());

            #if UNITY_EDITOR
                Debug.Log ("MainClass: " + str);
            #endif
        }
        // Handle the SubClass Stuff.
        else if(reader.Name == "SubClass")
        {
            str = reader.ReadElementContentAsString();
            obj.GetComponent<Player_Persona>().SubClass = str;
            handleSubClass(obj.GetComponent<Player_Persona>().MainClass , str, obj.GetComponent<Player_Character>());

            #if UNITY_EDITOR
                Debug.Log ("SubClass: " + str);
            #endif
        }
        // Handle the History Stuff.
        else if(reader.Name == "History")
        {
            str = reader.ReadElementContentAsString();
            obj.GetComponent<Player_Persona>().History = str;
            handleHistory(obj.GetComponent<Player_Persona>().SubClass, str, obj.GetComponent<Player_Character>());

            #if UNITY_EDITOR
                Debug.Log ("History: " + str);
            #endif
        }
        // Handle the attribute tree.
        else if (reader.Name == "Attribs")
        {
            handleAttribs(reader, obj.GetComponent<Player_Character>());
        }
        // Some kind of element that we don't know how to handle.
        else
        {
            #if UNITY_EDITOR
                Debug.LogWarning("Unknown element: " + reader.Name + ". Do not know how to handle.");
            #endif
        }
    }
开发者ID:gogolB,项目名称:NuGame,代码行数:68,代码来源:Character_Factory.cs


注:本文中的XmlTextReader.ReadElementContentAsString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。