XML解析蒸汽组API
本文关键字:API XML | 更新日期: 2023-09-27 18:08:00
我有一个问题:
如何在这个特定的文档中解析XML:http://steamcommunity.com/groups/BotBrothers/memberslistxml/?xml=1& p = 1
我想在一个文件文档中逐行获取所有的<STEAMID64>
它不是另一个的副本,我需要这个,因为它的工作方式不同
试试下面的代码。我必须将第一行从standalone="true"改为standalone="yes"
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:'temp'test.xml";
static void Main(string[] args)
{
string file = File.ReadAllText(FILENAME);
file = file.Replace("standalone='"true'"", "standalone='"yes'"");
StringReader reader = new StringReader(file);
XmlSerializer xs = new XmlSerializer(typeof(MemberList));
MemberList members = (MemberList)xs.Deserialize(reader);
}
}
[XmlRoot("memberList")]
public class MemberList
{
[XmlElement("groupID64")]
public string groupID64 { get; set;}
[XmlElement("groupDetails")]
public GroupDetails groupDetails { get; set;}
[XmlElement("nextPageLink")]
public Text nextPageLink { get; set; }
[XmlElement("members")]
public Members members { get; set; }
}
[XmlRoot("groupDetails")]
public class GroupDetails
{
[XmlElement("groupName")]
public Text groupName { get; set; }
[XmlElement("groupURL")]
public Text groupURL { get; set; }
[XmlElement("headline")]
public Text headline { get; set; }
[XmlElement("summary")]
public Text summary { get; set; }
[XmlElement("avatarIcon")]
public Text avatarIcon { get; set; }
[XmlElement("avatarMedium")]
public Text avatarMedium { get; set; }
[XmlElement("avatarFull")]
public Text avatarFull { get; set; }
[XmlElement("memberCount")]
public int memberCount { get; set; }
[XmlElement("membersInChat")]
public int membersInChat { get; set; }
[XmlElement("membersInGame")]
public int membersInGame { get; set; }
[XmlElement("membersOnline")]
public int membersOnline { get; set; }
}
public class Text
{
[XmlText]
public string text { get; set;}
}
[XmlRoot("members")]
public class Members
{
[XmlElement("steamID64")]
public List<string> steamID64 { get; set;}
}
}
获取steamID64并修复XML
中的错误的简单解决方案using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:'temp'test.xml";
static void Main(string[] args)
{
string file = File.ReadAllText(FILENAME);
file = file.Replace("standalone='"true'"", "standalone='"yes'"");
XDocument doc = XDocument.Parse(file);
List<string> steamID64 = doc.Descendants("steamID64").Select(x => (string)x).ToList();
}
}
}