Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -696,13 +696,24 @@ private bool WriteMemberText(Member anyText)
{
if (anyTextMapping.TypeDesc!.IsArrayLike)
{
string textValue;
if (text.Mapping!.TypeDesc!.CollapseWhitespace)
{
value = CollapseWhitespace(Reader.ReadString());
textValue = CollapseWhitespace(Reader.ReadString());
}
else
{
value = Reader.ReadString();
textValue = Reader.ReadString();
}
// For string arrays with XmlText, split on whitespace to support XML Schema list types
if (anyTextMapping.TypeDesc.Type == typeof(string[]))
{
string[] vals = textValue.Split((char[]?)null, StringSplitOptions.RemoveEmptyEntries);
value = vals;
}
else
{
value = textValue;
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,12 @@ private void WriteText(object o, TextAccessor text)
}
else
{
if (!WritePrimitiveValue(primitiveMapping.TypeDesc!, o, out stringValue))
// Handle string arrays as space-separated lists for XML Schema list types
if (o is string[] stringArray)
{
stringValue = string.Join(" ", stringArray);
}
else if (!WritePrimitiveValue(primitiveMapping.TypeDesc!, o, out stringValue))
{
Debug.Assert(o is byte[]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,11 @@ public static void XML_TypeWithXmlTextAttributeOnArray()

var actual = SerializeAndDeserialize<TypeWithXmlTextAttributeOnArray>(original,
@"<?xml version=""1.0""?>
<TypeWithXmlTextAttributeOnArray xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://schemas.xmlsoap.org/ws/2005/04/discovery"">val1val2</TypeWithXmlTextAttributeOnArray>");
<TypeWithXmlTextAttributeOnArray xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns=""http://schemas.xmlsoap.org/ws/2005/04/discovery"">val1 val2</TypeWithXmlTextAttributeOnArray>");
Assert.NotNull(actual.Text);
Assert.StrictEqual(1, actual.Text.Length);
Assert.Equal("val1val2", actual.Text[0]);
Assert.StrictEqual(2, actual.Text.Length);
Assert.Equal("val1", actual.Text[0]);
Assert.Equal("val2", actual.Text[1]);
}

[Fact]
Expand Down
Loading