Skip to content

Instantly share code, notes, and snippets.

/HAP43229.cs Secret

Created August 26, 2015 10:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/a09a66b9e2138af180ab to your computer and use it in GitHub Desktop.
Save anonymous/a09a66b9e2138af180ab to your computer and use it in GitHub Desktop.
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