private ArrayList ReadFromFile(string file) { ArrayList list = new ArrayList(); XmlReader reader = new XmlTextReader(file); while (reader.Read()) { if (reader.NodeType != XmlNodeType.Element) continue; if(string.Compare(reader.Name, @"data") != 0) continue; if (!reader.HasAttributes) continue; if(!reader.MoveToAttribute(@"xml:space")) continue; if (string.Compare(reader.Value, @"preserve") != 0) continue; if (!reader.MoveToAttribute("name")) continue; list.Add(reader.Value); } reader.Close(); return list; }
public List<Article> MakeList(params string[] searchCriteria) { List<Article> articles = new List<Article>(); using ( XmlTextReader reader = new XmlTextReader(new StringReader(Tools.GetHTML(Common.GetUrlFor("displayarticles") + "&count=" + Count)))) { while (reader.Read()) { if (reader.Name.Equals("site")) { reader.MoveToAttribute("address"); string site = reader.Value; if (site != Common.GetSite()) //Probably shouldnt get this as the wanted site was sent to the server { MessageBox.Show("Wrong Site"); } } else if (reader.Name.Equals("article")) { reader.MoveToAttribute("id"); int id = int.Parse(reader.Value); string title = reader.ReadString(); articles.Add(new Article(title)); if (!TypoScanBasePlugin.PageList.ContainsKey(title)) TypoScanBasePlugin.PageList.Add(title, id); } } } TypoScanBasePlugin.CheckoutTime = DateTime.Now; return articles; }
private void Parse( XmlTextReader xml ) { if ( xml.MoveToAttribute( "name" ) ) { m_Name = xml.Value; } else { m_Name = "empty"; } int x = 0, y = 0, z = 0; if ( xml.MoveToAttribute( "x" ) ) { x = Utility.ToInt32( xml.Value ); } if ( xml.MoveToAttribute( "y" ) ) { y = Utility.ToInt32( xml.Value ); } if ( xml.MoveToAttribute( "z" ) ) { z = Utility.ToInt32( xml.Value ); } m_Location = new Point3D( x, y, z ); }
public string[] stworz_liste_plikow_xml() { //tworzenie listy plików z folderu do porównywarki. string[] files = Directory.GetFiles(".", "top100_*.xml"); int i = 0; string data = "", czas = ""; if (files.Length != 0) { foreach (string file in files) { XmlTextReader xtr = new XmlTextReader(file); xtr.Read(); xtr.Read(); xtr.Read(); xtr.MoveToAttribute("data"); data = xtr.Value; xtr.MoveToAttribute("godzina"); czas = xtr.Value; plikiHistoriaKlasa[i] = file.ToString().Substring(2); i++; } } return plikiHistoriaKlasa; }
public void Load (string file, bool system) { XmlTextReader reader = new XmlTextReader (file); string set_name = null; List<string> counters = new List<string> (); while (reader.Read ()) { if (reader.NodeType == XmlNodeType.Element) { string name = reader.Name; if (name == "mperfmon") continue; if (name == "update") { for (int i = 0; i < reader.AttributeCount; ++i) { reader.MoveToAttribute (i); if (reader.Name == "interval") { timeout = uint.Parse (reader.Value); } } continue; } if (name == "set") { for (int i = 0; i < reader.AttributeCount; ++i) { reader.MoveToAttribute (i); if (reader.Name == "name") { set_name = reader.Value; } } continue; } if (name == "counter") { string cat = null, counter = null; for (int i = 0; i < reader.AttributeCount; ++i) { reader.MoveToAttribute (i); if (reader.Name == "cat") { cat = reader.Value; } else if (reader.Name == "name") { counter = reader.Value; } } if (cat != null && counter != null) { counters.Add (cat); counters.Add (counter); } continue; } } else if (reader.NodeType == XmlNodeType.EndElement) { if (reader.Name == "set") { sets.Add (new CounterSet (set_name, counters, system)); set_name = null; counters.Clear (); } } } }
public Currency() { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; try { xml = new XmlTextReader(sourceUrl); //tries to download XML file and create the Reader object } catch (WebException we) // if download is imposible, creates defalt value for BGN and EUR and throws an exception { this.baseCurrency = "EUR"; this.exchangeRates.Add(this.baseCurrency, 1M); this.exchangeRates.Add("BGN", 1.9558M); this.date = DateTime.Now; throw new WebException("Error downloading XML, exchange rate created for BGN only, base currency EUR!", we); } try { while (xml.Read()) { if (xml.Name == "Cube") { if (xml.AttributeCount == 1) { xml.MoveToAttribute("time"); this.date = DateTime.Parse(xml.Value); // gets the date on which this rates are valid } if (xml.AttributeCount == 2) { xml.MoveToAttribute("currency"); this.currency = xml.Value; xml.MoveToAttribute("rate"); try { this.rate = decimal.Parse(xml.Value); } catch (FormatException fe) { throw new FormatException("Urecognised format!", fe); } this.exchangeRates.Add(currency, rate); //ads currency and rate to exchange rate table } xml.MoveToNextAttribute(); } } } catch (XmlException xe) { throw new XmlException("Unable to parse Euro foreign exchange reference rates XML!", xe); } this.baseCurrency = "EUR"; // if XML parsed, add base currency this.exchangeRates.Add(this.baseCurrency, 1M); }
public CAGObject( CAGCategory parent, XmlTextReader xml ) { m_Parent = parent; if ( xml.MoveToAttribute( "type" ) ) m_Type = ScriptCompiler.FindTypeByFullName( xml.Value, false ); if ( xml.MoveToAttribute( "gfx" ) ) m_ItemID = XmlConvert.ToInt32( xml.Value ); if ( xml.MoveToAttribute( "hue" ) ) m_Hue = XmlConvert.ToInt32( xml.Value ); }
public void CreateLookup(SPFeatureReceiverProperties properties, SPWeb web, String filePath) { string fieldId; bool isReading = true; XmlDocument document = GetXmlDocument(properties.Definition, filePath, web.Locale); using (XmlTextReader reader = new XmlTextReader(new StringReader(document.OuterXml))) { CreateListMapping(properties); while (true) { if (reader.LocalName != "Field" || isReading) { if (!reader.Read()) { break; } } if (reader.LocalName == "Field") { if (reader.MoveToAttribute("Type") && reader.Value == "Lookup" && reader.MoveToAttribute("Name")) { fieldId = reader.Value; if (lookupsListMapping.ContainsKey(fieldId)) { String listName = lookupsListMapping[fieldId]; SPList list = GetListForLookup(listName, web); reader.MoveToContent(); XmlDocument doc = new XmlDocument(); String fieldElement = reader.ReadOuterXml(); doc.LoadXml(fieldElement); XPathNavigator navigator = doc.DocumentElement.CreateNavigator(); navigator.CreateAttribute("", "List", "", list.ID.ToString()); SPFieldLookup field = (SPFieldLookup)web.Fields[fieldId]; AddWebIdAttribute(web, doc); field.SchemaXml = RemoveXmlnsAttribute(doc.OuterXml); field.Update(true); isReading = false; continue; } } } isReading = true; } } }
public void LoadConfiguration(String configFilePath) { // Load the config file XmlTextReader xmlReader = null; try { xmlReader = new XmlTextReader(configFilePath); // Read all the infos while (xmlReader.Read()) { xmlReader.MoveToContent(); if (xmlReader.NodeType == XmlNodeType.Element) { switch (xmlReader.Name) { case "TorrentSrcDirectory": xmlReader.MoveToAttribute("path"); m_torrentSrcDirector = xmlReader.Value; break; case "TVShowDirectory": xmlReader.MoveToAttribute("path"); m_tvShowDirectory = xmlReader.Value; break; case "FileExtensions": xmlReader.MoveToAttribute("value"); m_fileExtensions = xmlReader.Value; break; case "TVShow": TVShow tvShow = new TVShow(); ReadTVShowInfos(xmlReader, tvShow); m_tvShows.Add(tvShow); break; } } } } catch (Exception e) { Program.LogMessageToFile(String.Format("Unable to process configuration file, {0}", e.ToString())); } finally { if (xmlReader != null) xmlReader.Close(); } }
private void Parse( XmlTextReader xml ) { if ( xml.MoveToAttribute( "name" ) ) m_Name = xml.Value; else m_Name = "empty"; if ( xml.IsEmptyElement ) { m_Children = new object[0]; } else { ArrayList children = new ArrayList(); while ( xml.Read() && xml.NodeType == XmlNodeType.Element ) { if ( xml.Name == "child" ) { ChildNode n = new ChildNode( xml, this ); children.Add( n ); } else { children.Add( new ParentNode( xml, this ) ); } } m_Children = children.ToArray(); } }
public void ReadXMLFile() { XmlTextReader xmlReader = null; try { string strPath = "C:\\temp\\kai\\Rules\\Russian_1.xml"; xmlReader = new XmlTextReader (strPath); while (xmlReader.Read()) { if (XmlNodeType.Element == xmlReader.NodeType) { sCurrentElement = xmlReader.Name; int nAttr = xmlReader.AttributeCount; for (int iAttr = 0; iAttr < nAttr; ++iAttr) { xmlReader.MoveToAttribute (iAttr); string sAttr = xmlReader.Name; // int ggg = 0; } } // if } // while... } // try catch { int ggg = 0; } finally { xmlReader.Close(); } }
public List<Article> MakeList(params string[] searchCriteria) { List<Article> articles = new List<Article>(); // TODO: must support other wikis if (Variables.Project != ProjectEnum.wikipedia || Variables.LangCode != LangCodeEnum.en) { MessageBox.Show("This plugin currently supports only English Wikipedia", "TypoScan", MessageBoxButtons.OK, MessageBoxIcon.Hand); return articles; } for (int i = 0; i < Iterations; i++) { using ( XmlTextReader reader = new XmlTextReader(new StringReader(Tools.GetHTML(Common.GetUrlFor("displayarticles"))))) { while (reader.Read()) { if (reader.Name.Equals("article")) { reader.MoveToAttribute("id"); int id = int.Parse(reader.Value); string title = reader.ReadString(); articles.Add(new Article(title)); if (!TypoScanAWBPlugin.PageList.ContainsKey(title)) TypoScanAWBPlugin.PageList.Add(title, id); } } } } TypoScanAWBPlugin.CheckoutTime = DateTime.Now; return articles; }
public bool LoadLogs(String[] uris) { try { foreach (String uri in uris) { XML = new XmlTextReader(uri); while (XML.Read()) { Console.Write("loading log"); if (XML.Name == "PointingMagnifier") { p.ReadLog(XML); } if (XML.HasAttributes) { for (int i = 0; i < XML.AttributeCount; i++) { XML.MoveToAttribute(i); } } } } } catch { return false; } lblNumStates.Text = String.Format("States: {0}", p.NumStates()); lblNumEvents.Text = String.Format("Events: Active - {0}, Inactive - {1}", p.NumActiveEvents(), p.NumNonActiveEvents()); return true; }
public CAGCategory( CAGCategory parent, XmlTextReader xml ) { m_Parent = parent; if ( xml.MoveToAttribute( "title" ) ) m_Title = xml.Value; else m_Title = "empty"; if ( m_Title == "Docked" ) m_Title = "Docked 2"; if ( xml.IsEmptyElement ) { m_Nodes = new CAGNode[0]; } else { ArrayList nodes = new ArrayList(); /*while ( xml.Read() && xml.NodeType != XmlNodeType.EndElement ) { if ( xml.NodeType == XmlNodeType.Element && xml.Name == "object" ) nodes.Add( new CAGObject( this, xml ) ); else if ( xml.NodeType == XmlNodeType.Element && xml.Name == "category" ) nodes.Add( new CAGCategory( this, xml ) ); else xml.Skip(); }*/ m_Nodes = (CAGNode[])nodes.ToArray( typeof( CAGNode ) ); } }
/// <summary> /// Parser recursiv de elemente XML. /// </summary> /// <param name="reader">Cititorul secvenţial care a deschis fişierul XML</param> /// <returns>Elementul XML parsat care conţine toate atributele şi subelementele sale</returns> private static XMLElement readCurrentElement(XmlTextReader reader) { if (!reader.IsStartElement()) { return null; } bool hasChildren = !reader.IsEmptyElement; XMLElement result = new XMLElement(); for (int i = 0; i < reader.AttributeCount; ++i) { reader.MoveToAttribute(i); result.addAttribute(reader.Name, reader.Value); } if (hasChildren) { while (reader.Read() && reader.NodeType != XmlNodeType.EndElement) { if (reader.IsStartElement()) { result.addElement(reader.Name, readCurrentElement(reader)); } } } reader.Read(); return result; }
private string serializeXMLtoJSON(string xmlString) { XmlTextReader reader = new XmlTextReader(new System.IO.StringReader(xmlString)); string parsedString = ""; while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: parsedString += "\"" + reader.Name + "\":{"; if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); parsedString += "\"" + reader.Name + "\":"; parsedString += "\"" + reader.Value + "\","; } } parsedString = parsedString.TrimEnd(charsToTrim); if (reader.HasValue) { parsedString += "},"; }//--looks for any attributes parsedString += "\n"; break; case XmlNodeType.Text: break; case XmlNodeType.EndElement: break; } } parsedString = parsedString.TrimEnd(charsToTrim); return parsedString; }
// logs the user in and accesses their userId and userName public static void loginUser(out string userId, out string userName) { OAuth oAuth = new OAuth(); oAuth.getOAuthToken(); string userXML = oAuth.getOAuthDataUrl("http://www.goodreads.com/api/auth_user"); userId = ""; userName = ""; // grab the user name and user id XmlTextReader textReader = new XmlTextReader(userXML); while (textReader.Read()) { textReader.MoveToElement(); if (textReader.LocalName.Equals("user")) { textReader.MoveToAttribute("id"); userId = textReader.Value; } if (textReader.LocalName.Equals("name")) { userName = textReader.ReadElementContentAsString(); } } }
static void Main(string[] args) { XmlTextReader reader = new XmlTextReader ("Stats.xml"); reader.Read(); while (reader.Read()) { if (reader.HasAttributes) { reader.MoveToAttribute("id"); string id = reader.Value; reader.MoveToAttribute("Name"); string name = reader.Value; Console.WriteLine("| " + id + " | " + name + " |"); reader.MoveToElement(); } } }
internal static string GetXomlManifestName(string fileName, string linkFileName, string rootNamespace, Stream binaryStream) { string str = string.Empty; string name = linkFileName; if ((name == null) || (name.Length == 0)) { name = fileName; } System.Workflow.ComponentModel.Compiler.Culture.ItemCultureInfo itemCultureInfo = System.Workflow.ComponentModel.Compiler.Culture.GetItemCultureInfo(name); if (binaryStream != null) { string str3 = null; try { XmlTextReader reader = new XmlTextReader(binaryStream); if ((reader.MoveToContent() == XmlNodeType.Element) && reader.MoveToAttribute("Class", "http://schemas.microsoft.com/winfx/2006/xaml")) { str3 = reader.Value; } } catch { } if ((str3 != null) && (str3.Length > 0)) { str = str3; if ((itemCultureInfo.culture != null) && (itemCultureInfo.culture.Length > 0)) { str = str + "." + itemCultureInfo.culture; } } } if (str.Length == 0) { if (!string.IsNullOrEmpty(rootNamespace)) { str = rootNamespace + "."; } string str4 = CreateManifestResourceName.MakeValidEverettIdentifier(Path.GetDirectoryName(itemCultureInfo.cultureNeutralFilename)); if (string.Compare(Path.GetExtension(itemCultureInfo.cultureNeutralFilename), ".resx", StringComparison.OrdinalIgnoreCase) == 0) { str = (str + Path.Combine(str4, Path.GetFileNameWithoutExtension(itemCultureInfo.cultureNeutralFilename))).Replace(Path.DirectorySeparatorChar, '.').Replace(Path.AltDirectorySeparatorChar, '.'); if ((itemCultureInfo.culture != null) && (itemCultureInfo.culture.Length > 0)) { str = str + "." + itemCultureInfo.culture; } return str; } str = (str + Path.Combine(str4, Path.GetFileName(itemCultureInfo.cultureNeutralFilename))).Replace(Path.DirectorySeparatorChar, '.').Replace(Path.AltDirectorySeparatorChar, '.'); if ((itemCultureInfo.culture != null) && (itemCultureInfo.culture.Length > 0)) { str = itemCultureInfo.culture + Path.DirectorySeparatorChar + str; } } return str; }
private Dictionary<string, ClassInfo> Parse(XmlTextReader reader) { XmlNamespaceManager nps = new XmlNamespaceManager(reader.NameTable); Dictionary<string, ClassInfo> table = new Dictionary<string, ClassInfo>(); ParentInfo parent = null; string previousNode = null; while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.EndElement) { ////Got an element. This will be the name of a class. string className = reader.LocalName; if (className.Equals("rss", StringComparison.OrdinalIgnoreCase)) { nps = new XmlNamespaceManager(reader.NameTable); for (int index = 0; index < reader.AttributeCount; index++) { { reader.MoveToAttribute(index); if (reader.Name.StartsWith("xmlns")) { nps.AddNamespace(reader.LocalName, reader.Value); } } } } if (reader.IsStartElement() || reader.IsEmptyElement) { ParseStartElements(reader, table, parent, nps, className); } else { ParseEndElements(table, className); } previousNode = className; } else if (reader.NodeType == XmlNodeType.Text) { if (!string.IsNullOrEmpty(previousNode)) { ClassInfo classInfo = table[previousNode]; classInfo.IsText = true; } } } return table; }
private void Parse(XmlTextReader xml) { if (xml.MoveToAttribute("name")) this.m_Name = xml.Value; else this.m_Name = "empty"; int x = 0, y = 0, z = 0; if (xml.MoveToAttribute("x")) x = Utility.ToInt32(xml.Value); if (xml.MoveToAttribute("y")) y = Utility.ToInt32(xml.Value); if (xml.MoveToAttribute("z")) z = Utility.ToInt32(xml.Value); this.m_Location = new Point3D(x, y, z); }
protected override void ProcessingHook(XmlTextReader reader) { string name = reader.Name.ToLower(); // Extract dependencies if (name.Equals("depend")) { if (reader.MoveToAttribute("stack")) { this.dep_names.Add(reader.Value); } } }
public void RefreshNews() { new Thread(delegate() { Thread.CurrentThread.IsBackground = true; try { var data = new System.Net.WebClient().DownloadString("http://d-ide.sourceforge.net/classes/news.php?xml=1&max=20&fromIDE=1"); var xr = new XmlTextReader(new StringReader(data)); _LastRetrievedNews.Clear(); while (xr.Read()) { if (xr.LocalName != "n") continue; var i = new NewsItem(); if (xr.MoveToAttribute("id")) i.Id = Convert.ToInt32(xr.GetAttribute("id")); if (xr.MoveToAttribute("timestamp")) i.Timestamp = Util.DateFromUnixTime(Convert.ToInt64(xr.GetAttribute("timestamp"))); xr.MoveToElement(); i.Content = Util.StripXmlTags(xr.ReadString()); _LastRetrievedNews.Add(i); } xr.Close(); } catch { } NewsList.Dispatcher.Invoke(new Action(delegate() { NewsList.ItemsSource = _LastRetrievedNews; })); }).Start(); }
public GBXMLContainer(XmlTextReader reader) { while (reader.NodeType != XmlNodeType.Element) { reader.Read(); } name = reader.Name; // check if the element has any attributes if (reader.HasAttributes) { // move to the first attribute reader.MoveToFirstAttribute (); for (int i = 0; i < reader.AttributeCount; i++) { // read the current attribute reader.MoveToAttribute (i); if (AttributesToChildren) { GBXMLContainer newChild = new GBXMLContainer(); newChild.name = reader.Name; newChild.textValue = reader.Value; children.Add(newChild); } else { attributes [reader.Name] = reader.Value; } } } reader.MoveToContent (); bool EndReached = reader.IsEmptyElement; while (!EndReached && reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: GBXMLContainer newChild = new GBXMLContainer (reader); children.Add (newChild); break; case XmlNodeType.Text: textValue = reader.Value; break; case XmlNodeType.XmlDeclaration: case XmlNodeType.ProcessingInstruction: break; case XmlNodeType.Comment: break; case XmlNodeType.EndElement: EndReached = true; break; } } }
public OpenXML_Zefania_XML_Bible_Markup_Language(string fileLocation, bible_data.BookManipulator manipulator) { _fileLocation = fileLocation; _reader = new XmlTextReader(_fileLocation); _bible = manipulator; // Create an XmlReader for <format>Zefania XML Bible Markup Language</format> using (_reader) { _reader.ReadToFollowing("title"); String title = _reader.ReadElementContentAsString(); _bible.SetVersion(title); String book; int verseNumber; int chapterNumber; string verseString; while (_reader.ReadToFollowing("BIBLEBOOK")) // read each book name { _reader.MoveToAttribute(1); book = _reader.Value; _reader.ReadToFollowing("CHAPTER"); while (_reader.Name == "CHAPTER") // read each chapter { _reader.MoveToFirstAttribute(); chapterNumber = Convert.ToInt32(_reader.Value); _reader.ReadToFollowing("VERS"); while (_reader.Name == "VERS") // read each verse { _reader.MoveToFirstAttribute(); verseNumber = Convert.ToInt32(_reader.Value); _reader.Read(); verseString = _reader.Value; sendToDataTree(book, verseNumber, chapterNumber, verseString); _reader.Read(); _reader.Read(); _reader.Read(); }//end verse while _reader.Read(); _reader.Read(); } //end chapter while } // end book while } //end using statement }
protected override void LoadSong() { using (XmlTextReader reader = new XmlTextReader(this.PlaylistPath)) { while (reader.Read()) { if (reader.Name != _parentTagName) continue; reader.MoveToAttribute("src"); if (Path.IsPathRooted(reader.Value)) this.Songs.Add(new Song(reader.Value)); else this.Songs.Add(new Song(Path.Combine(Path.GetDirectoryName(this.PlaylistPath), reader.Value))); } } }
public XmlAddCAGCategory( XmlAddCAGCategory parent, XmlTextReader xml ) { m_Parent = parent; if ( xml.MoveToAttribute( "title" ) ) { if(xml.Value == "Add Menu") m_Title = "XmlAdd Menu"; else m_Title = xml.Value; } else m_Title = "empty"; if ( m_Title == "Docked" ) m_Title = "Docked 2"; if ( xml.IsEmptyElement ) { m_Nodes = new XmlAddCAGNode[0]; } else { ArrayList nodes = new ArrayList(); try{ while ( xml.Read() && xml.NodeType != XmlNodeType.EndElement ) { if ( xml.NodeType == XmlNodeType.Element && xml.Name == "object" ) nodes.Add( new XmlAddCAGObject( this, xml ) ); else if ( xml.NodeType == XmlNodeType.Element && xml.Name == "category" ) nodes.Add( new XmlAddCAGCategory( this, xml ) ); else xml.Skip(); } } catch (Exception ex){ Console.WriteLine("XmlCategorizedAddGump: Corrupted Data/objects.xml file detected. Not all XmlCAG objects loaded. {0}", ex); } m_Nodes = (XmlAddCAGNode[])nodes.ToArray( typeof( XmlAddCAGNode ) ); } }
public List<Article> MakeList(string[] searchCriteria) { List<Article> articles = new List<Article>(); int start = 0; foreach (string s in searchCriteria) { do { string url = string.Format(BaseUrl, s, Variables.URL, NoOfResultsPerRequest, start); using (XmlTextReader reader = new XmlTextReader(new StringReader(Tools.GetHTML(url)))) { while (reader.Read()) { if (reader.Name.Equals("Message")) { if (string.Compare(reader.ToString(), "limit exceeded", true) == 0) Tools.MessageBox("Query limit for Yahoo Exceeded. Please try again later"); return articles; } if (reader.Name.Equals("ResultSet")) { reader.MoveToAttribute("totalResultsAvailable"); if (!string.IsNullOrEmpty(reader.Value) && int.Parse(reader.Value) > TotalResults) start += NoOfResultsPerRequest; } if (reader.Name.Equals("ClickUrl")) { string title = Tools.GetTitleFromURL(reader.ReadString()); if (!string.IsNullOrEmpty(title)) articles.Add(new Article(title)); } } } } while (articles.Count < TotalResults); } return articles; }
public void Parse(XmlTextReader reader) { try { while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: string namespaceURI = reader.NamespaceURI; string name = reader.Name; bool isEmpty = reader.IsEmptyElement; Hashtable attributes = new Hashtable(); if (reader.HasAttributes) { for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); attributes.Add(reader.Name,reader.Value); } } this.StartElement(namespaceURI, name, name, attributes); if (isEmpty) { EndElement(namespaceURI, name, name); } break; case XmlNodeType.EndElement: EndElement(reader.NamespaceURI, reader.Name, reader.Name); break; case XmlNodeType.Text: Characters(reader.Value, 0, reader.Value.Length); break; // There are many other types of nodes, but // we are not interested in them case XmlNodeType.Whitespace: Characters(reader.Value, 0, reader.Value.Length); break; } } } catch (XmlException e) { Console.WriteLine(e.Message); } finally { if (reader != null) { reader.Close(); } } }
static OrderWizard() { string conditionsDataPath = HttpContext.Current.Server.MapPath(PathToJoesPubSeatingConditions); XmlTextReader reader = new XmlTextReader(conditionsDataPath); if (!reader.ReadToFollowing("pubSeatingConditions")) throw new XmlException("Can't find <pubSeatingConditions> node."); if (!reader.ReadToDescendant("section")) throw new XmlException("Can't find any <section> nodes."); syosSeatingConditions = new Dictionary<int, string>(); do { if (!reader.MoveToAttribute("id")) throw new XmlException("Can't find \"id\" attribute for <section>."); int id = Int32.Parse(reader.Value.Trim()); reader.MoveToElement(); string conditions = reader.ReadElementContentAsString(); syosSeatingConditions.Add(id, conditions); } while (reader.ReadToNextSibling("section")); }