Skip to content

Commit

Permalink
[system.data] Skip over non-element nodes in an xml fragment (mono#20714
Browse files Browse the repository at this point in the history
)

This is what MS.NET does when loading fragments. Bug is on https://bugzilla.xamarin.com/show_bug.cgi?id=20714
  • Loading branch information
mattleibow committed Jun 19, 2014
1 parent dc18aac commit f0b412d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mcs/class/System.Data/System.Data/DataSet.cs
Expand Up @@ -1010,6 +1010,8 @@ public XmlReadMode ReadXml (XmlReader reader, XmlReadMode mode)
}
}

while (reader.NodeType != XmlNodeType.Element && !reader.EOF)
reader.Skip ();
if (reader.EOF)
return mode;

Expand Down
69 changes: 69 additions & 0 deletions mcs/class/System.Data/Test/System.Data/DataSetReadXmlTest.cs
Expand Up @@ -91,6 +91,10 @@ public class DataSetReadXmlTest : DataSetAssertion
</xs:element>
</xs:schema>";
const string schema2 = schema1 + xml8;
const string schema3 = schema1 + "<!-- some comment -->" + xml8;
const string schema4 = schema1 + "some text" + xml8;
const string schema5 = schema1 + "<![CDATA[ some stuff here ]]>" + xml8;
const string schema6 = schema1 + "<!-- some comment -->some text" + xml8;

[Test]
public void ReadSimpleAuto ()
Expand Down Expand Up @@ -582,6 +586,71 @@ public void TestSimpleSchemaPlusContentAll ()
AssertReadXml (ds, "ReadSchema", schema2,
XmlReadMode.ReadSchema, XmlReadMode.ReadSchema,
"NewDataSet", 1, ReadState.Interactive);
AssertDataTable ("readschema", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);
}

[Test]
public void TestSimpleSchemaPlusContentWithNonElementAll ()
{
DataSet ds;

// Fragment ... consumed both, skipping the comment in the middle
ds = new DataSet ();
AssertReadXml (ds, "read skip comment", schema3,
XmlReadMode.Fragment, XmlReadMode.Fragment,
"NewDataSet", 1);
AssertDataTable ("assert skip comment", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);

// Fragment ... consumed both, skipping the text in the middle
ds = new DataSet ();
AssertReadXml (ds, "read skip text", schema4,
XmlReadMode.Fragment, XmlReadMode.Fragment,
"NewDataSet", 1);
AssertDataTable ("assert skip text", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);

// Fragment ... consumed both, skipping the CDATA in the middle
ds = new DataSet ();
AssertReadXml (ds, "read skip cdata", schema5,
XmlReadMode.Fragment, XmlReadMode.Fragment,
"NewDataSet", 1);
AssertDataTable ("assert skip cdata", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);

// Fragment ... consumed both, skipping the comment and the text in the middle
ds = new DataSet ();
AssertReadXml (ds, "read skip comment and text", schema6,
XmlReadMode.Fragment, XmlReadMode.Fragment,
"NewDataSet", 1);
AssertDataTable ("assert skip comment and text", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);
}

[Test]
public void TestSimpleSchemaPlusContentWithComments ()
{
const string xml =
@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<!-- structure for dataset starts here -->
<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
<xs:element name='Root'>
<xs:complexType>
<xs:sequence>
<xs:element name='Child' type='xs:string' />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<!-- data for dataset starts here -->
<dataset>
<Root>
<Child>Row One!</Child>
</Root>
</dataset>
<!-- end xml -->";
TextReader stringReader = new StringReader(xml);
XmlReader reader = XmlReader.Create(stringReader, new XmlReaderSettings {
ConformanceLevel = ConformanceLevel.Fragment
});
DataSet ds = new DataSet();
ds.ReadXml(reader, XmlReadMode.Fragment);
}

[Test]
Expand Down

0 comments on commit f0b412d

Please sign in to comment.