Node Selecting | hidden input with no value

Oct 1, 2009 at 10:54 AM

Dear friends

Congratulations for such a powerful tool.

I am although experiencing some problems in the selection of some nodes:

<body id="ctl00_body">
<form name="aspnetForm" method="post" action="Accessodati.aspx?ReturnUrl=%2fIt%2fWebServerDataStore%2fMGP_Prezzi%2f20090903MGPPrezzi.xml" onsubmit="javascript:return WebForm_OnSubmit();" id="aspnetForm">
<div>
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />
<input type="hidden" name="__LASTFOCUS" id="__LASTFOCUS" value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTIwNTEyNDQzNzQPZBYCZg9kFgICAw9kFgICAQ9kFgICHQ9kFgICAQ8PFgIeDU9uQ2xpZW50Q2xpY2sFJmphdmFzY3JpcHQ6d2luZG93Lm9wZW4oJz9zdGFtcGE9dHJ1ZScpZGQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgUFDGN0bDAwJEltYWdlMQUSY3RsMDAkSW1hZ2VCdXR0b24xBSBjdGwwMCRDb250ZW50UGxhY2VIb2xkZXIxJHN0YW1wYQUkY3RsMDAkQ29udGVudFBsYWNlSG9sZGVyMSRDQkFjY2V0dG8xBSRjdGwwMCRDb250ZW50UGxhY2VIb2xkZXIxJENCQWNjZXR0bzJbvVIW8PU1YVhSYF9pMb+ito8SsQ==" />
</div>

<script type="text/javascript">
<!--

This is a part of the HTML I am trying to parse. I need to grab all the hidden input fields.

But, when calling:

                    foreach (HtmlNode hidden_input in htmlDoc.DocumentNode.SelectNodes("//input[@type='hidden']"))
                    {

                        // Adding an attribute to this node so that it will be easily found in the XML
                        PostRequestContents.Append(hidden_input.Attributes["id"].Value);
                        PostRequestContents.Append("=");
                        PostRequestContents.Append(hidden_input.Attributes["value"].Value);
                        PostRequestContents.Append("&");
                    }

It does not return the inputs whose attribute "value" is empty. This is an unexpected behaviour, I guess.

The parsed HTML has no errors. (ParseErrors.count = 0)

What can I do to fix it?

 

Developer
Oct 3, 2009 at 3:31 AM

Curious, the nodes are there and they are parsed.  I tried your code snippet above and got all 4 hidden inputs returned. I'm running the new 1.4.0 beta. There's gotta be something else later in the HTML that may be messing it up. Could you send me the entire file?

Also you could try the LINQ way and use this  (available in 1.4.0 beta 1)

var nodes = _html.DocumentNode.Descendants("input")
                 .Where(x => x.Attributes.Contains("type") && 
                        x.Attributes["type"].Value.ToLower().Contains("hidden"));