mirror of https://github.com/Jackett/Jackett
Compare commits
8 Commits
4431926aa7
...
79a5804cbe
Author | SHA1 | Date |
---|---|---|
Boris Gerretzen | 79a5804cbe | |
Garfield69 | a7efe1b6da | |
Boris | 8d3dfd43d4 | |
Boris Gerretzen | 4eaacaeb94 | |
Bogdan | 86f5e5abce | |
Boris | e4911054e3 | |
Boris | 533a25da54 | |
Boris | 23b62c2fa6 |
|
@ -11,21 +11,15 @@ links:
|
|||
caps:
|
||||
categorymappings:
|
||||
- {id: 1, cat: Movies, desc: "MOVIES"}
|
||||
- {id: 20, cat: Movies/Foreign, desc: "MOVIES-FOREIGN"}
|
||||
- {id: 2, cat: TV, desc: "TV"}
|
||||
- {id: 19, cat: TV/Foreign, desc: "TV-FOREIGN"}
|
||||
- {id: 4, cat: PC, desc: "APPS"}
|
||||
- {id: 5, cat: Audio, desc: "MUSIC"}
|
||||
- {id: 6, cat: XXX, desc: "XXX"}
|
||||
- {id: 7, cat: Console, desc: "GAMES"}
|
||||
- {id: 8, cat: Books, desc: "EBOOKS"}
|
||||
- {id: 3, cat: Audio, desc: "MUSIC"}
|
||||
|
||||
modes:
|
||||
search: [q]
|
||||
tv-search: [q, season, ep, imdbid, tvdbid, tmdbid]
|
||||
movie-search: [q, imdbid, tmdbid]
|
||||
music-search: [q]
|
||||
book-search: [q]
|
||||
# book-search: [q]
|
||||
|
||||
settings:
|
||||
- name: apikey
|
||||
|
@ -39,6 +33,10 @@ settings:
|
|||
type: checkbox
|
||||
label: Search freeleech only
|
||||
default: false
|
||||
- name: single_file_release_use_filename
|
||||
type: checkbox
|
||||
label: Use filename as title for single file releases
|
||||
default: true
|
||||
- name: sort
|
||||
type: select
|
||||
label: Sort requested from site
|
||||
|
@ -100,7 +98,7 @@ search:
|
|||
fields:
|
||||
category:
|
||||
selector: category_id
|
||||
title:
|
||||
title_optional:
|
||||
selector: name
|
||||
details:
|
||||
selector: details_link
|
||||
|
@ -122,10 +120,6 @@ search:
|
|||
genre:
|
||||
selector: meta.genres
|
||||
filters:
|
||||
- name: re_replace
|
||||
args: ["(?i)^None$", ""]
|
||||
- name: re_replace
|
||||
args: ["(?i)(Science Fiction)", "Science_Fiction"]
|
||||
- name: replace
|
||||
args: [" & ", "_&_"]
|
||||
description:
|
||||
|
@ -170,4 +164,9 @@ search:
|
|||
minimumseedtime:
|
||||
# 7 days (as seconds = 7 x 24 x 60 x 60)
|
||||
text: 604800
|
||||
# json UNIT3D 7.2.5
|
||||
title_filename:
|
||||
selector: "files[0].name"
|
||||
optional: true
|
||||
title:
|
||||
text: "{{ if and (.Config.single_file_release_use_filename) (eq .Result.files \"1\") (.Result.title_filename) }}{{ .Result.title_filename }}{{ else }}{{ .Result.title_optional }}{{ end }}"
|
||||
# json UNIT3D 8.0.2
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
using Newtonsoft.Json.Serialization;
|
||||
|
||||
namespace Jackett.Common.Helpers
|
||||
{
|
||||
public class LowerCaseNamingStrategy : NamingStrategy
|
||||
{
|
||||
protected override string ResolvePropertyName(string name) => name.ToLowerInvariant();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Jackett.Common.Extensions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Jackett.Common.Helpers
|
||||
{
|
||||
public static class XmlToJsonConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts an XML element to a JSON object.
|
||||
/// Attributes are stored in an @attributes object.
|
||||
/// </summary>
|
||||
public static JToken XmlToJson(XElement element)
|
||||
{
|
||||
var obj = new JObject();
|
||||
|
||||
// Build @attributes object from element attributes
|
||||
if (element.Attributes().Any())
|
||||
{
|
||||
var attributes = element.Attributes()
|
||||
.ToDictionary(
|
||||
attribute => GetName(attribute.Name, attribute.Parent?.Document),
|
||||
attribute => (JToken)attribute.Value
|
||||
);
|
||||
obj.Add("@attributes", JObject.FromObject(attributes));
|
||||
}
|
||||
|
||||
foreach (var childElement in element.Elements())
|
||||
{
|
||||
var childObj = XmlToJson(childElement);
|
||||
var childName = GetName(childElement.Name, element.Document);
|
||||
|
||||
// If the child name already exists, convert it to an array
|
||||
if (obj.ContainsKey(childName))
|
||||
{
|
||||
if (obj[childName] is JArray existingArray)
|
||||
{
|
||||
existingArray.Add(childObj);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj[childName] = new JArray(obj[childName]!, childObj);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.Add(childName, childObj);
|
||||
}
|
||||
}
|
||||
|
||||
if (!element.Elements().Any() && !element.Value.IsNullOrWhiteSpace())
|
||||
{
|
||||
return element.Value;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
private static string GetName(XName name, XDocument document)
|
||||
{
|
||||
if (document == null)
|
||||
{
|
||||
return name.LocalName;
|
||||
}
|
||||
|
||||
var prefix = document.Root?.GetPrefixOfNamespace(name.Namespace);
|
||||
return prefix != null ? $"{prefix}:{name.LocalName}" : name.LocalName;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ namespace Jackett.Common.Models.DTO
|
|||
public string imdbid { get; set; }
|
||||
public string ep { get; set; }
|
||||
public string t { get; set; }
|
||||
public string o { get; set; }
|
||||
public string extended { get; set; }
|
||||
public string limit { get; set; }
|
||||
public string offset { get; set; }
|
||||
|
|
|
@ -5,6 +5,8 @@ using System.Linq;
|
|||
using System.Text.RegularExpressions;
|
||||
using System.Threading;
|
||||
using System.Xml.Linq;
|
||||
using Jackett.Common.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Jackett.Common.Models
|
||||
{
|
||||
|
@ -52,7 +54,7 @@ namespace Jackett.Common.Models
|
|||
return new XElement(_TorznabNs + "attr", new XAttribute("name", name), new XAttribute("value", value));
|
||||
}
|
||||
|
||||
public string ToXml(Uri selfAtom)
|
||||
private XDocument GetXDocument(Uri selfAtom)
|
||||
{
|
||||
// IMPORTANT: We can't use Uri.ToString(), because it generates URLs without URL encode (links with unicode
|
||||
// characters are broken). We must use Uri.AbsoluteUri instead that handles encoding correctly
|
||||
|
@ -127,7 +129,19 @@ namespace Jackett.Common.Models
|
|||
)
|
||||
);
|
||||
|
||||
return xdoc;
|
||||
}
|
||||
|
||||
public string ToXml(Uri selfAtom)
|
||||
{
|
||||
var xdoc = GetXDocument(selfAtom);
|
||||
return xdoc.Declaration + Environment.NewLine + xdoc;
|
||||
}
|
||||
|
||||
public string ToJson(Uri selfAtom, JsonSerializerSettings serializerSettings = null)
|
||||
{
|
||||
var jsonObject = XmlToJsonConverter.XmlToJson(GetXDocument(selfAtom).Root);
|
||||
return JsonConvert.SerializeObject(jsonObject, serializerSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Jackett.Common.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Jackett.Common.Models
|
||||
{
|
||||
|
@ -352,6 +354,12 @@ namespace Jackett.Common.Models
|
|||
public string ToXml() =>
|
||||
GetXDocument().Declaration + Environment.NewLine + GetXDocument();
|
||||
|
||||
public string ToJson(JsonSerializerSettings serializerSettings = null)
|
||||
{
|
||||
var jsonObject = XmlToJsonConverter.XmlToJson(GetXDocument().Root);
|
||||
return JsonConvert.SerializeObject(jsonObject, serializerSettings);
|
||||
}
|
||||
|
||||
public static TorznabCapabilities Concat(TorznabCapabilities lhs, TorznabCapabilities rhs)
|
||||
{
|
||||
lhs.SearchAvailable = lhs.SearchAvailable || rhs.SearchAvailable;
|
||||
|
|
|
@ -48,6 +48,8 @@ namespace Jackett.Common.Models
|
|||
|
||||
public bool IsTest { get; set; }
|
||||
|
||||
public bool IsJson { get; set; }
|
||||
|
||||
public string ImdbIDShort => ImdbID?.TrimStart('t');
|
||||
|
||||
protected string[] QueryStringParts;
|
||||
|
|
|
@ -8,6 +8,7 @@ using System.Threading.Tasks;
|
|||
using System.Xml.Linq;
|
||||
using Jackett.Common;
|
||||
using Jackett.Common.Exceptions;
|
||||
using Jackett.Common.Helpers;
|
||||
using Jackett.Common.Indexers;
|
||||
using Jackett.Common.Indexers.Meta;
|
||||
using Jackett.Common.Models;
|
||||
|
@ -20,6 +21,9 @@ using Microsoft.AspNetCore.Mvc;
|
|||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.AspNetCore.Routing;
|
||||
using Microsoft.Net.Http.Headers;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NLog;
|
||||
|
||||
namespace Jackett.Server.Controllers
|
||||
|
@ -175,6 +179,17 @@ namespace Jackett.Server.Controllers
|
|||
private readonly IServerService serverService;
|
||||
private readonly ICacheService cacheService;
|
||||
private readonly Common.Models.Config.ServerConfig serverConfig;
|
||||
private static readonly JsonSerializerSettings _JsonSerializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
Converters = new List<JsonConverter>
|
||||
{
|
||||
new StringEnumConverter
|
||||
{
|
||||
NamingStrategy = new LowerCaseNamingStrategy()
|
||||
}
|
||||
},
|
||||
NullValueHandling = NullValueHandling.Ignore
|
||||
};
|
||||
|
||||
public ResultsController(IIndexerManagerService indexerManagerService, IServerService ss, ICacheService c, Logger logger, Common.Models.Config.ServerConfig sConfig)
|
||||
{
|
||||
|
@ -339,9 +354,16 @@ namespace Jackett.Server.Controllers
|
|||
[HttpGet]
|
||||
public async Task<IActionResult> Torznab([FromQuery] TorznabRequest request)
|
||||
{
|
||||
if (string.Equals(request.o, "json", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
CurrentQuery.IsJson = true;
|
||||
}
|
||||
|
||||
if (string.Equals(CurrentQuery.QueryType, "caps", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return Content(CurrentIndexer.TorznabCaps.ToXml(), "application/rss+xml", Encoding.UTF8);
|
||||
return CurrentQuery.IsJson ?
|
||||
Content(CurrentIndexer.TorznabCaps.ToJson(_JsonSerializerSettings), "application/json", Encoding.UTF8) :
|
||||
Content(CurrentIndexer.TorznabCaps.ToXml(), "application/rss+xml", Encoding.UTF8);
|
||||
}
|
||||
|
||||
// indexers - returns a list of all included indexers (meta indexers only)
|
||||
|
@ -350,7 +372,7 @@ namespace Jackett.Server.Controllers
|
|||
if (!(CurrentIndexer is BaseMetaIndexer)) // shouldn't be needed because CanHandleQuery should return false
|
||||
{
|
||||
logger.Warn($"A search request with t=indexers from {Request.HttpContext.Connection.RemoteIpAddress} was made but the indexer {CurrentIndexer.Name} isn't a meta indexer.");
|
||||
return GetErrorXML(203, "Function Not Available: this isn't a meta indexer");
|
||||
return GetError(203, "Function Not Available: this isn't a meta indexer");
|
||||
}
|
||||
var CurrentBaseMetaIndexer = (BaseMetaIndexer)CurrentIndexer;
|
||||
var indexers = CurrentBaseMetaIndexer.Indexers;
|
||||
|
@ -376,6 +398,11 @@ namespace Jackett.Server.Controllers
|
|||
)
|
||||
);
|
||||
|
||||
if (CurrentQuery.IsJson)
|
||||
{
|
||||
return Json(XmlToJsonConverter.XmlToJson(xdoc.Root), _JsonSerializerSettings);
|
||||
}
|
||||
|
||||
return Content(xdoc.Declaration.ToString() + Environment.NewLine + xdoc.ToString(), "application/xml", Encoding.UTF8);
|
||||
}
|
||||
|
||||
|
@ -395,19 +422,19 @@ namespace Jackett.Server.Controllers
|
|||
if (CurrentQuery.ImdbID == null)
|
||||
{
|
||||
logger.Warn($"A search request from {Request.HttpContext.Connection.RemoteIpAddress} was made with an invalid imdbid.");
|
||||
return GetErrorXML(201, "Incorrect parameter: invalid imdbid format");
|
||||
return GetError(201, "Incorrect parameter: invalid imdbid format");
|
||||
}
|
||||
|
||||
if (CurrentQuery.IsMovieSearch && !CurrentIndexer.TorznabCaps.MovieSearchImdbAvailable)
|
||||
{
|
||||
logger.Warn($"A search request with imdbid from {Request.HttpContext.Connection.RemoteIpAddress} was made but the indexer {CurrentIndexer.Name} doesn't support it.");
|
||||
return GetErrorXML(203, "Function Not Available: imdbid is not supported for movie search by this indexer");
|
||||
return GetError(203, "Function Not Available: imdbid is not supported for movie search by this indexer");
|
||||
}
|
||||
|
||||
if (CurrentQuery.IsTVSearch && !CurrentIndexer.TorznabCaps.TvSearchImdbAvailable)
|
||||
{
|
||||
logger.Warn($"A search request with imdbid from {Request.HttpContext.Connection.RemoteIpAddress} was made but the indexer {CurrentIndexer.Name} doesn't support it.");
|
||||
return GetErrorXML(203, "Function Not Available: imdbid is not supported for TV search by this indexer");
|
||||
return GetError(203, "Function Not Available: imdbid is not supported for TV search by this indexer");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,13 +443,13 @@ namespace Jackett.Server.Controllers
|
|||
if (CurrentQuery.IsMovieSearch && !CurrentIndexer.TorznabCaps.MovieSearchTmdbAvailable)
|
||||
{
|
||||
logger.Warn($"A search request with tmdbid from {Request.HttpContext.Connection.RemoteIpAddress} was made but the indexer {CurrentIndexer.Name} doesn't support it.");
|
||||
return GetErrorXML(203, "Function Not Available: tmdbid is not supported for movie search by this indexer");
|
||||
return GetError(203, "Function Not Available: tmdbid is not supported for movie search by this indexer");
|
||||
}
|
||||
|
||||
if (CurrentQuery.IsTVSearch && !CurrentIndexer.TorznabCaps.TvSearchTmdbAvailable)
|
||||
{
|
||||
logger.Warn($"A search request with tmdbid from {Request.HttpContext.Connection.RemoteIpAddress} was made but the indexer {CurrentIndexer.Name} doesn't support it.");
|
||||
return GetErrorXML(203, "Function Not Available: tmdbid is not supported for TV search by this indexer");
|
||||
return GetError(203, "Function Not Available: tmdbid is not supported for TV search by this indexer");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,7 +458,7 @@ namespace Jackett.Server.Controllers
|
|||
if (CurrentQuery.IsTVSearch && !CurrentIndexer.TorznabCaps.TvSearchAvailable)
|
||||
{
|
||||
logger.Warn($"A search request with tvdbid from {Request.HttpContext.Connection.RemoteIpAddress} was made but the indexer {CurrentIndexer.Name} doesn't support it.");
|
||||
return GetErrorXML(203, "Function Not Available: tvdbid is not supported for movie search by this indexer");
|
||||
return GetError(203, "Function Not Available: tvdbid is not supported for movie search by this indexer");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,7 +492,14 @@ namespace Jackett.Server.Controllers
|
|||
else
|
||||
logger.Info($"Torznab search in {CurrentIndexer.Name} for {CurrentQuery.GetQueryString()} => Found {result.Releases.Count()} releases{cacheStr} [{stopwatch.ElapsedMilliseconds:0}ms]");
|
||||
|
||||
var xml = resultPage.ToXml(new Uri(serverUrl));
|
||||
var serverUri = new Uri(serverUrl);
|
||||
if (CurrentQuery.IsJson)
|
||||
{
|
||||
var json = resultPage.ToJson(serverUri);
|
||||
return Content(json, "application/json", Encoding.UTF8);
|
||||
}
|
||||
|
||||
var xml = resultPage.ToXml(serverUri);
|
||||
|
||||
// Force the return as XML
|
||||
return Content(xml, "application/rss+xml", Encoding.UTF8);
|
||||
|
@ -485,25 +519,29 @@ namespace Jackett.Server.Controllers
|
|||
}
|
||||
}
|
||||
|
||||
return GetErrorXML(900, ex.Message, StatusCodes.Status429TooManyRequests);
|
||||
return GetError(900, ex.Message, StatusCodes.Status429TooManyRequests);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
logger.Error(e);
|
||||
return GetErrorXML(900, e.ToString());
|
||||
return GetError(900, e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[Route("[action]/{ignored?}")]
|
||||
public IActionResult GetErrorXML(int code, string description, int statusCode = StatusCodes.Status400BadRequest)
|
||||
public IActionResult GetError(int code, string description, int statusCode = StatusCodes.Status400BadRequest)
|
||||
{
|
||||
var mediaTypeHeaderValue = MediaTypeHeaderValue.Parse("application/xml");
|
||||
var mediaTypeHeaderValue = CurrentQuery.IsJson ?
|
||||
MediaTypeHeaderValue.Parse("application/json") :
|
||||
MediaTypeHeaderValue.Parse("application/xml");
|
||||
mediaTypeHeaderValue.Encoding = Encoding.UTF8;
|
||||
|
||||
return new ContentResult
|
||||
{
|
||||
StatusCode = statusCode,
|
||||
Content = CreateErrorXML(code, description),
|
||||
Content = CurrentQuery.IsJson ?
|
||||
CreateErrorJson(code, description) :
|
||||
CreateErrorXML(code, description),
|
||||
ContentType = mediaTypeHeaderValue.ToString()
|
||||
};
|
||||
}
|
||||
|
@ -520,6 +558,19 @@ namespace Jackett.Server.Controllers
|
|||
return xdoc.Declaration + Environment.NewLine + xdoc;
|
||||
}
|
||||
|
||||
public static string CreateErrorJson(int code, string description)
|
||||
{
|
||||
return new JObject
|
||||
{
|
||||
{ "error", new JObject
|
||||
{
|
||||
{ "code", code },
|
||||
{ "description", description }
|
||||
}
|
||||
}
|
||||
}.ToString();
|
||||
}
|
||||
|
||||
public static IActionResult GetErrorActionResult(RouteData routeData, HttpStatusCode status, int torznabCode, string description)
|
||||
{
|
||||
var isTorznab = routeData.Values["action"].ToString().Equals("torznab", StringComparison.OrdinalIgnoreCase);
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
using System.Xml.Linq;
|
||||
using Jackett.Common.Helpers;
|
||||
using Newtonsoft.Json;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace Jackett.Test.Common.Helpers
|
||||
{
|
||||
[TestFixture]
|
||||
public class XmlToJsonConverterTests
|
||||
{
|
||||
[Test]
|
||||
public void XmlToJsonConverter_XmlToJson_Empty()
|
||||
{
|
||||
var element = new XElement("test");
|
||||
var json = XmlToJsonConverter.XmlToJson(element);
|
||||
Assert.AreEqual("{}", json.ToString(Formatting.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void XmlToJsonConverter_XmlToJson_WithAttributes()
|
||||
{
|
||||
var element = new XElement("test", new XAttribute("attr1", "value1"), new XAttribute("attr2", "value2"));
|
||||
var json = XmlToJsonConverter.XmlToJson(element);
|
||||
Assert.AreEqual("{\"@attributes\":{\"attr1\":\"value1\",\"attr2\":\"value2\"}}", json.ToString(Formatting.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void XmlToJsonConverter_XmlToJson_WithChildElement()
|
||||
{
|
||||
var element = new XElement("test", new XElement("child"));
|
||||
var json = XmlToJsonConverter.XmlToJson(element);
|
||||
Assert.AreEqual("{\"child\":{}}", json.ToString(Formatting.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void XmlToJsonConverter_XmlToJson_WithChildElement_WithAttributes()
|
||||
{
|
||||
var element = new XElement("test", new XElement("child", new XAttribute("attr1", "value1"), new XAttribute("attr2", "value2")));
|
||||
var json = XmlToJsonConverter.XmlToJson(element);
|
||||
Assert.AreEqual("{\"child\":{\"@attributes\":{\"attr1\":\"value1\",\"attr2\":\"value2\"}}}", json.ToString(Formatting.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void XmlToJsonConverter_XmlToJson_WithChildElement_WithText()
|
||||
{
|
||||
var element = new XElement("test", new XElement("child", new XElement("subchild", "text")));
|
||||
var json = XmlToJsonConverter.XmlToJson(element);
|
||||
Assert.AreEqual("{\"child\":{\"subchild\":\"text\"}}", json.ToString(Formatting.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void XmlToJsonConverter_XmlToJson_WithChildElementArray()
|
||||
{
|
||||
var element = new XElement("test", new XElement("child"), new XElement("child"));
|
||||
var json = XmlToJsonConverter.XmlToJson(element);
|
||||
Assert.AreEqual("{\"child\":[{},{}]}", json.ToString(Formatting.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void XmlToJsonConverter_XmlToJson_WithChildElementArray_WithText()
|
||||
{
|
||||
var element = new XElement("test", new XElement("child", "text1"), new XElement("child", "text2"));
|
||||
var json = XmlToJsonConverter.XmlToJson(element);
|
||||
Assert.AreEqual("{\"child\":[\"text1\",\"text2\"]}", json.ToString(Formatting.None));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void XmlToJsonConverter_XmlToJson_HandlesNamespaces()
|
||||
{
|
||||
var document = new XDocument(
|
||||
new XElement("root",
|
||||
new XAttribute(XNamespace.Xmlns + "ns1", "http://example.com/ns1"),
|
||||
new XAttribute(XNamespace.Xmlns + "ns2", "http://example.com/ns2"),
|
||||
new XElement("{http://example.com/ns1}child1"),
|
||||
new XElement("{http://example.com/ns2}child2")
|
||||
)
|
||||
);
|
||||
|
||||
var json = XmlToJsonConverter.XmlToJson(document.Root);
|
||||
Assert.AreEqual("{\"@attributes\":{\"xmlns:ns1\":\"http://example.com/ns1\",\"xmlns:ns2\":\"http://example.com/ns2\"},\"ns1:child1\":{},\"ns2:child2\":{}}", json.ToString(Formatting.None));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue