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


C# Xml.XmlTextReader类代码示例

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


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

示例1: PhotoInfoParseFull

        public void PhotoInfoParseFull()
        {
            string x = "<photo id=\"7519320006\">"
                    + "<location latitude=\"54.971831\" longitude=\"-1.612683\" accuracy=\"16\" context=\"0\" place_id=\"Ke8IzXlQV79yxA\" woeid=\"15532\">"
                    + "<neighbourhood place_id=\"Ke8IzXlQV79yxA\" woeid=\"15532\">Central</neighbourhood>"
                    + "<locality place_id=\"DW0IUrFTUrO0FQ\" woeid=\"20928\">Gateshead</locality>"
                    + "<county place_id=\"myqh27pQULzLWcg7Kg\" woeid=\"12602156\">Tyne and Wear</county>"
                    + "<region place_id=\"2eIY2QFTVr_DwWZNLg\" woeid=\"24554868\">England</region>"
                    + "<country place_id=\"cnffEpdTUb5v258BBA\" woeid=\"23424975\">United Kingdom</country>"
                    + "</location>"
                    + "</photo>";

            System.IO.StringReader sr = new System.IO.StringReader(x);
            System.Xml.XmlTextReader xr = new System.Xml.XmlTextReader(sr);
            xr.Read();

            var info = new PhotoInfo();
            ((IFlickrParsable)info).Load(xr);

            Assert.AreEqual("7519320006", info.PhotoId);
            Assert.IsNotNull(info.Location);
            Assert.AreEqual((GeoAccuracy)16, info.Location.Accuracy);

            Assert.IsNotNull(info.Location.Country);
            Assert.AreEqual("cnffEpdTUb5v258BBA", info.Location.Country.PlaceId);
        }
开发者ID:JamieKitson,项目名称:flickrnet-experimental,代码行数:26,代码来源:PhotosGeoTests.cs

示例2: GetBytes

        /// <summary>
        /// Creates a byte array from the hexadecimal string. Each two characters are combined
        /// to create one byte. First two hexadecimal characters become first byte in returned array.
        /// Non-hexadecimal characters are ignored. 
        /// </summary>
        /// <param name="hexString">string to convert to byte array</param>
        /// <param name="discarded">number of characters in string ignored</param>
        /// <returns>byte array, in the same left-to-right order as the hexString</returns>
        public static byte[] GetBytes(string hexString, out int discarded)
        {
            discarded = 0;

            // XML Reader/Writer is highly optimized for BinHex conversions
            // use instead of byte/character replacement for performance on
            // arrays larger than a few dozen elements

            hexString = "<node>" + hexString + "</node>";

            System.Xml.XmlTextReader tr = new System.Xml.XmlTextReader(
                hexString,
                System.Xml.XmlNodeType.Element,
                null);

            tr.Read();

            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            int bufLen = 1024;
            int cap = 0;
            byte[] buf = new byte[bufLen];

            do
            {
                cap = tr.ReadBinHex(buf, 0, bufLen);
                ms.Write(buf, 0, cap);
            } while (cap == bufLen);

            return ms.ToArray();
        }
开发者ID:AnthonyGilliam,项目名称:LikeMyDessert,代码行数:39,代码来源:HexEncoding.cs

示例3: Deserialize

 public static TransactionSpecification Deserialize(string xml)
 {
     System.IO.StringReader stringReader = new System.IO.StringReader(xml);
     System.Xml.XmlTextReader xmlTextReader = new System.Xml.XmlTextReader(stringReader);
     System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(TransactionSpecification));
     return ((TransactionSpecification)(xmlSerializer.Deserialize(xmlTextReader)));
 }
开发者ID:hitgeek,项目名称:OopFactoryX12Parser,代码行数:7,代码来源:TransactionSpecification.cs

