Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.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#将SQLXML反序列化为类或对象_C#_Xml_Sqlxml - Fatal编程技术网

C#将SQLXML反序列化为类或对象

C#将SQLXML反序列化为类或对象,c#,xml,sqlxml,C#,Xml,Sqlxml,这两个都是我使用HttpClient提取的示例数据,我想获取属性(?),例如PlatformTag,ETA等等 这是使用适用于Windows 10 mobile和桌面的Univeral应用程序。但我不知道接下来会发生什么 XDocument Document = XDocument.Parse(RESPONSE_CONSTANT); var Stops = from Stop in Document.Descendants("Platform") select new { Platformta

这两个都是我使用HttpClient提取的示例数据,我想获取属性(?),例如
PlatformTag
ETA
等等

这是使用适用于Windows 10 mobile和桌面的Univeral应用程序。但我不知道接下来会发生什么

XDocument Document =  XDocument.Parse(RESPONSE_CONSTANT);
var Stops = from Stop in Document.Descendants("Platform")
select new
{
Platformtag = (string)Stop.Attribute("PlatformTag"),
Platformno = (string)Stop.Attribute("PlatformNo")};
foreach (var item in Stops)
BusData.Text = item.Platformtag;
}
是我目前拥有的,但没有任何东西来自它,它只是坐在那里好像什么也看不见,从这里我对XML解析了解不够,无法找到下一步


注意:Response_常量包含如下数据:

尝试以下内容。必须修改xml以替换符号

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using System.IO;

namespace ConsoleApplication14
{
    class Program
    {
        const string FILENAME = @"c:\temp\test.xml";
        static void Main(string[] args)
        {
            string xml = File.ReadAllText(FILENAME);
            xml = xml.Replace("&", "&");
            StringReader sReader = new StringReader(xml);
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            XmlReader reader = XmlReader.Create(sReader);

            List<Platform> platforms = new List<Platform>();
            while (!reader.EOF)
            {
                if (reader.Name != "Platform")
                {
                    reader.ReadToFollowing("Platform");
                }
                if (!reader.EOF)
                {
                    XElement platform = (XElement)XElement.ReadFrom(reader);

                    platforms.Add(new Platform()
                    {
                        tag = (int)platform.Attribute("PlatformTag"),
                        no = (int?)platform.Attribute("PlatformNo"),
                        name = (string)platform.Attribute("Name"),
                        bearingToRoad = (double?)platform.Attribute("BearingToRoad"),
                        roadName = (string)platform.Attribute("RoadName"),
                        lat = (double)platform.Element(platform.Name.Namespace + "Position").Attribute("Lat"),
                        _long = (double)platform.Element(platform.Name.Namespace + "Position").Attribute("Long")
                    });
                }
            }
        }
    }
    public class Platform
    {
        public int tag { get; set; }
        public int? no { get; set; }
        public string name { get; set; }
        public double? bearingToRoad { get; set; }
        public string roadName { get; set; }
        public double lat { get; set; }
        public double _long { get; set; }
    }
}
使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用系统文本;
使用System.Xml;
使用System.Xml.Linq;
使用System.IO;
命名空间控制台应用程序14
{
班级计划
{
常量字符串文件名=@“c:\temp\test.xml”;
静态void Main(字符串[]参数)
{
字符串xml=File.ReadAllText(文件名);
xml=xml.Replace(“&”、“&;”;
StringReader sReader=新的StringReader(xml);
XmlReaderSettings设置=新建XmlReaderSettings();
settings.ConformanceLevel=ConformanceLevel.Fragment;
XmlReader=XmlReader.Create(sReader);
列表平台=新列表();
而(!reader.EOF)
{
if(reader.Name!=“平台”)
{
reader.ReadToFollowing(“平台”);
}
if(!reader.EOF)
{
XElement平台=(XElement)XElement.ReadFrom(reader);
platforms.Add(新平台()
{
tag=(int)platform.Attribute(“PlatformTag”),
否=(int?)platform.Attribute(“PlatformNo”),
name=(字符串)platform.Attribute(“name”),
bearingToRoad=(双?)platform.Attribute(“bearingToRoad”),
roadName=(字符串)platform.Attribute(“roadName”),
lat=(双精度)platform.Element(platform.Name.Namespace+“Position”).Attribute(“lat”),
_long=(双精度)platform.Element(platform.Name.Namespace+“Position”).Attribute(“long”)
});
}
}
}
}
公共课堂平台
{
公共int标记{get;set;}
公共int?否{get;set;}
公共字符串名称{get;set;}
公共双轴承TOROAD{get;set;}
公共字符串roadName{get;set;}
公共双lat{get;set;}
公共双_long{get;set;}
}
}

到目前为止,您尝试了什么?在实现您的解决方案时遇到了什么问题?始终以此作为答复是什么?我已经尝试了简单的XML反序列化程序,我不再使用我尝试过的代码,因为它不能满足我的需要,所以我放弃了它。我尝试过类似和其他XML反序列化技术,但由于这不是标准XML,它们无法按我希望的方式工作。我成功了,我错过了在代码上方键入的内容。感谢帮助:)如果我在API的任何其他部分采用它时遇到任何问题,我将在这里发布,我们将拭目以待,但是从你的代码来看,它看起来会非常相似