-Fixed XmlNodeConverter not turning all attribute properties into attributes
-Added .gitattributes file
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
*.doc diff=astextplain
|
||||
*.DOC diff=astextplain
|
||||
*.docx diff=astextplain
|
||||
*.DOCX diff=astextplain
|
||||
*.dot diff=astextplain
|
||||
*.DOT diff=astextplain
|
||||
*.pdf diff=astextplain
|
||||
*.PDF diff=astextplain
|
||||
*.rtf diff=astextplain
|
||||
*.RTF diff=astextplain
|
||||
|
||||
*.jpg binary
|
||||
*.png binary
|
||||
*.gif binary
|
||||
|
||||
*.cs text diff=csharp
|
||||
*.vb text
|
||||
*.c text
|
||||
*.cpp text
|
||||
*.cxx text
|
||||
*.h text
|
||||
*.hxx text
|
||||
*.py text
|
||||
*.rb text
|
||||
*.java text
|
||||
*.html text
|
||||
*.htm text
|
||||
*.css text
|
||||
*.scss text
|
||||
*.sass text
|
||||
*.less text
|
||||
*.js text
|
||||
*.lisp text
|
||||
*.clj text
|
||||
*.sql text
|
||||
*.php text
|
||||
*.lua text
|
||||
*.m text
|
||||
*.asm text
|
||||
*.erl text
|
||||
*.fs text
|
||||
*.fsx text
|
||||
*.hs text
|
||||
|
||||
*.csproj text merge=union
|
||||
*.vbproj text merge=union
|
||||
*.fsproj text merge=union
|
||||
*.dbproj text merge=union
|
||||
*.sln text eol=crlf merge=union
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
$workingDir = "$baseDir\Working"
|
||||
$builds = @(
|
||||
@{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net40"; NuGetDir = "net40"; Framework="net-4.0"; Sign=$true},
|
||||
@{Name = "Newtonsoft.Json.Metro"; TestsName = $null; Constants="NETFX_CORE"; FinalDir="Metro"; NuGetDir = "winrt45"; Framework="net-4.5"; Sign=$true},
|
||||
#@{Name = "Newtonsoft.Json.Metro"; TestsName = $null; Constants="NETFX_CORE"; FinalDir="Metro"; NuGetDir = "winrt45"; Framework="net-4.5"; Sign=$true},
|
||||
|
||||
# unsigned SL/WP
|
||||
@{Name = "Newtonsoft.Json.WindowsPhone"; TestsName = $null; Constants="SILVERLIGHT;WINDOWS_PHONE"; FinalDir="WindowsPhone"; NuGetDir = "sl3-wp,sl4-windowsphone71"; Framework="net-4.0"; Sign=$false},
|
||||
|
||||
@@ -383,12 +383,12 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
""@class"": ""vevent"",
|
||||
""a"": {
|
||||
""@class"": ""url"",
|
||||
""@href"": ""http://www.web2con.com/"",
|
||||
""span"": {
|
||||
""@class"": ""summary"",
|
||||
""#text"": ""Web 2.0 Conference"",
|
||||
""#cdata-section"": ""my escaped text""
|
||||
}
|
||||
},
|
||||
""@href"": ""http://www.web2con.com/""
|
||||
}
|
||||
}
|
||||
}";
|
||||
@@ -481,7 +481,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
[Test]
|
||||
public void OtherElementDataTypes()
|
||||
{
|
||||
string jsonText = @"{""?xml"":{""@version"":""1.0"",""@standalone"":""no""},""root"":{""person"":[{""@id"":""1"",""Float"":2.5,""Integer"":99},{""@id"":""2"",""Boolean"":true,""date"":""\/Date(954374400000)\/""}]}}";
|
||||
string jsonText = @"{""?xml"":{""@version"":""1.0"",""@standalone"":""no""},""root"":{""person"":[{""@id"":""1"",""Float"":2.5,""Integer"":99},{""Boolean"":true,""@id"":""2"",""date"":""\/Date(954374400000)\/""}]}}";
|
||||
|
||||
XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
|
||||
|
||||
@@ -1796,6 +1796,16 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
|
||||
Assert.AreEqual(expectedXaml, xaml2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeAttributePropertyNotAtStart()
|
||||
{
|
||||
string json = @"{""item"": {""@action"": ""update"", ""@itemid"": ""1"", ""elements"": [{""@action"": ""none"", ""@id"": ""2""},{""@action"": ""none"", ""@id"": ""3""}],""@description"": ""temp""}}";
|
||||
|
||||
XmlDocument xmldoc = JsonConvert.DeserializeXmlNode(json);
|
||||
|
||||
Assert.AreEqual(@"<item action=""update"" itemid=""1"" description=""temp""><elements action=""none"" id=""2"" /><elements action=""none"" id=""3"" /></item>", xmldoc.InnerXml);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1183,44 +1183,60 @@ namespace Newtonsoft.Json.Converters
|
||||
|
||||
string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);
|
||||
|
||||
IXmlElement element = CreateElement(propertyName, document, elementPrefix, manager);
|
||||
|
||||
currentNode.AppendChild(element);
|
||||
|
||||
// add attributes to newly created element
|
||||
foreach (KeyValuePair<string, string> nameValue in attributeNameValues)
|
||||
if (propertyName.StartsWith("@"))
|
||||
{
|
||||
string attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);
|
||||
var attributeName = propertyName.Substring(1);
|
||||
var attributeValue = reader.Value.ToString();
|
||||
|
||||
IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
|
||||
? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix), nameValue.Value)
|
||||
: document.CreateAttribute(nameValue.Key, nameValue.Value);
|
||||
var attributePrefix = MiscellaneousUtils.GetPrefix(attributeName);
|
||||
|
||||
element.SetAttributeNode(attribute);
|
||||
}
|
||||
var attribute = (!string.IsNullOrEmpty(attributePrefix))
|
||||
? document.CreateAttribute(attributeName, manager.LookupNamespace(attributePrefix), attributeValue)
|
||||
: document.CreateAttribute(attributeName, attributeValue);
|
||||
|
||||
if (reader.TokenType == JsonToken.String
|
||||
|| reader.TokenType == JsonToken.Integer
|
||||
|| reader.TokenType == JsonToken.Float
|
||||
|| reader.TokenType == JsonToken.Boolean
|
||||
|| reader.TokenType == JsonToken.Date)
|
||||
{
|
||||
element.AppendChild(document.CreateTextNode(ConvertTokenToXmlValue(reader)));
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.Null)
|
||||
{
|
||||
// empty element. do nothing
|
||||
((IXmlElement)currentNode).SetAttributeNode(attribute);
|
||||
}
|
||||
else
|
||||
{
|
||||
// finished element will have no children to deserialize
|
||||
if (reader.TokenType != JsonToken.EndObject)
|
||||
IXmlElement element = CreateElement(propertyName, document, elementPrefix, manager);
|
||||
|
||||
currentNode.AppendChild(element);
|
||||
|
||||
// add attributes to newly created element
|
||||
foreach (KeyValuePair<string, string> nameValue in attributeNameValues)
|
||||
{
|
||||
manager.PushScope();
|
||||
string attributePrefix = MiscellaneousUtils.GetPrefix(nameValue.Key);
|
||||
|
||||
DeserializeNode(reader, document, manager, element);
|
||||
IXmlNode attribute = (!string.IsNullOrEmpty(attributePrefix))
|
||||
? document.CreateAttribute(nameValue.Key, manager.LookupNamespace(attributePrefix), nameValue.Value)
|
||||
: document.CreateAttribute(nameValue.Key, nameValue.Value);
|
||||
|
||||
manager.PopScope();
|
||||
element.SetAttributeNode(attribute);
|
||||
}
|
||||
|
||||
if (reader.TokenType == JsonToken.String
|
||||
|| reader.TokenType == JsonToken.Integer
|
||||
|| reader.TokenType == JsonToken.Float
|
||||
|| reader.TokenType == JsonToken.Boolean
|
||||
|| reader.TokenType == JsonToken.Date)
|
||||
{
|
||||
element.AppendChild(document.CreateTextNode(ConvertTokenToXmlValue(reader)));
|
||||
}
|
||||
else if (reader.TokenType == JsonToken.Null)
|
||||
{
|
||||
// empty element. do nothing
|
||||
}
|
||||
else
|
||||
{
|
||||
// finished element will have no children to deserialize
|
||||
if (reader.TokenType != JsonToken.EndObject)
|
||||
{
|
||||
manager.PushScope();
|
||||
|
||||
DeserializeNode(reader, document, manager, element);
|
||||
|
||||
manager.PopScope();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user