示例4: IsolatedStorage_Read_and_Write_Sample

        public static void IsolatedStorage_Read_and_Write_Sample()
        {
            string fileName = @"SelfWindow.xml";

            IsolatedStorageFile storFile = IsolatedStorageFile.GetUserStoreForDomain();
            IsolatedStorageFileStream storStream = new IsolatedStorageFileStream(fileName, FileMode.Create, FileAccess.Write);
            System.Xml.XmlWriter writer = new System.Xml.XmlTextWriter(storStream, Encoding.UTF8);
            writer.WriteStartDocument();

            writer.WriteStartElement("Settings");

            writer.WriteStartElement("UserID");
            writer.WriteValue(42);
            writer.WriteEndElement();
            writer.WriteStartElement("UserName");
            writer.WriteValue("kingwl");
            writer.WriteEndElement();

            writer.WriteEndElement();

            writer.Flush();
            writer.Close();
            storStream.Close();

            string[] userFiles = storFile.GetFileNames();

            foreach(var userFile in userFiles)
            {
                if(userFile == fileName)
                {
                    var storFileStreamnew =  new IsolatedStorageFileStream(fileName,FileMode.Open,FileAccess.Read);
                    StreamReader storReader = new StreamReader(storFileStreamnew);
                    System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(storReader);

                    int UserID = 0;
                    string UserName = null;

                    while(reader.Read())
                    {
                        switch(reader.Name)
                        {
                            case "UserID":
                                UserID = int.Parse(reader.ReadString());
                                break;
                            case "UserName":
                                UserName = reader.ReadString();
                                break;
                            default:
                                break;
                        }
                    }

                    Console.WriteLine("{0} {1}", UserID, UserName);

                    storFileStreamnew.Close();
                }
            }
            storFile.Close();
        }
开发者ID:xxy1991,项目名称:cozy,代码行数:59,代码来源:D8IsolatedStorageReadAndWrite.cs

示例5: LoadHighlightingDefinition

 private void LoadHighlightingDefinition()
 {
   var xshdUri = App.GetResourceUri("simai.xshd");
   var rs = Application.GetResourceStream(xshdUri);
   var reader = new System.Xml.XmlTextReader(rs.Stream);
   definition = HighlightingLoader.Load(reader, HighlightingManager.Instance);
   reader.Close();
 }
开发者ID:youaoi,项目名称:simaiAssistant,代码行数:8,代码来源:Editor.xaml.cs

示例6: Copy

		///<summary>
		///Create a full copy of the current properties
		///</summary>
		public MySection Copy()
		{
			MySection copy = new MySection();
			string xml = SerializeSection(this, "MySection", ConfigurationSaveMode.Full);
			System.Xml.XmlReader rdr = new System.Xml.XmlTextReader(new System.IO.StringReader(xml));
			copy.DeserializeSection(rdr);
			return copy;
		}
开发者ID:josecohenca,项目名称:xmlconvertsql,代码行数:11,代码来源:MySection.cs

示例7: Deserialize

        public static SegmentSet Deserialize(string xml)
        {
            System.IO.StringReader stringReader = new System.IO.StringReader(xml);
            System.Xml.XmlTextReader xmlTextReader = new System.Xml.XmlTextReader(stringReader);
            System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(SegmentSet));

            return ((SegmentSet)(xmlSerializer.Deserialize(xmlTextReader)));
        }
开发者ID:hitgeek,项目名称:OopFactoryX12Parser,代码行数:8,代码来源:SegmentSet.cs

示例8: NameAndCasNmber

 static public string[] NameAndCasNmber(string compoundName)
 {
     string[] retVal = new string[2];
     gov.nih.nlm.chemspell.SpellAidService service = new gov.nih.nlm.chemspell.SpellAidService();
     string response = service.getSugList(compoundName, "All databases");
     var XMLReader = new System.Xml.XmlTextReader(new System.IO.StringReader(response));
     System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Synonym));
     if (serializer.CanDeserialize(XMLReader))
     {
         Synonym synonym = (Synonym)serializer.Deserialize(XMLReader);
         foreach (SynonymChemical chemical in synonym.Chemical)
         {
             int result = String.Compare(compoundName, chemical.Name, true);
             if (result == 0)
             {
                 retVal[0] = chemical.CAS;
                 retVal[1] = chemical.Name;
                 return retVal;
             }
         }
     }
     serializer = new System.Xml.Serialization.XmlSerializer(typeof(SpellAid));
     if (serializer.CanDeserialize(XMLReader))
     {
         SpellAid aid = (SpellAid)serializer.Deserialize(XMLReader);
         bool different = true;
         retVal[0] = aid.Chemical[0].CAS;
         retVal[1] = aid.Chemical[0].Name;
         for (int i = 0; i < aid.Chemical.Length - 1; i++)
         {
             if (retVal[0] != aid.Chemical[i + 1].CAS)
             {
                 different = false;
                 retVal[0] = aid.Chemical[i].CAS;
                 retVal[1] = aid.Chemical[i].Name;
             }
         }
         if (!different)
         {
             foreach (SpellAidChemical chemical in aid.Chemical)
             {
                 int result = String.Compare(compoundName, 0, chemical.Name, 0, compoundName.Length, true);
                 if (result == 0 && compoundName.Length >= chemical.Name.Length)
                 {
                     retVal[0] = chemical.CAS;
                     retVal[1] = chemical.Name;
                     return retVal;
                 }
             }
             SelectChemicalForm form = new SelectChemicalForm(aid, compoundName);
             form.ShowDialog();
             retVal[0] = form.SelectedChemical.CAS;
             retVal[1] = form.SelectedChemical.Name;
             return retVal;
         }
     }
     return retVal;
 }
