Reputation: 41909
I've used the Html Agility Pack to read/parse HTML elements' values for Coded UI Tests (automated UI testing).
Example:
<html>
<body>
<div id='a'>
<input name="inp" value="some input"> </input>
</div>
</body>
</html>
Grab div with id='a'.
HtmlAgilityPack.HtmlNode divNode =
doc.DocumentNode.SelectSingleNode("//div[@id='a']//input[@name='inp']");
Console.WriteLine(divNode.Attributes["value"].Value); // prints out "some input"
I could modify the div's "value" in memory by doing divNode.SetAttribute("value", "new value");
.
However, what if I want to actually apply/write this updated value to the web page?
Can I do this with the Html Agility Pack?
Upvotes: 0
Views: 538
Reputation: 138925
The process for modifying a document is something like this:
HtmlDocument doc = new HtmlDocument();
doc.Load("somefile.html");
// modify doc in memory
doc.Save("somefile.html");
Upvotes: 2