0 Replies - 12853 Views - Last Post: 23 July 2010 - 06:06 PM Rate Topic: -----

#1 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Encoding issues

Posted 23 July 2010 - 06:06 PM

skyhawk133 I'm sure you've been made aware of this but there's an issue with some of the API calls, sch as when I go to get the sub-forums by forum , some of the forum descriptions, such as C++ & Java, have illegal characters in them, which generates errors when C# tries to parse the XML.

The C++ Programmers has the URL to the main C++ forum, which throws an error in C# because it says the = in the URL is an illegal character. Is there any settings in the API that allow for things like this to be changed? Oh and the C# forum, when my code comes across that forum it comes back as C&#45, which struck me as odd.

For those interested here's how I get the sub-forums by forum (I use this when populating the list of forums, so it's sub-forums are listed with the forum). We got a class called SubForum (It implements the IEquitable interface because the sub-forums are listed 2 times in the XML)

namespace DreamInCodeAPI.Core
    public class SubForum : IEquatable<SubForum>
        public string ForumID { get; set; }
        public string ForumName { get; set; }
        public string ForumURL { get; set; }
        public string ForumDescription { get; set; }
        public Post LastPost { get; set; }

        public bool Equals(SubForum sub)
            //Check whether the compared object is null.
            if (Object.ReferenceEquals(sub, null)) 
                return false;

            //Check whether the compared object references the same data.
            if (Object.ReferenceEquals(this, sub)) 
                return true;

            //Check whether the subforus' properties are equal.
            return ForumName.Equals(sub.ForumName) && ForumID.Equals(sub.ForumID);

        public override int GetHashCode()
            //Get hash code for the ForumName field if it is not null.
            int hashName = (ForumName == null) ? 0 : ForumName.GetHashCode();

            //Get hash code for the ForumID field.
            int hashCode = ForumID.GetHashCode();

            //Calculate the hash code for the SubForum.
            return hashName ^ hashCode;


/// <summary>
/// method to retrieve the sub-forums for the specified forum
/// </summary>
/// <param name="id">the forum id (the XML returned gives in a string format)</param>
/// <returns>generic list of SubForum objects</returns>
public List<SubForum> GetSubForums(string id)
    List<SubForum> list = new List<SubForum>();

        XElement element = XElement.Parse(GetXML(string.Format(URLConstants.FORUM_BY_ID, id))).Element("forum").Element("subforums");
        if (element != null)
            foreach (XElement e in element.Elements("forum"))
                list.Add(new SubForum()
                    ForumID = e.Element("id").Value,
                    ForumName = e.Element("name").Value,
                    ForumURL = e.Element("url").Value,
                    LastPost = LatestPost(e.Element("lastpost"))

    return list.Distinct().ToList();

The value of the UrlConstants.FORUM_BY_ID variable is

public const string FORUM_BY_ID = "http://www.dreamincode.net/forums/xml.php?showforum={0}";

Hope this helps someone ;)

PS: With this code if the forum is is 15, 32 or 28 (C++, Java & PHP) is when you get the massive errors with parsing the XML

Is This A Good Question/Topic? 0
  • +

Page 1 of 1