Skip to content

Commit 821be7b

Browse files
committed
Fix issue #398: XmlNotepad detects xml-errors at empty nillable xsd:date Elements, but xml is correct and add new unit test.
1 parent af381cc commit 821be7b

File tree

7 files changed

+71
-2
lines changed

7 files changed

+71
-2
lines changed

src/Model/Checker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ bool LoadSchemas(XmlDocument doc, XmlSchemaSet set, SchemaResolver resolver)
179179
{
180180
result |= LoadSchemasForNamespace(set, resolver, sc, nsuri, root);
181181
}
182+
result |= LoadSchemasForNamespace(set, resolver, sc, doc.DocumentElement.NamespaceURI, root);
182183
}
183184
// Make sure all the required includes or imports are there.
184185
// This is making up for a possible bug in XmlSchemaSet where it

src/Model/XmlHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public static bool IsXsiAttribute(XmlNode node)
219219
{
220220
if (node == null) return false;
221221
return node.NodeType == XmlNodeType.Attribute &&
222-
(node.LocalName == "type" && node.NamespaceURI == "http://www.w3.org/2001/XMLSchema-instance");
222+
node.NamespaceURI == "http://www.w3.org/2001/XMLSchema-instance";
223223
}
224224
}
225225

src/UnitTests/UnitTest1.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ Window LaunchNotepad(string filename, bool testSettings = true, bool debugMouse
123123
return window;
124124
}
125125

126+
AutomationWrapper ErrorList
127+
{
128+
get
129+
{
130+
AutomationWrapper grid = this.window.FindDescendant("DataGridView");
131+
return grid;
132+
}
133+
}
134+
126135

127136
AutomationWrapper XmlTreeView
128137
{
@@ -690,7 +699,7 @@ public void TestIntellisense()
690699

691700
private void NavigateErrorWithMouse()
692701
{
693-
AutomationWrapper grid = this.window.FindDescendant("DataGridView");
702+
AutomationWrapper grid = this.ErrorList;
694703
AutomationWrapper row = grid.FirstChild;
695704
row = row.NextSibling;
696705
Point pt = row.Bounds.Center();
@@ -1337,6 +1346,42 @@ public void TestSchemaDialog()
13371346

13381347
}
13391348

1349+
1350+
[TestMethod]
1351+
[Timeout(TestMethodTimeout)]
1352+
public void TestXsiAttributes()
1353+
{
1354+
Trace.WriteLine("TestXsiAttributes==========================================================");
1355+
string testFile = _testDir + "UnitTests\\test13.xml";
1356+
var w = LaunchNotepad(testFile);
1357+
1358+
AutomationWrapper grid = this.ErrorList;
1359+
AutomationWrapper description = grid.FirstChild.NextSibling.FirstChild.NextSibling;
1360+
var text = description.SimpleValue;
1361+
if (!text.Contains("The 'last_changed' element is invalid"))
1362+
{
1363+
throw new Exception("Missing validation error");
1364+
}
1365+
1366+
// correct the value of the xsi:nil attribute
1367+
w.SendKeystrokes("{END}{RIGHT}{DOWN}{TAB}{ENTER}true{ENTER}");
1368+
Sleep(500);
1369+
1370+
try
1371+
{
1372+
description = grid.FirstChild.NextSibling.FirstChild.NextSibling;
1373+
text = description.SimpleValue;
1374+
throw new Exception($"Error list should now be empty, but found: {text}");
1375+
}
1376+
catch (Exception ex)
1377+
{
1378+
if (!ex.Message.Contains("There is no next sibling"))
1379+
{
1380+
throw new Exception($"Unexpected error: {ex.Message}");
1381+
}
1382+
}
1383+
}
1384+
13401385
[TestMethod]
13411386
[Timeout(TestMethodTimeout)]
13421387
public void TestSchemaGeneration()

src/UnitTests/UnitTests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<Content Include="test11.xml" />
8080
<Content Include="test12.xml" />
8181
<Content Include="test10.xml" />
82+
<Content Include="test13.xml" />
8283
<Content Include="test2.xml" />
8384
<Content Include="test3.xml" />
8485
<Content Include="test4.xml" />
@@ -126,6 +127,9 @@
126127
<None Include="patients.xsd">
127128
<SubType>Designer</SubType>
128129
</None>
130+
<None Include="test13.xsd">
131+
<SubType>Designer</SubType>
132+
</None>
129133
<None Include="test2.xsd">
130134
<SubType>Designer</SubType>
131135
</None>

src/UnitTests/test13.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test13.xsd">
3+
<name>Chris</name>
4+
<last_changed xsi:nil="false" />
5+
</root>

src/UnitTests/test13.xsd

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
xmlns:vs="http://schemas.microsoft.com/Visual-Studio-Intellisense">
5+
<xs:element name="root">
6+
<xs:complexType>
7+
<xs:sequence maxOccurs="2">
8+
<xs:element name="name" type="xs:string" />
9+
<xs:element name="last_changed" type="xs:date" nillable="true" minOccurs="0"/>
10+
</xs:sequence>
11+
</xs:complexType>
12+
</xs:element>
13+
</xs:schema>

src/Updates/Updates.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
</application>
1212
<version number="2.9.0.14">
1313
<bug>Fix issue #418: check setttings-file for "read-only".</bug>
14+
<bug>Fix issue #398: XmlNotepad detects xml-errors at empty nillable xsd:date Elements, but xml is correct</bug>
1415
</version>
1516
<version number="2.9.0.13">
1617
<feature>Issue 409: Not able to validate XML against multiple not referenced Schemas</feature>

0 commit comments

Comments
 (0)