XmlReader读取XML
发布时间:2020-12-16 05:24:15 所属栏目:百科 来源:网络整理
导读:留着以后用。 StringBuilder output = new StringBuilder();String xmlString = @"bookstore book genre='autobiography' publicationdate='1981-03-22' ISBN='1-861003-11-0' titleThe Autobiography of Benjamin Franklin/title author first-nameBenjamin
留着以后用。 StringBuilder output = new StringBuilder(); String xmlString = @"<bookstore> <book genre='autobiography' publicationdate='1981-03-22' ISBN='1-861003-11-0'> <title>The Autobiography of Benjamin Franklin</title> <author> <first-name>Benjamin</first-name> <last-name>Franklin</last-name> </author> <price>8.99</price> </book> </bookstore>"; // Create an XmlReader using (XmlReader reader = XmlReader.Create(new StringReader(xmlString))) { reader.ReadToFollowing("book"); if (reader.HasAttributes) { output.Append("Attributes of <" + reader.Name + ">"); for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); output.Append(" " + reader.Name + "=" + reader.Value); } reader.MoveToElement(); // Moves the reader back to the element node. } } OutputTextBlock.Text = output.ToString(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- XStream处理重复的或循环引用
- 【状态压缩搜索】函数依赖
- postgresql – 在数据库中强制执行“至少一个”或“恰好一个
- [译] Alamofire Tutorial: Getting Started
- c# – 如何保存拖动项目的位置
- 使用A *搜索算法来解决3×3三维盒拼图?
- collections – 将org.w3c.dom.NodeList转换为Clojure ISeq
- ruby – RuntimeError::json未在Faraday :: Request上注册
- ruby – 使用https rails app和http faye app时Faye无法正常
- c# – 使变量捕获的闭包不稳定