[ Microsoft.com ] – XPath Examples

XPath Examples

    XPath Examples
    ………………………………………………………………………………………………………………….
    This topic reviews the syntax examples that appear throughout the XPath Reference. All are based on the Sample XML File
    for XPath Syntax (inventory.xml).  For an example of using an XPath expression in a test file, see “Example of Unions ( | )”,
    at the bottom of this topic.

Continue reading

[ StackOverflow.com ] – how to post data to specific URL using WebClient in C#

how to post data to specific URL using WebClient in C# – Stack Overflow

string URI =http://www.myurl.com/post.php”;
string myParameters =“param1=value1&param2=value2&param3=value3”;

using (WebClient wc =newWebClient())
{
      wc
.Headers[HttpRequestHeader.ContentType]=“application/x-www-form-urlencoded”;
     
stringHtmlResult= wc.UploadString(URI, myParameters);
}

[ StackOverflow.com ] Cannot set some HTTP headers when using System.Net.WebRequest

c# – Cannot set some HTTP headers when using System.Net.WebRequest – Stack Overflow

When I try to add a HTTP header key/value pair on a WebRequest object, I get the following exception:

This header must be modified using the appropriate property

I’ve tried adding new values to the Headers collection by using the Add() method but I still get the same exception… Continue reading

[ StackOverflow ] – Use ListForEach to add element to HashTable

c# – Use ListForEach to add element to HashTable – Stack Overflow

Try this:

valueList.ForEach(x => htable.Add(valueList.FindIndex(y => y == x), x));

Although, there’s really no reason not to use a for here

for(var index =0; index < valueList.Count; index++){
    htable.Add(index, valueList[index]);}

[ StackOverflow ] – Know if an attribute contains a value in HTMLAgilityPack’s C# Node Collection

xml – What is the correct XPath for choosing attributes that contain “foo”? – Stack Overflow

The link above is quite interesting for HTMLAgilityPack C# beginners, helps a lot !

Another thing to note is that while the XPath above will return the correct answer for that particular xml, if you want to guarantee you only get the “a” elements in element “blah”, you should as others have mentioned also use

/bla/a[contains(@prop,'Foo')]

This will search you all “a” elements in your entire xml document, regardless of being nested in a “blah” element

//a[contains(@prop,'Foo')]