Take the 2-minute tour ×

I've a set of html docs that I need to parse. They are encoded in Latin1Encoded. I'm using HtmlAgiliy pack for "parsing".

I have a Xpath query (with swedish characters) that I can't get to work because of different encodings between the docs and the encoding VS stores the XPath query in??

Xpath query:


The xpath query works fine in the Firefox extension xpath checker.

share|improve this question
How does the data that you want to parse look like? –  Fredrik Mörk May 12 '09 at 7:27
I had a case of "magic", It suddenly started to work, which is both great and irritating.... I read somewhere that VS starts to store in UTF8 first when needed? –  Niels Bosma May 12 '09 at 9:27
The format VS stores your source file should not matter because strings in the C# are always in Unicode at runtime (yoda.arachsys.com/csharp/strings.html). If your input XML document has been loaded correctly then both XPath expression and XML are in Unicode encoding internally. –  0xA3 May 12 '09 at 9:39
add comment

1 Answer

up vote 3 down vote accepted

Could you provide more sample code and some input XML document? From the information given I wrote a little sample program which just works as expected. Does the following work for you?

Sample document:



using System;
using System.Xml.XPath;

class Program
    static void Main(string[] args)
        XPathDocument xpdoc = new XPathDocument(@"sample.xml");
        XPathNavigator nav = xpdoc.CreateNavigator();
        XPathNodeIterator iter = nav.Select("//*[text() = 'Företag']");

        while (iter.MoveNext())



From the sample code given it seems that you are using the Microsoft.Windows.Design.Documents.Trees.DocumentNode class. However, the documentation states that this class is not intended to be used directly. May I ask what you are trying to do?

Update: It might be that you are facing an issue with whitespace normalization (which might be done by your FireFox add-in and not in your code). Have you tried to change your XPath by replacing the test text() = 'Företag' by normalize-space() = 'Företag' (Just to exclude the case that there is additional leading or trailing whitespace)?

share|improve this answer
+1 I was also thinking of "normalize-space()". –  Tomalak May 13 '09 at 6:46
add comment

Your Answer