开发者ID:wbarret1,项目名称:ChemicalDataSourcesTestApp,代码行数:58,代码来源:NistChemicalList.cs

示例9: GetXmlData

        public XmlActionResult GetXmlData()
        {
            LogInfo();

            System.Xml.XmlTextReader reader =
              new System.Xml.XmlTextReader(Server.MapPath("~/Book.xml"));
            var xml = XElement.Load(reader);
            return new XmlActionResult(xml.ToString(), "book.xml");
        }
开发者ID:sabotuer99,项目名称:ExtensibilityMVC,代码行数:9,代码来源:XmlController.cs

示例10: Unmarshall

        public override WebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(context.ResponseStream);
            BatchReceiveMessageResponse batchReceiveMessageResponse = new BatchReceiveMessageResponse();
            Message message = null;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case System.Xml.XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                            case MNSConstants.XML_ROOT_MESSAGE:
                                message = new Message();
                                break;
                            case MNSConstants.XML_ELEMENT_MESSAGE_ID:
                                message.Id = reader.ReadElementContentAsString();
                                break;
                            case MNSConstants.XML_ELEMENT_RECEIPT_HANDLE:
                                message.ReceiptHandle = reader.ReadElementContentAsString();
                                break;
                            case MNSConstants.XML_ELEMENT_MESSAGE_BODY_MD5:
                                message.BodyMD5 = reader.ReadElementContentAsString();
                                break;
                            case MNSConstants.XML_ELEMENT_MESSAGE_BODY:
                                message.Body = reader.ReadElementContentAsString();
                                break;
                            case MNSConstants.XML_ELEMENT_ENQUEUE_TIME:
                                message.EnqueueTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(reader.ReadElementContentAsLong());
                                break;
                            case MNSConstants.XML_ELEMENT_NEXT_VISIBLE_TIME:
                                message.NextVisibleTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(reader.ReadElementContentAsLong());
                                break;
                            case MNSConstants.XML_ELEMENT_FIRST_DEQUEUE_TIME:
                                message.FirstDequeueTime = AliyunSDKUtils.ConvertFromUnixEpochSeconds(reader.ReadElementContentAsLong());
                                break;
                            case MNSConstants.XML_ELEMENT_DEQUEUE_COUNT:
                                message.DequeueCount = (uint)reader.ReadElementContentAsInt();
                                break;
                            case MNSConstants.XML_ELEMENT_PRIORITY:
                                message.Priority = (uint)reader.ReadElementContentAsInt();
                                break;
                        }
                        break;
                    case System.Xml.XmlNodeType.EndElement:
                        if (reader.LocalName == MNSConstants.XML_ROOT_MESSAGE)
                        {
                            batchReceiveMessageResponse.Messages.Add(message);
                        }
                        break;
                }
            }
            reader.Close();
            return batchReceiveMessageResponse;
        }
开发者ID:a526757124,项目名称:YCTYProject,代码行数:56,代码来源:BatchReceiveMessageResponseUnmarshaller.cs

示例11: GetSummary

 /// <summary>
 /// Currently a naive implementation. Treats all fields under summary as text.
 /// </summary>
 /// <param name="xmlDocumentation"></param>
 /// <returns></returns>
 public string GetSummary(string xmlDocumentation)
 {
     var frag = new System.Xml.XmlTextReader(xmlDocumentation, System.Xml.XmlNodeType.Element, null);
     string result = "";
     while (frag.Read()) {
         result += frag.Value;
     }
     frag.Close();
     return result;
 }
开发者ID:flukus,项目名称:doCS,代码行数:15,代码来源:XmlDocumentationHelper.cs

