Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Update2</strong>: Here is a code example how to get values of attributes using Html Agility Pack:</p> <p><strong><a href="http://htmlagilitypack.codeplex.com/wikipage?title=Examples" rel="nofollow noreferrer">http://htmlagilitypack.codeplex.com/wikipage?title=Examples</a></strong></p> <pre><code> HtmlDocument doc = new HtmlDocument(); doc.Load("file.htm"); foreach(HtmlNode link in doc.DocumentElement.SelectNodes("//a[@href"]) { HtmlAttribute att = link.Attributes["href"]; att.Value = FixLink(att); } doc.Save("file.htm"); </code></pre> <p>You obviously need to adapt this code to your needs -- for example you will not modify the attributes, but will just use <code>att.Value</code> .</p> <hr> <p><strong>Update</strong>: You may also look at this question:</p> <p><strong><a href="https://stackoverflow.com/questions/541953/selecting-attribute-values-with-html-agility-pack">Selecting attribute values with html Agility Pack</a></strong></p> <hr> <p><strong>Your problem is most likely a default namespace problem</strong> -- search for "XPath default namespace c#" and you will find many good solutions (hint: use the overload of <strong><a href="http://msdn.microsoft.com/en-us/library/4bektfx9.aspx" rel="nofollow noreferrer"><code>SelectNodes()</code></a></strong> that has an <strong><a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlnamespacemanager.aspx" rel="nofollow noreferrer"><code>XmlNamespaceManager</code></a></strong> argument).</p> <p><strong>The following code shows what one gets for an attribute in a document in</strong> "no namespace":</p> <pre><code>using System; using System.IO; using System.Xml; public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("&lt;input value='novel' ISBN='1-861001-57-5'&gt;" + "&lt;title&gt;Pride And Prejudice&lt;/title&gt;" + "&lt;/input&gt;"); XmlNode root = doc.DocumentElement; XmlNode value = doc.SelectNodes("//input/@value")[0]; Console.WriteLine("Inner text: " + value.InnerText); Console.WriteLine("InnerXml: " + value.InnerXml); Console.WriteLine("OuterXml: " + value.OuterXml); Console.WriteLine("Value: " + value.Value); } } </code></pre> <p><strong>The result from running this app is</strong>:</p> <pre><code>Inner text: novel InnerXml: novel OuterXml: value="novel" Value: novel </code></pre> <p><strong>Now, for a document that is in a default namespace</strong>:</p> <pre><code>using System; using System.IO; using System.Xml; public class Sample { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("&lt;input xmlns='some:Namespace' value='novel' ISBN='1-861001-57-5'&gt;" + "&lt;title&gt;Pride And Prejudice&lt;/title&gt;" + "&lt;/input&gt;"); XmlNode root = doc.DocumentElement; XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable); nsmgr.AddNamespace("x", "some:Namespace"); XmlNode value = doc.SelectNodes("//x:input/@value", nsmgr)[0]; Console.WriteLine("Inner text: " + value.InnerText); Console.WriteLine("InnerXml: " + value.InnerXml); Console.WriteLine("OuterXml: " + value.OuterXml); Console.WriteLine("Value: " + value.Value); } } </code></pre> <p><strong>Running this app produces again the wanted results</strong>:</p> <pre><code>Inner text: novel InnerXml: novel OuterXml: value="novel" Value: novel </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload