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":
{
if (!reader.IsEmptyElement)
{ {
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
return ParseBodyTag(subReader); return ParseBodyTag(subReader);
} }
} }
else
{
reader.Read();
}
break;
}
default: default:
{ {
reader.Skip(); reader.Skip();
@ -173,6 +181,8 @@ namespace Emby.Dlna.Service
result.LocalName = reader.LocalName; result.LocalName = reader.LocalName;
result.NamespaceURI = reader.NamespaceURI; result.NamespaceURI = reader.NamespaceURI;
if (!reader.IsEmptyElement)
{
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
result.Headers = ParseFirstBodyChild(subReader); result.Headers = ParseFirstBodyChild(subReader);
@ -185,6 +195,11 @@ namespace Emby.Dlna.Service
reader.Read(); reader.Read();
} }
} }
else
{
reader.Read();
}
}
return result; return result;
} }

View File

@ -133,12 +133,20 @@ namespace Emby.Server.Implementations.News
switch (reader.Name) switch (reader.Name)
{ {
case "channel": case "channel":
{
if (!reader.IsEmptyElement)
{ {
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
return ParseFromChannelNode(subReader); return ParseFromChannelNode(subReader);
} }
} }
else
{
reader.Read();
}
break;
}
default: default:
{ {
reader.Skip(); reader.Skip();
@ -169,11 +177,18 @@ namespace Emby.Server.Implementations.News
switch (reader.Name) switch (reader.Name)
{ {
case "item": case "item":
{
if (!reader.IsEmptyElement)
{ {
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
list.Add(ParseItem(subReader)); list.Add(ParseItem(subReader));
} }
}
else
{
reader.Read();
}
break; break;
} }
default: default:

View File

@ -394,20 +394,34 @@ namespace MediaBrowser.LocalMetadata.Parsers
} }
case "TagLines": case "TagLines":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchFromTaglinesNode(subtree, item); FetchFromTaglinesNode(subtree, item);
} }
}
else
{
reader.Read();
}
break; break;
} }
case "Countries": case "Countries":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchFromCountriesNode(subtree, item); FetchFromCountriesNode(subtree, item);
} }
}
else
{
reader.Read();
}
break; break;
} }
@ -591,6 +605,8 @@ namespace MediaBrowser.LocalMetadata.Parsers
} }
case "Trailers": case "Trailers":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
@ -600,6 +616,11 @@ namespace MediaBrowser.LocalMetadata.Parsers
FetchDataFromTrailersNode(subtree, hasTrailers); FetchDataFromTrailersNode(subtree, hasTrailers);
} }
} }
}
else
{
reader.Read();
}
break; break;
} }
@ -698,51 +719,88 @@ namespace MediaBrowser.LocalMetadata.Parsers
break; break;
case "Genres": case "Genres":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchFromGenresNode(subtree, item); FetchFromGenresNode(subtree, item);
} }
}
else
{
reader.Read();
}
break; break;
} }
case "Tags": case "Tags":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchFromTagsNode(subtree, item); FetchFromTagsNode(subtree, item);
} }
}
else
{
reader.Read();
}
break; break;
} }
case "PlotKeywords": case "PlotKeywords":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchFromKeywordsNode(subtree, item); FetchFromKeywordsNode(subtree, item);
} }
}
else
{
reader.Read();
}
break; break;
} }
case "Persons": case "Persons":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchDataFromPersonsNode(subtree, itemResult); FetchDataFromPersonsNode(subtree, itemResult);
} }
}
else
{
reader.Read();
}
break; break;
} }
case "Studios": case "Studios":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchFromStudiosNode(subtree, item); FetchFromStudiosNode(subtree, item);
} }
}
else
{
reader.Read();
}
break; break;
} }
case "Shares": case "Shares":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
@ -752,6 +810,11 @@ namespace MediaBrowser.LocalMetadata.Parsers
FetchFromSharesNode(subtree, hasShares); 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,18 +43,32 @@ namespace MediaBrowser.LocalMetadata.Parsers
case "PlaylistItems": case "PlaylistItems":
if (!reader.IsEmptyElement)
{
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
FetchFromCollectionItemsNode(subReader, item); FetchFromCollectionItemsNode(subReader, item);
} }
}
else
{
reader.Read();
}
break; break;
case "Shares": case "Shares":
if (!reader.IsEmptyElement)
{
using (var subReader = reader.ReadSubtree()) using (var subReader = reader.ReadSubtree())
{ {
FetchFromSharesNode(subReader, item); FetchFromSharesNode(subReader, item);
} }
}
else
{
reader.Read();
}
break; break;
default: default:
@ -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)
{ {
reader.Read();
continue;
}
using (var subtree = reader.ReadSubtree()) 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

@ -654,6 +654,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers
} }
case "actor": case "actor":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
@ -664,6 +666,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers
itemResult.AddPerson(person); itemResult.AddPerson(person);
} }
} }
}
else
{
reader.Read();
}
break; break;
} }
@ -830,11 +837,18 @@ namespace MediaBrowser.XbmcMetadata.Parsers
} }
case "fileinfo": case "fileinfo":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
FetchFromFileInfoNode(subtree, item); FetchFromFileInfoNode(subtree, item);
} }
}
else
{
reader.Read();
}
break; break;
} }
@ -895,6 +909,8 @@ namespace MediaBrowser.XbmcMetadata.Parsers
} }
case "resume": case "resume":
{
if (!reader.IsEmptyElement)
{ {
using (var subtree = reader.ReadSubtree()) using (var subtree = reader.ReadSubtree())
{ {
@ -905,6 +921,11 @@ namespace MediaBrowser.XbmcMetadata.Parsers
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);