示例12: ReadSettings

        /// <summary>
        /// loads a configuration from a xml-file - if there isn't one, use default settings
        /// </summary>
        public void ReadSettings()
        {
            bool dirty = false;
            Reset();
            try
            {
                System.Xml.XmlTextReader xmlConfigReader = new System.Xml.XmlTextReader("settings.xml");
                while (xmlConfigReader.Read())
                {
                    if (xmlConfigReader.NodeType == System.Xml.XmlNodeType.Element)
                    {
                        switch (xmlConfigReader.Name)
                        {
                            case "display":
                                fullscreen = Convert.ToBoolean(xmlConfigReader.GetAttribute("fullscreen"));
                                resolutionX = Convert.ToInt32(xmlConfigReader.GetAttribute("resolutionX"));
                                resolutionY = Convert.ToInt32(xmlConfigReader.GetAttribute("resolutionY"));

                                // validate resolution
                                // TODO
                              /*  if (!GraphicsAdapter.DefaultAdapter.SupportedDisplayModes.Any(x => x.Format == SurfaceFormat.Color &&
                                                                                                x.Height == resolutionY && x.Width == resolutionX))
                                {
                                    ChooseStandardResolution();
                                    dirty = true;
                                } */
                                break;
                        }
                    }
                }
                xmlConfigReader.Close();
            }
            catch
            {
                // error in xml document - write a new one with standard values
                try
                {
                    Reset();
                    dirty = true;
                }
                catch
                {
                }
            }

            // override fullscreen resolutions
            if (fullscreen)
            {
                ResolutionX = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
                ResolutionY = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
            }

            if(dirty)
                Save();
        }
开发者ID:Jojendersie,项目名称:Voxelseeds,代码行数:58,代码来源:Settings.cs

示例13: Collection_Loaded

 private void Collection_Loaded(object sender, RoutedEventArgs e)
 {
     using (var stream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("a7DocumentDbStudio.Resources.avalonEditSql.xshd"))
     {
         using (var reader = new System.Xml.XmlTextReader(stream))
         {
             this.sqlEditor.SyntaxHighlighting =
                 ICSharpCode.AvalonEdit.Highlighting.Xshd.HighlightingLoader.Load(reader,
                 ICSharpCode.AvalonEdit.Highlighting.HighlightingManager.Instance);
         }
     }
 }
开发者ID:alekkowalczyk,项目名称:a7DocumentDbStudio,代码行数:12,代码来源:Collection.xaml.cs

示例14: TestADOTabularCSDLVisitor

        public void TestADOTabularCSDLVisitor()
        {
            ADOTabularConnection c = new ADOTabularConnection("Data Source=localhost", AdomdType.AnalysisServices);
            MetaDataVisitorCSDL v = new MetaDataVisitorCSDL(c);
            ADOTabularModel m = new ADOTabularModel(c, "Test","Test", "Test Description", "");
            System.Xml.XmlReader xr = new System.Xml.XmlTextReader(@"..\..\data\csdl.xml");
            var tabs = new ADOTabularTableCollection(c,m);

            v.GenerateTablesFromXmlReader(tabs, xr);

            Assert.AreEqual(4, tabs.Count);
            Assert.AreEqual(8, tabs["Sales"].Columns.Count());
        }
开发者ID:votrongdao,项目名称:DaxStudio,代码行数:13,代码来源:ADOTabularTests.cs

示例15: SettingsServer

        public SettingsServer(string profileFolderName, string profileDisplayName)
        {
            InitValues();

            ProfileFolderName = profileFolderName;
            ProfileDisplayName = profileDisplayName;

            try
            {
                if (!Directory.Exists(ProfileFolder))
                    Directory.CreateDirectory(ProfileFolder);

                foreach (string path in new string[] { ProfileFolder, StoreToFileFolder })
                {
                    try
                    {
                        if (!System.IO.Directory.Exists(path))
                            System.IO.Directory.CreateDirectory(path);
                    }
                    catch (System.Exception ex) { GenLib.Log.LogService.LogException("Unable to create folder: " + path + "\nError: ", ex); }
                }

                if (File.Exists(Path.Combine(ProfileFolder, SettingsFileName)))
                {
                    lock (lockObj)
                    {
                        using (System.Xml.XmlTextReader input = new System.Xml.XmlTextReader(Path.Combine(ProfileFolder, SettingsFileName)))
                        {
                            XmlSerializer serializer = new XmlSerializer(typeof(SettingsServer));
                            SettingsServer sett = (SettingsServer)serializer.Deserialize(input);
                            InitValues(sett);
                        }
                    }
                }
                else
                {
                    // since this is the first time we are loading this profile (settings don't exist yet)
                    // create a new version file so that we know what version of data is contained in this folder
                    WriteVersionData(ProfileFolder);
                    SaveSettings();
                }
            }
            catch (Exception ex) { GenLib.Log.LogService.LogException("Settings. LoadSettings failed.", ex); }

            try { File.Create(Path.Combine(ProfileFolder, "ProfileName-" + profileDisplayName + ".txt")); }		// try creating the filename containing the profile name
            catch	// if there are invalid chars then create a file and inside of it put the profile name
            {
                try { File.WriteAllText(Path.Combine(ProfileFolder, "ProfileName.txt"), profileDisplayName); }
                catch { }
            }
        }
开发者ID:AlertProject,项目名称:Text-processing-bundle,代码行数:51,代码来源:SettingsServer.cs


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