update xml parsing

This commit is contained in:
Luke Pulverenti 2016-12-03 18:57:34 -05:00
parent 83ad945015
commit 7ed6c67db0
12 changed files with 293 additions and 52 deletions

View File

@ -136,12 +136,20 @@ namespace Emby.Dlna.Service
switch (reader.LocalName) switch (reader.LocalName)
{ {
case "Body": case "Body":
{
using (var subReader = reader.ReadSubtree())
{ {
return ParseBodyTag(subReader); if (!reader.IsEmptyElement)
{
using (var subReader = reader.ReadSubtree())
{
return ParseBodyTag(subReader);
}
}
else
{
reader.Read();
}
break;
} }
}
default: default:
{ {
reader.Skip(); reader.Skip();
@ -173,11 +181,18 @@ namespace Emby.Dlna.Service
result.LocalName = reader.LocalName; result.LocalName = reader.LocalName;
result.NamespaceURI = reader.NamespaceURI; result.NamespaceURI = reader.NamespaceURI;
using (var subReader = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
result.Headers = ParseFirstBodyChild(subReader); using (var subReader = reader.ReadSubtree())
{
result.Headers = ParseFirstBodyChild(subReader);
return result; return result;
}
}
else
{
reader.Read();
} }
} }
else else

View File

@ -134,10 +134,18 @@ namespace Emby.Server.Implementations.News
{ {
case "channel": case "channel":
{ {
using (var subReader = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
return ParseFromChannelNode(subReader); using (var subReader = reader.ReadSubtree())
{
return ParseFromChannelNode(subReader);
}
} }
else
{
reader.Read();
}
break;
} }
default: default:
{ {
@ -170,9 +178,16 @@ namespace Emby.Server.Implementations.News
{ {
case "item": case "item":
{ {
using (var subReader = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
list.Add(ParseItem(subReader)); using (var subReader = reader.ReadSubtree())
{
list.Add(ParseItem(subReader));
}
}
else
{
reader.Read();
} }
break; break;
} }

View File

@ -395,18 +395,32 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "TagLines": case "TagLines":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchFromTaglinesNode(subtree, item); using (var subtree = reader.ReadSubtree())
{
FetchFromTaglinesNode(subtree, item);
}
}
else
{
reader.Read();
} }
break; break;
} }
case "Countries": case "Countries":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchFromCountriesNode(subtree, item); using (var subtree = reader.ReadSubtree())
{
FetchFromCountriesNode(subtree, item);
}
}
else
{
reader.Read();
} }
break; break;
} }
@ -592,14 +606,21 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "Trailers": case "Trailers":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
var hasTrailers = item as IHasTrailers; using (var subtree = reader.ReadSubtree())
if (hasTrailers != null)
{ {
FetchDataFromTrailersNode(subtree, hasTrailers); var hasTrailers = item as IHasTrailers;
if (hasTrailers != null)
{
FetchDataFromTrailersNode(subtree, hasTrailers);
}
} }
} }
else
{
reader.Read();
}
break; break;
} }
@ -699,59 +720,101 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "Genres": case "Genres":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchFromGenresNode(subtree, item); using (var subtree = reader.ReadSubtree())
{
FetchFromGenresNode(subtree, item);
}
}
else
{
reader.Read();
} }
break; break;
} }
case "Tags": case "Tags":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchFromTagsNode(subtree, item); using (var subtree = reader.ReadSubtree())
{
FetchFromTagsNode(subtree, item);
}
}
else
{
reader.Read();
} }
break; break;
} }
case "PlotKeywords": case "PlotKeywords":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchFromKeywordsNode(subtree, item); using (var subtree = reader.ReadSubtree())
{
FetchFromKeywordsNode(subtree, item);
}
}
else
{
reader.Read();
} }
break; break;
} }
case "Persons": case "Persons":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchDataFromPersonsNode(subtree, itemResult); using (var subtree = reader.ReadSubtree())
{
FetchDataFromPersonsNode(subtree, itemResult);
}
}
else
{
reader.Read();
} }
break; break;
} }
case "Studios": case "Studios":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchFromStudiosNode(subtree, item); using (var subtree = reader.ReadSubtree())
{
FetchFromStudiosNode(subtree, item);
}
}
else
{
reader.Read();
} }
break; break;
} }
case "Shares": case "Shares":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
var hasShares = item as IHasShares; using (var subtree = reader.ReadSubtree())
if (hasShares != null)
{ {
FetchFromSharesNode(subtree, hasShares); var hasShares = item as IHasShares;
if (hasShares != null)
{
FetchFromSharesNode(subtree, hasShares);
}
} }
} }
else
{
reader.Read();
}
break; break;
} }
@ -824,6 +887,11 @@ namespace MediaBrowser.LocalMetadata.Parsers
{ {
case "Share": case "Share":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
var share = GetShareFromNode(subtree); var share = GetShareFromNode(subtree);
@ -1090,6 +1158,11 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "Person": case "Person":
case "Actor": case "Actor":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
foreach (var person in GetPersonsFromXmlNode(subtree)) foreach (var person in GetPersonsFromXmlNode(subtree))

View File

@ -43,17 +43,31 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "PlaylistItems": case "PlaylistItems":
using (var subReader = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchFromCollectionItemsNode(subReader, item); using (var subReader = reader.ReadSubtree())
{
FetchFromCollectionItemsNode(subReader, item);
}
}
else
{
reader.Read();
} }
break; break;
case "Shares": case "Shares":
using (var subReader = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchFromSharesNode(subReader, item); using (var subReader = reader.ReadSubtree())
{
FetchFromSharesNode(subReader, item);
}
}
else
{
reader.Read();
} }
break; break;
@ -79,6 +93,12 @@ namespace MediaBrowser.LocalMetadata.Parsers
{ {
case "PlaylistItem": case "PlaylistItem":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
var child = GetLinkedChild(subReader); var child = GetLinkedChild(subReader);
@ -123,6 +143,12 @@ namespace MediaBrowser.LocalMetadata.Parsers
{ {
case "Share": case "Share":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
var child = GetShare(subReader); var child = GetShare(subReader);

View File

@ -218,6 +218,11 @@ namespace MediaBrowser.MediaEncoding.Probing
switch (reader.Name) switch (reader.Name)
{ {
case "dict": case "dict":
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
ReadFromDictNode(subtree, info); ReadFromDictNode(subtree, info);
@ -279,9 +284,14 @@ namespace MediaBrowser.MediaEncoding.Probing
} }
break; break;
case "array": case "array":
if (!string.IsNullOrWhiteSpace(currentKey)) if (reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree())
{
if (!string.IsNullOrWhiteSpace(currentKey))
{ {
pairs.AddRange(ReadValueArray(subtree)); pairs.AddRange(ReadValueArray(subtree));
} }
@ -315,6 +325,12 @@ namespace MediaBrowser.MediaEncoding.Probing
switch (reader.Name) switch (reader.Name)
{ {
case "dict": case "dict":
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
var dict = GetNameValuePair(subtree); var dict = GetNameValuePair(subtree);

View File

@ -274,6 +274,11 @@ namespace MediaBrowser.Providers.Music
{ {
case "release-list": case "release-list":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
return ParseReleaseList(subReader); return ParseReleaseList(subReader);
@ -311,6 +316,11 @@ namespace MediaBrowser.Providers.Music
{ {
case "release": case "release":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
var releaseId = reader.GetAttribute("id"); var releaseId = reader.GetAttribute("id");
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
@ -435,6 +445,11 @@ namespace MediaBrowser.Providers.Music
{ {
case "release-group-list": case "release-group-list":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
return GetFirstReleaseGroupId(subReader); return GetFirstReleaseGroupId(subReader);

View File

@ -97,6 +97,11 @@ namespace MediaBrowser.Providers.Music
{ {
case "artist-list": case "artist-list":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
return ParseArtistList(subReader); return ParseArtistList(subReader);
@ -136,6 +141,11 @@ namespace MediaBrowser.Providers.Music
{ {
case "artist": case "artist":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
var mbzId = reader.GetAttribute("id"); var mbzId = reader.GetAttribute("id");
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())

View File

@ -127,6 +127,11 @@ namespace MediaBrowser.Providers.People
{ {
case "Actor": case "Actor":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
var info = FetchImageInfoFromActorNode(personName, subtree); var info = FetchImageInfoFromActorNode(personName, subtree);

View File

@ -139,6 +139,11 @@ namespace MediaBrowser.Providers.TV
{ {
case "Banner": case "Banner":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
AddImage(subtree, list, seasonNumber); AddImage(subtree, list, seasonNumber);

View File

@ -126,6 +126,11 @@ namespace MediaBrowser.Providers.TV
{ {
case "Banner": case "Banner":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
AddImage(subtree, list); AddImage(subtree, list);

View File

@ -314,6 +314,11 @@ namespace MediaBrowser.Providers.TV
{ {
case "Series": case "Series":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
return FindSeriesId(subtree); return FindSeriesId(subtree);
@ -559,6 +564,11 @@ namespace MediaBrowser.Providers.TV
{ {
case "Series": case "Series":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
var searchResult = GetSeriesSearchResultFromSubTree(subtree, comparableName); var searchResult = GetSeriesSearchResultFromSubTree(subtree, comparableName);
@ -799,6 +809,11 @@ namespace MediaBrowser.Providers.TV
{ {
case "Series": case "Series":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchDataFromSeriesNode(result, subtree, cancellationToken); FetchDataFromSeriesNode(result, subtree, cancellationToken);
@ -808,6 +823,11 @@ namespace MediaBrowser.Providers.TV
case "Episode": case "Episode":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
var date = GetFirstAiredDateFromEpisodeNode(subtree, cancellationToken); var date = GetFirstAiredDateFromEpisodeNode(subtree, cancellationToken);
@ -942,6 +962,11 @@ namespace MediaBrowser.Providers.TV
{ {
case "Actor": case "Actor":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchDataFromActorNode(result, subtree); FetchDataFromActorNode(result, subtree);

View File

@ -655,15 +655,22 @@ namespace MediaBrowser.XbmcMetadata.Parsers
case "actor": case "actor":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
var person = GetPersonFromXmlNode(subtree); using (var subtree = reader.ReadSubtree())
if (!string.IsNullOrWhiteSpace(person.Name))
{ {
itemResult.AddPerson(person); var person = GetPersonFromXmlNode(subtree);
if (!string.IsNullOrWhiteSpace(person.Name))
{
itemResult.AddPerson(person);
}
} }
} }
else
{
reader.Read();
}
break; break;
} }
@ -831,9 +838,16 @@ namespace MediaBrowser.XbmcMetadata.Parsers
case "fileinfo": case "fileinfo":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
FetchFromFileInfoNode(subtree, item); using (var subtree = reader.ReadSubtree())
{
FetchFromFileInfoNode(subtree, item);
}
}
else
{
reader.Read();
} }
break; break;
} }
@ -896,15 +910,22 @@ namespace MediaBrowser.XbmcMetadata.Parsers
case "resume": case "resume":
{ {
using (var subtree = reader.ReadSubtree()) if (!reader.IsEmptyElement)
{ {
if (!string.IsNullOrWhiteSpace(userDataUserId)) using (var subtree = reader.ReadSubtree())
{ {
var userData = GetOrAdd(itemResult, userDataUserId); if (!string.IsNullOrWhiteSpace(userDataUserId))
{
var userData = GetOrAdd(itemResult, userDataUserId);
FetchFromResumeNode(subtree, item, userData); FetchFromResumeNode(subtree, item, userData);
}
} }
} }
else
{
reader.Read();
}
break; break;
} }
@ -1006,6 +1027,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{ {
case "streamdetails": case "streamdetails":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchFromStreamDetailsNode(subtree, item); FetchFromStreamDetailsNode(subtree, item);
@ -1039,6 +1065,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers
{ {
case "video": case "video":
{ {
if (reader.IsEmptyElement)
{
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchFromVideoNode(subtree, item); FetchFromVideoNode(subtree, item);