Another open source rant
-
wizardzz wrote:
What are you using it for? If you need help, I might be able to help.
Well, that's cool! Nothing complicated, just replacing the img src tags with a local file (this is test code, I will shortly replace the hardcoded paths, etc.):
protected void SaveOffline(object sender, EventArgs args)
{
HtmlDocument doc = View.Browser.Document;
HtmlAgilityPack.HtmlDocument adoc = new HtmlAgilityPack.HtmlDocument();
adoc.LoadHtml(doc.Body.OuterHtml);
int n=0;foreach (HtmlAgilityPack.HtmlNode img in adoc.DocumentNode.Descendants("img")) { img.Attributes\["src"\].IfNotNull(a => { string src = a.Value; string location = DownloadImage(src, "c:\\\\temp\\\\testfolder\\\\" + n.ToString() + "." + src.RightOfRightmostOf('.')); ++n; if (location != String.Empty) { a.Value = "file:///" + location; } }); } adoc.Save("c:\\\\temp\\\\test2.html");
}
Which works great - basically, I haven't needed it for anything else, so it's probably overkill. Poking around the code to verify that if the attribute is not found it returns null rather than throwing an exception), I found this:
public HtmlAttribute this[string name]
{
get
{
if (name == null)
{
throw new ArgumentNullException("name");
}
HtmlAttribute value;
return Hashitems.TryGetValue(name.ToLower(), out value) ? value : null;
}
set { Append(value); }
}The setter is very strange. I would expect a syntax like:
node["someAttribute"]=new HtmlAttribute("foobar");
to replace the attribute if it exists or create a new one if it doesn't. What puzzles me is the Append call, which:Hashitems\[newAttribute.Name\] = newAttribute; newAttribute.\_ownernode = \_ownernode; items.Add(newAttribute);
adds the new attribute to the items collection, but replaces it in the Hashitems dictionary. This seems wrong. Thoughts? Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My BlogI don't get an exception from trying to iterate the null set. Test.html contains no "img" nodes:
HtmlAgilityPack.HtmlDocument hd = new HtmlAgilityPack.HtmlDocument();
hd.LoadHtml("c:\test\test.html");try
{
//code executes
foreach (HtmlAgilityPack.HtmlNode img in hd.DocumentNode.Descendants("img"))
{
//never executes
Console.WriteLine(img.ToString());
}
//code executes
}
catch (Exception ex)
{
//never executes
Console.WriteLine(ex.Message);
}As far as the Dictionary, that is adding if it doesn't exist, but replacing it if it does. It's an add/replace, but I don't think will be a replace ever as the attributes would be unique. Example:
Dictionary<string, int> dic = new Dictionary<string, int>();
dic["first"] = 1;
Console.WriteLine(dic["first"].ToString());Output: 1
-
This time, my sights are on HtmlAgilityPack[^]. Besides the fact that there is no documentation and the one example provided has an absurd quote-placement error, so obviously the code was never tested, there's this:
/// /// Selects a list of nodes matching the expression.
///
/// The XPath expression.
/// An containing a collection of nodes matching the query, or null if no node matched the XPath expression.
public HtmlNodeCollection SelectNodes(string xpath)What? You return a null if no matches are found??? Which of course would blow up their "example" if no "href" tags exist:
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{Why is it that the quality of what "we" as supposed professionals produce is so obviously bad? On a positive note, someone did put together a HAPExplorer (albeit in WPF, why???) that at least provides some working examples, and lo-and-behold, it does compile (after I nuked the test project with an NUnit dependency), but on a bad note, the latest source download complained about a missing .cs file, so the test stuff doesn't build anyways. :sigh: Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My BlogOpen source is not equal to quality, open source is equal to I put the best I can in my spare time to fix a problem I had and I put it in the internet so anyone having this problem can see and/or use my solution. As some open source project maintainers say (although I respectfully disagree on some of the means they make this clear), if you don't like the state of the project, improve it.
CEO at: - Rafaga Systems - Para Facturas - Modern Components for the moment...
-
This time, my sights are on HtmlAgilityPack[^]. Besides the fact that there is no documentation and the one example provided has an absurd quote-placement error, so obviously the code was never tested, there's this:
/// /// Selects a list of nodes matching the expression.
///
/// The XPath expression.
/// An containing a collection of nodes matching the query, or null if no node matched the XPath expression.
public HtmlNodeCollection SelectNodes(string xpath)What? You return a null if no matches are found??? Which of course would blow up their "example" if no "href" tags exist:
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{Why is it that the quality of what "we" as supposed professionals produce is so obviously bad? On a positive note, someone did put together a HAPExplorer (albeit in WPF, why???) that at least provides some working examples, and lo-and-behold, it does compile (after I nuked the test project with an NUnit dependency), but on a bad note, the latest source download complained about a missing .cs file, so the test stuff doesn't build anyways. :sigh: Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My BlogAs it is open source, why don't you fix it? Then, instead of complaining about all open based on one example, you could actually be part of the solution. Just a thought...
-
This time, my sights are on HtmlAgilityPack[^]. Besides the fact that there is no documentation and the one example provided has an absurd quote-placement error, so obviously the code was never tested, there's this:
/// /// Selects a list of nodes matching the expression.
///
/// The XPath expression.
/// An containing a collection of nodes matching the query, or null if no node matched the XPath expression.
public HtmlNodeCollection SelectNodes(string xpath)What? You return a null if no matches are found??? Which of course would blow up their "example" if no "href" tags exist:
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{Why is it that the quality of what "we" as supposed professionals produce is so obviously bad? On a positive note, someone did put together a HAPExplorer (albeit in WPF, why???) that at least provides some working examples, and lo-and-behold, it does compile (after I nuked the test project with an NUnit dependency), but on a bad note, the latest source download complained about a missing .cs file, so the test stuff doesn't build anyways. :sigh: Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My BlogMarc Clifton wrote:
Why is it that the quality of what "we" as supposed professionals produce is so obviously bad?
Documentation & example code isn't generally the fun part to people who work on open source projects, which is why that part of nearly every project is so dismal. The source code is also sometimes an audition.
We can program with only 1's, but if all you've got are zeros, you've got nothing.
-
I don't get an exception from trying to iterate the null set. Test.html contains no "img" nodes:
HtmlAgilityPack.HtmlDocument hd = new HtmlAgilityPack.HtmlDocument();
hd.LoadHtml("c:\test\test.html");try
{
//code executes
foreach (HtmlAgilityPack.HtmlNode img in hd.DocumentNode.Descendants("img"))
{
//never executes
Console.WriteLine(img.ToString());
}
//code executes
}
catch (Exception ex)
{
//never executes
Console.WriteLine(ex.Message);
}As far as the Dictionary, that is adding if it doesn't exist, but replacing it if it does. It's an add/replace, but I don't think will be a replace ever as the attributes would be unique. Example:
Dictionary<string, int> dic = new Dictionary<string, int>();
dic["first"] = 1;
Console.WriteLine(dic["first"].ToString());Output: 1
wizardzz wrote:
I don't get an exception from trying to iterate the null set. Test.html contains no "img" nodes:
The issue isn't with Descendents, it's with SelectNodes, which return null instead of an empty collection. Perhaps that is the desired behavior for a "Select" function.
wizardzz wrote:
that is adding if it doesn't exist, but replacing it if it does.
Right, but then what's this line doing:
items.Add(newAttribute);
in the Append function? Why is the has replacing while the items collection is adding, leading to confusion about the use of the hash and the name "Append." I'm a bit confused by your answers, because they seem to miss the mark with regards to my earlier posts. Perhaps they were not clear enough? Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My Blog -
wizardzz wrote:
I don't get an exception from trying to iterate the null set. Test.html contains no "img" nodes:
The issue isn't with Descendents, it's with SelectNodes, which return null instead of an empty collection. Perhaps that is the desired behavior for a "Select" function.
wizardzz wrote:
that is adding if it doesn't exist, but replacing it if it does.
Right, but then what's this line doing:
items.Add(newAttribute);
in the Append function? Why is the has replacing while the items collection is adding, leading to confusion about the use of the hash and the name "Append." I'm a bit confused by your answers, because they seem to miss the mark with regards to my earlier posts. Perhaps they were not clear enough? Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My BlogI'll look at the first one later, I thought you were talking about Descendants too. Regarding the append/replace: Yes. It's goofy to do it the way they did, but will it ever do a replace? Won't dic[newwattname] = newattvalue; always be an append to the dictionary? Sure they aren't using .Add to the dictionary, that's the goofy part, I get that. Some people are accustomed to using the Append/Replace way to prevent the attempt to add non unique keys to the dictionary. The other goofiness is using an Add only to the list after just doing an add/replace, yes, it's goofy, it's inconsistent. I would never do it this way, they (dictionary & list) could get out of whack and it is ugly and inconsistent, but as far as using the code they wrote; won't attributes always be unique anyways? I think it's an example of ugly code that works only in the situation they wrote it for.
-
I see what your both saying, but many of these "build it yourself" projects also have the package files in Linux distro repositories, so I'm sure they could make a Windows binary too.
.-. |o,o| ,| \_\\=/\_ .-""-. ||/\_/\_\\\_\\ /\[\] \_ \_\\ |\_/|(\_)|\\\\ \_|\_o\_LII|\_ \\.\_./// / | ==== | \\ |\\\_/|"\` |\_| ==== |\_| |\_|\_| ||" || || |-|-| ||LI o || |\_|\_| ||'----'|| /\_/ \\\_\\ /\_\_| |\_\_\\
-
Yes, yes, no doubt "they" can do all sorts of things for you. Now, perhaps you would like to contribute by making the Windows binary.
Quote:
No thanks, I likely don't use the same toolchain or compilers as you
.-. |o,o| ,| \_\\=/\_ .-""-. ||/\_/\_\\\_\\ /\[\] \_ \_\\ |\_/|(\_)|\\\\ \_|\_o\_LII|\_ \\.\_./// / | ==== | \\ |\\\_/|"\` |\_| ==== |\_| |\_|\_| ||" || || |-|-| ||LI o || |\_|\_| ||'----'|| /\_/ \\\_\\ /\_\_| |\_\_\\
-
Web development is saturated with individuals whose skill-set is extremely poor and who lie about their ability with no shame. It really grinds my gears. I set about a guy recently in the LinkedIn forums who was asking if anyone had any guides so he could quickly learn JavaScript though on his profile he said he was an expert!
JimBob SquarePants ******************************************************************* "He took everything personally, including our royalties!" David St.Hubbins, Spinal Tap about Ian Faith, their ex-manager *******************************************************************
LinkedIn has a lot of weird quirks. I had one person verify my expertise with SharePoint. I didn't ask for it, I don't even follow any SharePoint forums. I'm guessing he got a look at my resume which included working for the SharePoint group. I will say I am more familiar with the back-end SQL portion of that app (in 2005) than most people, but that doesn't put me anywhere close to being a SharePoint developer or expert.
-
This time, my sights are on HtmlAgilityPack[^]. Besides the fact that there is no documentation and the one example provided has an absurd quote-placement error, so obviously the code was never tested, there's this:
/// /// Selects a list of nodes matching the expression.
///
/// The XPath expression.
/// An containing a collection of nodes matching the query, or null if no node matched the XPath expression.
public HtmlNodeCollection SelectNodes(string xpath)What? You return a null if no matches are found??? Which of course would blow up their "example" if no "href" tags exist:
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{Why is it that the quality of what "we" as supposed professionals produce is so obviously bad? On a positive note, someone did put together a HAPExplorer (albeit in WPF, why???) that at least provides some working examples, and lo-and-behold, it does compile (after I nuked the test project with an NUnit dependency), but on a bad note, the latest source download complained about a missing .cs file, so the test stuff doesn't build anyways. :sigh: Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My Blog -
This time, my sights are on HtmlAgilityPack[^]. Besides the fact that there is no documentation and the one example provided has an absurd quote-placement error, so obviously the code was never tested, there's this:
/// /// Selects a list of nodes matching the expression.
///
/// The XPath expression.
/// An containing a collection of nodes matching the query, or null if no node matched the XPath expression.
public HtmlNodeCollection SelectNodes(string xpath)What? You return a null if no matches are found??? Which of course would blow up their "example" if no "href" tags exist:
HtmlDocument doc = new HtmlDocument();
doc.Load("file.htm");
foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"])
{Why is it that the quality of what "we" as supposed professionals produce is so obviously bad? On a positive note, someone did put together a HAPExplorer (albeit in WPF, why???) that at least provides some working examples, and lo-and-behold, it does compile (after I nuked the test project with an NUnit dependency), but on a bad note, the latest source download complained about a missing .cs file, so the test stuff doesn't build anyways. :sigh: Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My BlogIt is software development in general. There are "programmers" everywhere that make bad software. Code of the "quality" you describe is absolutely typical of virtually all in-house-developed/custom line-of-business software. Without those crufty old VB6 or FoxPro or MSAccess the whole economy would collapse. Comforting isn't it? That is exactly why that given the choice I will ALWAYS choose an open source solution over a closed one. I can examine the inner workings, interact with developers, etc. If I went with closed software my options are limited, and since I KNOW most closed software (most software in general) has some degree of garbage in it then I cannot trust it when my support options are limited to a chain of call centre drones. Can't put down software development alone though--a lot of people who worked in a fast food place can't bring themselves to eat fast food any more, because they know the way it is made, not to mention the character of the people making it for you.
-
wizardzz wrote:
I don't get an exception from trying to iterate the null set. Test.html contains no "img" nodes:
The issue isn't with Descendents, it's with SelectNodes, which return null instead of an empty collection. Perhaps that is the desired behavior for a "Select" function.
wizardzz wrote:
that is adding if it doesn't exist, but replacing it if it does.
Right, but then what's this line doing:
items.Add(newAttribute);
in the Append function? Why is the has replacing while the items collection is adding, leading to confusion about the use of the hash and the name "Append." I'm a bit confused by your answers, because they seem to miss the mark with regards to my earlier posts. Perhaps they were not clear enough? Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My BlogSorry for getting back to you so after the fact. Yes it returns null, and it is complete shit. We have a class that handles calls to the agility pack for us, so we don't make changes to the open source code while being able to improve our interacts. Make a wrapper class. I think there are only 2 lines of code in the agility pack that we've changed, one is to be able to get csv, xml files.
-
Sorry for getting back to you so after the fact. Yes it returns null, and it is complete shit. We have a class that handles calls to the agility pack for us, so we don't make changes to the open source code while being able to improve our interacts. Make a wrapper class. I think there are only 2 lines of code in the agility pack that we've changed, one is to be able to get csv, xml files.
wizardzz wrote:
Sorry for getting back to you so after the fact.
No worries. Thanks for the reply. Marc
Testers Wanted!
Latest Article: User Authentication on Ruby on Rails - the definitive how to
My Blog