Skip to content

Commit

Permalink
XmlDocument Fix (#12)
Browse files Browse the repository at this point in the history
* Fixed the GetXml() of XmlDocument (double declaration) and added GetOriginalXml().

* Format of documents

* Removing GetOriginalXml as it's not really possible due to the Parser.
  • Loading branch information
MichielOda authored Nov 27, 2023

Verified

This commit was signed with the committer’s verified signature.
sambostock Sam Bostock
1 parent 6ff32c6 commit b6652c3
Showing 3 changed files with 30 additions and 5 deletions.
1 change: 1 addition & 0 deletions Parsers.Common/Xml/Parser.cs
Original file line number Diff line number Diff line change
@@ -201,6 +201,7 @@ private void Step1_CharsToTokens(Queue<Token> tokens)
tokens.Enqueue(token);
}
}

private void Step2_TokensToTree(Queue<Token> tokens, out XmlDocument root)
{
Stack<XmlNode> nodes = new Stack<XmlNode>();
6 changes: 1 addition & 5 deletions Parsers.Common/Xml/XmlDocument.cs
Original file line number Diff line number Diff line change
@@ -52,15 +52,11 @@ public static XmlDocument Load(string path)
return Parse(xml);
}

/// <inheritdoc />
public override string GetXml()
{
var sb = new StringBuilder();

if (Declaration != null)
{
sb.Append(Declaration.GetXml());
}

foreach (var c in Children)
{
sb.Append(c.GetXml());
28 changes: 28 additions & 0 deletions Parsers.CommonTests/Xml/XmlDocumentTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Parsers.CommonTests.Xml
{
using FluentAssertions;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Skyline.DataMiner.CICD.Parsers.Common.Xml;

[TestClass]
public class XmlDocumentTests
{
[TestMethod]
public void XmlDocument_GetXml()
{
// Arrange
const string xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?><abc></abc>";
const string expectedXml = @"<?xml version=""1.0"" encoding=""utf-8"" ?><abc />";

XmlDocument document = XmlDocument.Parse(xml);

// Act
var result = document.GetXml();

// Check
result.Should().BeEquivalentTo(expectedXml);
}
}
}

0 comments on commit b6652c3

Please sign in to comment.