Skip to content

Commit

Permalink
Clean X namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
askonomm committed Nov 3, 2024
1 parent 356e31b commit bccac7b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Htmt/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ private void Parse()
AddIdentifierToNodes();
RunAttributeParsers();
RemoveIdentifierFromNodes();
RemoveXNamespace();
}

/// <summary>
Expand Down Expand Up @@ -321,4 +322,27 @@ private void RemoveIdentifierFromNodes()
}
}
}

/// <summary>
/// Removes the x namespace from the document.
/// </summary>
private void RemoveXNamespace()
{
if (Xml.DocumentElement == null) return;

var nodesToProcess = new Queue<XmlNode>(Xml.DocumentElement.ChildNodes.Cast<XmlNode>());

while (nodesToProcess.Count > 0)
{
var node = nodesToProcess.Dequeue();
if (node is not XmlElement element) continue;

element.RemoveAttribute("xmlns:x");

foreach (XmlNode child in element.ChildNodes)
{
nodesToProcess.Enqueue(child);
}
}
}
}

0 comments on commit bccac7b

Please sign in to comment.