我有一个XML文件,其中包含我想要的标识符,xml看起来像
cr1 = int(input("What is the convertion rate of the first one? "))
我想要的标识符是60371408,60371409
答案 0 :(得分:1)
答案 1 :(得分:0)
var serializer = new XmlSerializer(typeof(Dictionary<string, object>));
...然后反序列化。例如,您还没有指定此XML的格式,无论您是字符串还是流。以下是您对XML字符串进行反序列化的方法:
var reader = new StringReader(xml);
var dict = serializer.Deserialize(reader);
现在您拥有Dictionary<string, object>
,但由于值是普通对象,因此您需要转换值:
var list = (List<int>)dict["key"];
答案 2 :(得分:0)
试试xml linq
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
public class Program
{
const string FILENAME = @"c:\temp\test.xml";
public static void Main()
{
XDocument doc = XDocument.Load(FILENAME);
XElement dictionary = doc.Descendants().Where(x => x.Name.LocalName == "Dictionary").FirstOrDefault();
XNamespace xNs = dictionary.GetNamespaceOfPrefix("x");
var results = dictionary.Descendants(xNs + "Int32").Select(x => (int)x).ToList();
}
}
}