You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
|
|
namespace MediaBrowser.Dlna.PlayTo
|
|
{
|
|
public class uParser
|
|
{
|
|
public static IList<uBaseObject> ParseBrowseXml(XDocument doc)
|
|
{
|
|
if (doc == null)
|
|
{
|
|
throw new ArgumentException("doc");
|
|
}
|
|
|
|
var list = new List<uBaseObject>();
|
|
|
|
var document = doc.Document;
|
|
|
|
if (document == null)
|
|
return list;
|
|
|
|
var item = (from result in document.Descendants("Result") select result).FirstOrDefault();
|
|
|
|
if (item == null)
|
|
return list;
|
|
|
|
var uPnpResponse = XElement.Parse((String)item);
|
|
|
|
var uObjects = from container in uPnpResponse.Elements(uPnpNamespaces.containers)
|
|
select new uParserObject { Type = (string)container.Element(uPnpNamespaces.uClass), Element = container };
|
|
|
|
var uObjects2 = from container in uPnpResponse.Elements(uPnpNamespaces.items)
|
|
select new uParserObject { Type = (string)container.Element(uPnpNamespaces.uClass), Element = container };
|
|
|
|
list.AddRange(uObjects.Concat(uObjects2).Select(CreateObjectFromXML).Where(uObject => uObject != null));
|
|
|
|
return list;
|
|
}
|
|
|
|
public static uBaseObject CreateObjectFromXML(uParserObject uItem)
|
|
{
|
|
return uContainer.Create(uItem.Element);
|
|
}
|
|
}
|
|
|
|
public class uParserObject
|
|
{
|
|
public string Type { get; set; }
|
|
|
|
public XElement Element { get; set; }
|
|
}
|
|
}
|