-Fixed XmlNodeConverter not turning all attribute properties into attributes

-Added .gitattributes file
This commit is contained in:
James Newton-King
2012-03-31 15:39:53 +13:00
parent b10ad030ac
commit a139d7bf20
5 changed files with 3520 additions and 3445 deletions
+49
View File
@@ -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
View File
@@ -17,7 +17,7 @@
$workingDir = "$baseDir\Working" $workingDir = "$baseDir\Working"
$builds = @( $builds = @(
@{Name = "Newtonsoft.Json"; TestsName = "Newtonsoft.Json.Tests"; Constants=""; FinalDir="Net40"; NuGetDir = "net40"; Framework="net-4.0"; Sign=$true}, @{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 # 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}, @{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"", ""@class"": ""vevent"",
""a"": { ""a"": {
""@class"": ""url"", ""@class"": ""url"",
""@href"": ""http://www.web2con.com/"",
""span"": { ""span"": {
""@class"": ""summary"", ""@class"": ""summary"",
""#text"": ""Web 2.0 Conference"", ""#text"": ""Web 2.0 Conference"",
""#cdata-section"": ""my escaped text"" ""#cdata-section"": ""my escaped text""
} },
""@href"": ""http://www.web2con.com/""
} }
} }
}"; }";
@@ -481,7 +481,7 @@ namespace Newtonsoft.Json.Tests.Converters
[Test] [Test]
public void OtherElementDataTypes() 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); XmlDocument newDoc = (XmlDocument)DeserializeXmlNode(jsonText);
@@ -1796,6 +1796,16 @@ namespace Newtonsoft.Json.Tests.Converters
Assert.AreEqual(expectedXaml, xaml2); 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 #endif
@@ -1183,6 +1183,21 @@ namespace Newtonsoft.Json.Converters
string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName); string elementPrefix = MiscellaneousUtils.GetPrefix(propertyName);
if (propertyName.StartsWith("@"))
{
var attributeName = propertyName.Substring(1);
var attributeValue = reader.Value.ToString();
var attributePrefix = MiscellaneousUtils.GetPrefix(attributeName);
var attribute = (!string.IsNullOrEmpty(attributePrefix))
? document.CreateAttribute(attributeName, manager.LookupNamespace(attributePrefix), attributeValue)
: document.CreateAttribute(attributeName, attributeValue);
((IXmlElement)currentNode).SetAttributeNode(attribute);
}
else
{
IXmlElement element = CreateElement(propertyName, document, elementPrefix, manager); IXmlElement element = CreateElement(propertyName, document, elementPrefix, manager);
currentNode.AppendChild(element); currentNode.AppendChild(element);
@@ -1224,6 +1239,7 @@ namespace Newtonsoft.Json.Converters
} }
} }
} }
}
private string ConvertTokenToXmlValue(JsonReader reader) private string ConvertTokenToXmlValue(JsonReader reader)
{ {