-
-
Save anonymous/a09a66b9e2138af180ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using HtmlAgilityPack; | |
namespace HAP43229 | |
{ | |
class Program | |
{ | |
static string getHtmlSnippet() | |
{ | |
// malformed html | |
return @"<!doctype html> | |
<html><head>Hello World!</head> | |
<body> | |
<div data-group='01'> | |
<div> | |
<input name='prename'> | |
<input name='surname'> | |
</section> | |
</div> | |
<div data-group='02'> | |
<input name='projectname'> | |
</div> | |
</body></html>"; | |
} | |
static void Main(string[] args) | |
{ | |
var html = new HtmlDocument(); | |
html.LoadHtml(getHtmlSnippet()); | |
var body = html.DocumentNode.SelectSingleNode("//body"); | |
var groups = html.DocumentNode.SelectNodes("//*[@data-group]"); | |
// swap the two groups: | |
body.ChildNodes.Clear(); | |
groups.Reverse().ToList().ForEach((group) => body.AppendChild(group)); | |
var inputs = html.DocumentNode.SelectNodes("//*[@name]"); // OutOfMemoryException | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment