[英]C# code to search and result in xml
我在一些C#代码之后,这些代码将具有以下方法,这些方法将返回Xml作为结果。
搜索Apple iTunes App商店。 如果我给它传递一个名称或部分名称,则该函数必须返回可能搜索结果的列表,或者如果完美匹配则仅返回一个结果。
示例如下所示:
<App>
<AppId>321564880</AppId>
<Name>Doodle Clock - Clock A Doodle Do!</Name>
<ReleaseDate>Released Sep 28, 2009</ReleaseDate>
<Artist>YARG</Artist>
<Description>Description of App</Description>
<Copyright>© YARG Limited 2009</Copyright>
<Price>$0.99</Price>
<Category>Lifestyle</Category>
<MainImageUrl><!—main App icon image urlà </ImageUrl>
<ExtraImages>
<!-- these will be the extra images you see in the App store other than the main application icon -->
<ImageUrl> <!—url of extra image 1à</ImageUrl>
<ImageUrl> <!—url of extra image 2à</ImageUrl>
<ImageUrl> <!—url of extra image 3à</ImageUrl>
</ExtraImages>
<Version>Version: 1.1 (iPhone OS 3.0 Tested)</Version>
<Size>1.5 MB</Size>
</App>
好的,创建xml文件并进行解析和操作的最佳方法是使用XDocument
, XElement
等。 因为它们是可枚举的,这意味着您可以在它们上使用LINQ,这将对您有所帮助。
例如 :
XElement element = new XElement("Persons",
new XElement("Person","John",
new XAttribute("Id","1")),
new XElement("Person","Aaron",
new XAttribute("Id",2))
)
回报
<Persons>
<Person Id="1">John</Person>
<Person Id="2">Aaron</Person>
</Person>
详细信息: System.Xml.Linq Namespace
如果您正在寻找速度,那么可以使用XMLReader
和XMLWriter
但是找不到System.Xml.Linq
提供的灵活性。
您应该在.NET中使用XPath: http : //www.aspfree.com/c/a/.NET/Working-with-XPath-The-NET-Way/
我会使用XmlTextReader 。 如果您正在寻找速度,这是最快的方法(尽管是只读的)。 如果不是,则XPath应该这样做。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.