none
Xml file encoding="utf-8" with arabic text that looks like this format "%d8%a7%d9%84%d8%ad..."

    Question

  • I have xml file with encoding="UTF-8" at the beginning

    and inside it I have the following:

    <item id="item1" href="%d8%a7%d9%84%d8%ad%d9%84%d9%88%d9%8a%d8%a7%d8%aa%20%d8%a7%d9%84%d8%b3%d9%87%d9%84%d8%a9%20%d8%a7%d9%84%d8%aa%d8%ad%d8%b6%d9%8a%d8%b1.html"/>

    Value of href refers to an html file. This file has filename in Arabic and it appears as mentioned above in the xml file.

    What encoding do I use in my C# code to get the Arabic value of this string

    %d8%a7%d9%84%d8%ad%d9%84%d9%88%d9%8a%d8%a7%d8%aa%20%d8%a7%d9%84%d8%b3%d9%87%d9%84%d8%a9%20%d8%a7%d9%84%d8%aa%d8%ad%d8%b6%d9%8a%d8%b1

    ?

    Tuesday, November 20, 2012 2:15 PM

Answers

  • I don't think the file encoding of the XML declaration matters for that "href" attribute value, that more looks like the percentage encoding found in URIs. So try whether

      System.Uri.UnescapeDataString(XElement.Load("file.xml").Descendants("item").First(el => (string)el.Attribute("id") == "item1").Attribute("href").Value)

    gives you the value you expect. So basically the method of System.Uri needs to be applied to the attribute value. And I used LINQ to XML to read out that attribute value.


    MVP Data Platform Development My blog

    • Proposed as answer by Martin Honnen Tuesday, November 20, 2012 4:32 PM
    • Marked as answer by Mahagh Wednesday, November 21, 2012 7:22 AM
    Tuesday, November 20, 2012 2:46 PM