Skip to content

Commit

Permalink
add more whitespace sensitive ISource types knowing about the XML spec
Browse files Browse the repository at this point in the history
see #39
  • Loading branch information
bodewig committed Apr 10, 2023
1 parent aa7ae9f commit 893c09b
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 4 deletions.
5 changes: 3 additions & 2 deletions RELEASE_NOTES.md
Expand Up @@ -12,8 +12,9 @@
[#38](https://github.com/xmlunit/xmlunit.net/issues/38). And neither
of the methods could deal with `XmlSignificantWhitespace` at all.

* add `XmlWhitespaceStrippedSource` that only trims characters that
are considered whitespace by the [XML
* add `XmlWhitespaceStrippedSource`, `XmlWhitespaceNormalizedSource`
and `XmlElementContentWhitespaceStrippedSource` that only trim
characters that are considered whitespace by the [XML
Specification](https://www.w3.org/TR/xml11/#NT-S) from textual
content.
Issue [#39](https://github.com/xmlunit/xmlunit.net/issues/39).
Expand Down
Expand Up @@ -22,6 +22,11 @@ namespace Org.XmlUnit.Input {
/// </summary>
/// <remarks>
/// <para>
/// Unlike <see cref="XmlElementContentWhitespaceStrippedSource"/> this class uses
/// Unicode's idea of whitespace rather than the more restricted
/// subset considered whitespace by XML.
/// </para>
/// <para>
/// since XMLUnit 2.6.0
/// </para>
/// </remarks>
Expand Down
11 changes: 11 additions & 0 deletions src/main/net-core/Input/WhitespaceNormalizedSource.cs
Expand Up @@ -21,9 +21,20 @@ namespace Org.XmlUnit.Input {
/// all empty text nodes and normalizing the non-empty ones.
/// </summary>
/// <remarks>
/// <para>
/// "normalized" in this context means all whitespace characters
/// are replaced by space characters and consecutive whitespace
/// characters are collapsed.
/// </para>
/// <para>
/// This class is similiar to <see cref="WhitespaceStrippedSource"/>
/// but in addition "normalizes" whitespace.
/// </para>
/// <para>
/// Unlike <see cref="XmlWhitespaceNormalizedSource"/> this class uses
/// Unicode's idea of whitespace rather than the more restricted
/// subset considered whitespace by XML.
/// </para>
/// </remarks>
public class WhitespaceNormalizedSource : DOMSource {
/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/main/net-core/Input/WhitespaceStrippedSource.cs
Expand Up @@ -27,6 +27,11 @@ namespace Org.XmlUnit.Input {
/// other text nodes alone you should use
/// ElementContentWhitespaceStrippedSource instead.
/// </para>
/// <para>
/// Unlike <see cref="XmlWhitespaceStrippedSource"/> this class uses
/// Unicode's idea of whitespace rather than the more restricted
/// subset considered whitespace by XML.
/// </para>
/// </remarks>
public class WhitespaceStrippedSource : DOMSource {
/// <summary>
Expand Down
@@ -0,0 +1,44 @@
/*
This file is licensed to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

using Org.XmlUnit.Util;

namespace Org.XmlUnit.Input {

/// <summary>
/// A source that is obtained from a different source by removing all
/// text nodes that only contain whitespace.
/// </summary>
/// <remarks>
/// <para>
/// Unlike <see cref="ElementContentWhitespaceStrippedSource"/>
/// this class uses XML's idea of whitespace rather than the more
/// extensive set considered whitespace by Unicode.
/// </para>
/// <para>
/// since XMLUnit 2.10.0
/// </para>
/// </remarks>
public class XmlElementContentWhitespaceStrippedSource : DOMSource {
/// <summary>
/// Creates a new source that consists of the given source with all
/// text nodes that only contain whitespace stripped.
/// </summary>
/// <param name="originalSource">source with the original content</param>
public XmlElementContentWhitespaceStrippedSource(ISource originalSource) :
base(Nodes.StripXmlElementContentWhitespace(originalSource.ToDocument())) {
SystemId = originalSource.SystemId;
}
}
}
53 changes: 53 additions & 0 deletions src/main/net-core/Input/XmlWhitespaceNormalizedSource.cs
@@ -0,0 +1,53 @@
/*
This file is licensed to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

using Org.XmlUnit.Util;

namespace Org.XmlUnit.Input {

/// <summary>
/// A source that is obtained from a different source by removing
/// all empty text nodes and normalizing the non-empty ones.
/// </summary>
/// <remarks>
/// <para>
/// "normalized" in this context means all XML whitespace
/// characters are replaced by space characters and
/// consecutive XML whitespace characters are collapsed.
/// </para>
/// <para>
/// This class is similiar to <see cref="XmlWhitespaceStrippedSource"/>
/// but in addition "normalizes" XML whitespace.
/// </para>
/// <para>
/// Unlike <see cref="WhitespaceNormalizedSource"/> this uses XML's idea
/// of whitespace rather than the more extensive set considered
/// whitespace by Unicode.
/// </para>
/// <para>
/// since XMLUnit 2.10.0
/// </para>
/// </remarks>
public class XmlWhitespaceNormalizedSource : DOMSource {
/// <summary>
/// Creates a new Source with the same content as another source normalizing XML whitespace in Text nodes.
/// </summary>
/// <param name="originalSource">source with the original content</param>
public XmlWhitespaceNormalizedSource(ISource originalSource) :
base(Nodes.NormalizeXmlWhitespace(originalSource.ToDocument()))
{
SystemId = originalSource.SystemId;
}
}
}
5 changes: 5 additions & 0 deletions src/main/net-core/Input/XmlWhitespaceStrippedSource.cs
Expand Up @@ -30,6 +30,11 @@ namespace Org.XmlUnit.Input {
/// ElementContentWhitespaceStrippedSource instead.
/// </para>
/// <para>
/// Unlike <see cref="WhitespaceStrippedSource"/> this uses XML's idea
/// of whitespace rather than the more extensive set considered
/// whitespace by Unicode.
/// </para>
/// <para>
/// since XMLUnit 2.10.0
/// </para>
/// </remarks>
Expand Down
Expand Up @@ -110,6 +110,8 @@
<Compile Include="..\Input\StringSource.cs" />
<Compile Include="..\Input\WhitespaceNormalizedSource.cs" />
<Compile Include="..\Input\WhitespaceStrippedSource.cs" />
<Compile Include="..\Input\XmlElementContentWhitespaceStrippedSource.cs" />
<Compile Include="..\Input\XmlWhitespaceNormalizedSource.cs" />
<Compile Include="..\Input\XmlWhitespaceStrippedSource.cs" />
<Compile Include="..\ISource.cs" />
<Compile Include="..\Transform\Transformation.cs" />
Expand Down
4 changes: 2 additions & 2 deletions src/main/net-core/Util/Nodes.cs
Expand Up @@ -130,7 +130,7 @@ public static class Nodes {
/// <para>
/// "normalized" in this context means all whitespace
/// characters are replaced by space characters and
/// consecutive whitespace characaters are collapsed.
/// consecutive whitespace characters are collapsed.
/// </para>
/// <para>
/// This method is similiar to <see cref="StripWhitespace"/>
Expand Down Expand Up @@ -159,7 +159,7 @@ public static class Nodes {
/// <para>
/// "normalized" in this context means all XML whitespace
/// characters are replaced by space characters and
/// consecutive XML whitespace characaters are collapsed.
/// consecutive XML whitespace characters are collapsed.
/// </para>
/// <para>
/// This method is similiar to <see cref="StripXmlWhitespace"/>
Expand Down

0 comments on commit 893c09b

Please sign in to comment.