Skip to content

Commit

Permalink
Fix issue #398: XmlNotepad detects xml-errors at empty nillable xsd:d…
Browse files Browse the repository at this point in the history
…ate Elements, but xml is correct and add new unit test.
  • Loading branch information
clovett committed Sep 26, 2024
1 parent af381cc commit 821be7b
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Model/Checker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ bool LoadSchemas(XmlDocument doc, XmlSchemaSet set, SchemaResolver resolver)
{
result |= LoadSchemasForNamespace(set, resolver, sc, nsuri, root);
}
result |= LoadSchemasForNamespace(set, resolver, sc, doc.DocumentElement.NamespaceURI, root);
}
// Make sure all the required includes or imports are there.
// This is making up for a possible bug in XmlSchemaSet where it
Expand Down
2 changes: 1 addition & 1 deletion src/Model/XmlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static bool IsXsiAttribute(XmlNode node)
{
if (node == null) return false;
return node.NodeType == XmlNodeType.Attribute &&
(node.LocalName == "type" && node.NamespaceURI == "http://www.w3.org/2001/XMLSchema-instance");
node.NamespaceURI == "http://www.w3.org/2001/XMLSchema-instance";
}
}

Expand Down
47 changes: 46 additions & 1 deletion src/UnitTests/UnitTest1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ Window LaunchNotepad(string filename, bool testSettings = true, bool debugMouse
return window;
}

AutomationWrapper ErrorList
{
get
{
AutomationWrapper grid = this.window.FindDescendant("DataGridView");
return grid;
}
}


AutomationWrapper XmlTreeView
{
Expand Down Expand Up @@ -690,7 +699,7 @@ public void TestIntellisense()

private void NavigateErrorWithMouse()
{
AutomationWrapper grid = this.window.FindDescendant("DataGridView");
AutomationWrapper grid = this.ErrorList;
AutomationWrapper row = grid.FirstChild;
row = row.NextSibling;
Point pt = row.Bounds.Center();
Expand Down Expand Up @@ -1337,6 +1346,42 @@ public void TestSchemaDialog()

}


[TestMethod]
[Timeout(TestMethodTimeout)]
public void TestXsiAttributes()
{
Trace.WriteLine("TestXsiAttributes==========================================================");
string testFile = _testDir + "UnitTests\\test13.xml";
var w = LaunchNotepad(testFile);

AutomationWrapper grid = this.ErrorList;
AutomationWrapper description = grid.FirstChild.NextSibling.FirstChild.NextSibling;
var text = description.SimpleValue;
if (!text.Contains("The 'last_changed' element is invalid"))
{
throw new Exception("Missing validation error");
}

// correct the value of the xsi:nil attribute
w.SendKeystrokes("{END}{RIGHT}{DOWN}{TAB}{ENTER}true{ENTER}");
Sleep(500);

try
{
description = grid.FirstChild.NextSibling.FirstChild.NextSibling;
text = description.SimpleValue;
throw new Exception($"Error list should now be empty, but found: {text}");
}
catch (Exception ex)
{
if (!ex.Message.Contains("There is no next sibling"))
{
throw new Exception($"Unexpected error: {ex.Message}");
}
}
}

[TestMethod]
[Timeout(TestMethodTimeout)]
public void TestSchemaGeneration()
Expand Down
4 changes: 4 additions & 0 deletions src/UnitTests/UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Content Include="test11.xml" />
<Content Include="test12.xml" />
<Content Include="test10.xml" />
<Content Include="test13.xml" />
<Content Include="test2.xml" />
<Content Include="test3.xml" />
<Content Include="test4.xml" />
Expand Down Expand Up @@ -126,6 +127,9 @@
<None Include="patients.xsd">
<SubType>Designer</SubType>
</None>
<None Include="test13.xsd">
<SubType>Designer</SubType>
</None>
<None Include="test2.xsd">
<SubType>Designer</SubType>
</None>
Expand Down
5 changes: 5 additions & 0 deletions src/UnitTests/test13.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test13.xsd">
<name>Chris</name>
<last_changed xsi:nil="false" />
</root>
13 changes: 13 additions & 0 deletions src/UnitTests/test13.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:vs="http://schemas.microsoft.com/Visual-Studio-Intellisense">
<xs:element name="root">
<xs:complexType>
<xs:sequence maxOccurs="2">
<xs:element name="name" type="xs:string" />
<xs:element name="last_changed" type="xs:date" nillable="true" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
1 change: 1 addition & 0 deletions src/Updates/Updates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
</application>
<version number="2.9.0.14">
<bug>Fix issue #418: check setttings-file for "read-only".</bug>
<bug>Fix issue #398: XmlNotepad detects xml-errors at empty nillable xsd:date Elements, but xml is correct</bug>
</version>
<version number="2.9.0.13">
<feature>Issue 409: Not able to validate XML against multiple not referenced Schemas</feature>
Expand Down

0 comments on commit 821be7b

Please sign in to comment.