Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# XML解析蒸汽组API_C#_Xml_Parsing - Fatal编程技术网

C# XML解析蒸汽组API

C# XML解析蒸汽组API,c#,xml,parsing,C#,Xml,Parsing,我有一个问题: 如何在此特定文档中解析XML: 我想逐行获取文件文档中的所有 它不是另一个的副本,我需要这一个,因为它的工作原理不同。请尝试下面的代码。我不得不将第一行从standalone=“true”更改为standalone=“yes” 使用System.Linq; 使用系统文本; 使用System.Xml; 使用System.Xml.Serialization; 使用System.IO; 命名空间控制台应用程序1 { 班级计划 { 常量字符串文件名=@“c:\temp\test.xml

我有一个问题:

如何在此特定文档中解析XML:

我想逐行获取文件文档中的所有


它不是另一个的副本,我需要这一个,因为它的工作原理不同。

请尝试下面的代码。我不得不将第一行从standalone=“true”更改为standalone=“yes”

使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Serialization;
使用System.IO;
命名空间控制台应用程序1
{
班级计划
{
常量字符串文件名=@“c:\temp\test.xml”;
静态void Main(字符串[]参数)
{
字符串文件=file.ReadAllText(文件名);
file=file.Replace(“standalone=\“true\”,“standalone=\“yes\”);
StringReader=新的StringReader(文件);
XmlSerializer xs=新的XmlSerializer(typeof(MemberList));
MemberList members=(MemberList)xs.反序列化(读卡器);
}
}
[XmlRoot(“成员列表”)]
公共类成员列表
{
[XmlElement(“groupID64”)]
公共字符串groupID64{get;set;}
[XmlElement(“groupDetails”)]
公共GroupDetails GroupDetails{get;set;}
[XmlElement(“nextPageLink”)]
公共文本nextPageLink{get;set;}
[XmlElement(“成员”)]
公共成员成员{get;set;}
}
[XmlRoot(“groupDetails”)]
公共类组详细信息
{
[XmlElement(“groupName”)]
公共文本组名{get;set;}
[XmlElement(“groupURL”)]
公共文本组URL{get;set;}
[XmlElement(“标题”)]
公共文本标题{get;set;}
[XmlElement(“摘要”)]
公共文本摘要{get;set;}
[XmlElement(“avatarIcon”)]
公共文本虚拟角色{get;set;}
[XmlElement(“avatarMedium”)]
公共文本{get;set;}
[XmlElement(“avatarFull”)]
公共文本avatarFull{get;set;}
[XmlElement(“memberCount”)]
public int memberCount{get;set;}
[XmlElement(“membersInChat”)]
公共int成员聊天{get;set;}
[XmlElement(“成员名称”)]
public int membersInGame{get;set;}
[XmlElement(“membersOnline”)]
public int membersOnline{get;set;}
}
公共类文本
{
[XmlText]
公共字符串文本{get;set;}
}
[XmlRoot(“成员”)]
公共班级成员
{
[XmlElement(“steamID64”)]
公共列表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();
        }
    }

}​
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Linq;
使用System.IO;
命名空间控制台应用程序1
{
班级计划
{
常量字符串文件名=@“c:\temp\test.xml”;
静态void Main(字符串[]参数)
{
字符串文件=file.ReadAllText(文件名);
file=file.Replace(“standalone=\“true\”,“standalone=\“yes\”);
XDocument doc=XDocument.Parse(文件);
列出streamid64=doc.substands(“streamid64”).Select(x=>(string)x.ToList();
}
}
}​

这可能会重复,但如果必须编辑输入XML,则这不是一个理想的解决方案。一般来说(这里是个人偏好),简单地张贴一堵没有解释的代码墙会导致非常糟糕的答案——对于OP(似乎对XML解析很陌生)和任何未来寻找答案的读者来说都是如此,而不是其他你可以消除你不需要的类中的任何对象。我修改了代码以修复XML中的错误,将“true”更改为“yes”。蒂姆:您希望如何读取包含错误的文件。唯一真正的解决办法是修正错误。如果您不是生成错误的代码的所有者,那么您必须做一些事情作为解决方法。
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();
        }
    }

}​