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


C# XmlTextReader.MoveToElement方法代码示例

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


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

示例1: getGEAlt

    double getGEAlt(double lat, double lng)
    {
        double alt = 0;
            //http://maps.google.com/maps/api/elevation/xml

            try
            {
                using (XmlTextReader xmlreader = new XmlTextReader("http://maps.google.com/maps/api/elevation/xml?locations=" + lat.ToString(new System.Globalization.CultureInfo("en-US")) + "," + lng.ToString(new System.Globalization.CultureInfo("en-US")) + "&sensor=true"))
                {
                    while (xmlreader.Read())
                    {
                        xmlreader.MoveToElement();
                        switch (xmlreader.Name)
                        {
                            case "elevation":
                                alt = double.Parse(xmlreader.ReadString(), new System.Globalization.CultureInfo("en-US"));
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            catch { }

            return alt * MainV2.comPort.MAV.cs.multiplierdist;
    }
开发者ID:LeoTosti,项目名称:x-drone,代码行数:27,代码来源:TrackerHomeGPS.cs

示例2: fileToStruct

    // This method takes a configData object and creates a config.xml file at
    // the given path out of it.
    public bool fileToStruct(string configXMLPath, ConfigData configData)
    {
        if (!File.Exists(configXMLPath))
            return false;

        using (XmlTextReader configReader = new XmlTextReader(configXMLPath))
        {
            while (configReader.Read())
            {
                if (configReader.NodeType == XmlNodeType.Element)
                {
                    // "Global" Attributes
                    string itNameAttr = "";

                    switch (configReader.Name)
                    {
                        case "ImageTarget":

                            // Parse name from config file
                            itNameAttr = configReader.GetAttribute("name");
                            if (itNameAttr == null)
                            {
                                Debug.LogWarning("Found ImageTarget without " +
                                                 "name attribute in " +
                                                 "config.xml. Image Target " +
                                                 "will be ignored.");
                                continue;
                            }

                            // Parse itSize from config file
                            Vector2 itSize = Vector2.zero;
                            string[] itSizeAttr =
                                configReader.GetAttribute("size").Split(' ');
                            if (itSizeAttr != null)
                            {
                                if (!QCARUtilities.SizeFromStringArray(
                                    out itSize, itSizeAttr))
                                {
                                    Debug.LogWarning("Found illegal itSize " +
                                                     "attribute for Image " +
                                                     "Target " + itNameAttr +
                                                     " in config.xml. " +
                                                     "Image Target will be " +
                                                     "ignored.");
                                    continue;
                                }
                            }
                            else
                            {
                                Debug.LogWarning("Image Target " + itNameAttr +
                                                 " is missing a itSize " +
                                                 "attribut in config.xml. " +
                                                 "Image Target will be " +
                                                 "ignored.");
                                continue;
                            }
                            configReader.MoveToElement();

                            ConfigData.ImageTarget imageTarget =
                                new ConfigData.ImageTarget();

                            imageTarget.size = itSize;
                            imageTarget.virtualButtons =
                                new List<ConfigData.VirtualButton>();

                            configData.SetImageTarget(imageTarget, itNameAttr);

                            break;

                        case "VirtualButton":

                            // Parse name from config file
                            string vbNameAttr =
                                configReader.GetAttribute("name");
                            if (vbNameAttr == null)
                            {
                                Debug.LogWarning("Found VirtualButton " +
                                                 "without name attribute in " +
                                                 "config.xml. Virtual Button " +
                                                 "will be ignored.");
                                continue;
                            }

                            // Parse rectangle from config file
                            Vector4 vbRectangle = Vector4.zero;
                            string[] vbRectangleAttr =
                                configReader.GetAttribute("rectangle").Split(' ');
                            if (vbRectangleAttr != null)
                            {
                                if (!QCARUtilities.RectangleFromStringArray(
                                    out vbRectangle, vbRectangleAttr))
                                {
                                    Debug.LogWarning("Found invalid " +
                                                     "rectangle attribute " +
                                                     "for Virtual Button " +
                                                     vbNameAttr +
                                                     " in config.xml. " +
                                                     "Virtual Button will " +
//.........这里部分代码省略.........
开发者ID:yonutix,项目名称:BattleTroops,代码行数:101,代码来源:ConfigParser.cs

示例3: 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

示例4: Parse

        public void Parse(string filePath)
        {
            try
            {
            XmlTextReader reader = new XmlTextReader(filePath);
            reader.WhitespaceHandling = WhitespaceHandling.None;
            while (reader.Read())
            {
                if (this.inMathNode == true)
                {
                    ParseMath(reader);
                    continue;
                }

                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (reader.Prefix != String.Empty)
                        {
                            // namespaced element not part of SBML
                            reader.Skip();
                        }
                        String elementName = reader.LocalName.ToLower();

                        if (elementName == "notes" ||
                            elementName == "annotation")
                        {
                            // not part of the SBML model
                            //reader.Skip(); // need to skip then move back one node
                            reader.Read();
                        }

                        Hashtable attributes = new Hashtable();
                        if (reader.HasAttributes)
                        {
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                if (reader.Name == "xmlns" && elementName != "math"
                                    && elementName != "sbml")
                                {
                                    // namespaced node/subtree not part of SBML...unless MathML
                                    reader.MoveToElement();
                                    reader.Skip();
                                }
                                if (reader.Name == "specie")
                                {
                                    // horrible leftover from SBML Level 1
                                    attributes.Add("species", reader.Value);
                                }
                                else
                                {
                                    attributes.Add(reader.Name.ToLower(), reader.Value);
                                }
                            }
                        }
                        StartElement(elementName, attributes);
                        break;

                    case XmlNodeType.EndElement:
                        EndElement(reader.LocalName.ToLower());
                        break;
                    // There are many other types of nodes, but
                    // we are not interested in them
                }
            }
            }
            catch (XmlException e)
            {
            Console.WriteLine(e.Message);
            }
        }
开发者ID:dorchard,项目名称:mucell,代码行数:72,代码来源:Reader.cs

示例5: 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


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