2017-09-27 71 views
0

我从Ebay API调用获取XML返回。这实际上是一个Ebay类别的收藏清单。但问题是,我无法从XML输出访问它的集合。我附上了两张图片 - 第一张显示XML值返回变量的调试,第二张显示“InnerList”。我的主要目标是准备这个XML数据以存储在我的数据库中,所以我需要一个来自XML数据的清晰的值列表。有任何想法吗?从API处理XML输出

Picture One

Picture Two

+0

'categories.InnerList'或'categories.List'是你需要用来获取类别信息。 –

+0

是不是你需要的'List'属性? –

+0

与XML无关,您已经序列化了一些类型的集合 - 您可以通过它们的属性访问/删除数据 – Fabio

回答

1

你可以反序列化XML到自己的类/对象 - 那么它可能是更容易使用。我所做的就是把xml标签放到一个类中,我可以反序列化它。请参阅下面的类别和方法:

public static T Deserialize<T>(string xmlText) 
{ 
    try 
    { 
     var stringReader = new System.IO.StringReader(xmlText); 
     var serializer = new XmlSerializer(typeof(T)); 
     return (T)serializer.Deserialize(stringReader); 
    } 
    catch 
    { 
     throw; 
    } 
} 

[XmlElement("adress")] 
public class Adress 
{ 
    [XmlElementAttribute("street_address")] 
    public string street_address { get; set; } 

    [XmlElementAttribute("postal_code")] 
    public string postal_code { get; set; } 

    [XmlElementAttribute("city")] 
    public string city { get; set; } 

    [XmlElementAttribute("country")] 
    public string country { get; set; } 
} 

public main() 
{ 
    Adress myAdress = Deserialize<Adress>(XMLstring); 
} 

希望它有帮助!

0

看来你使用的是Ebay SDK。请尝试下面的代码来处理返回值。

foreach (CategoryTypeCollection item in categories) 
        { 
         item.ItemAt(0).CategoryID = "This is how you access the properties of he returned result"; 
         // THE XML is already parsed for you via SDK, so you don't have to parse it... 
         // since i wrote foreach loop here, always access itemAt 0th index posiiton 
        }