What's the easiest way to Parse an XML file with many different levels?

i know this is a long question.. but I'm going crazy here trying to learn one of the many ways to parse an XML document... Alot of the examples I have online are very simple XML documents.. but I have something multi leveled and I would like to get this parsed..

my class code here: http://pastebin.com/VKbWzKHG

<?xml version="1.0" encoding="utf-8"?>

pretty much there will be a lot of pages.. i didn't want to paste the full thing so i tried to cut it out.. but this is the structure:

  --> upper left
      --> parameters
          --> league
          --> season
          --> category
          --> rankorder
      --> info
          --> row 1
              --> team logo
              --> rank
              --> name
              --> stat
          --> row 2 to row 5
  --> upper right, lower left, lower right
end page

How can I successfully parse this nightmare? Everything is a class that I created that was nice and neat.. but trying to put everything back into a class i'm just having so much trouble..

XDocument xdoc;
            List<MLBPage> collection =
                from e in XDocument.Load("PageList.xml").Root.Elements("PageList")

                select new MLBPage
                    ul = new Quadrant  //upper left
                        qp = new QuadrantParameters
                            //league, season, category, rank order here
                        qi = new QuadrantInfo
                            //team logo, rank, name, stat here
        catch (Exception)


You could start mapping the classes/attributes/elements:

[Serializable] //Root
[XmlRoot(ElementName = "InfXml", Namespace="the namespace URI")]
public class InfXml
    [XmlAttribute(AttributeName = "id")] //attribute
    public string Id { get; set; }
    public bool ShouldSerializeId() //Should serialize, only serializes if not null.
        return !string.IsNullOrEmpty(Id); //This is only for optional fields.

    [XmlElement(ElementName = "Identification")] //Non optional group.
    public Identification Identification{ get; set; }

    [XmlElement(ElementName = "Adress")] //Optional group.
    public Adress Adress{ get; set; }
    public bool ShouldSerializeAdress()
        return Adress!= null;

If you have a mapped class-to-Xml, you can use this 2 methods:

const string PrefixXml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";

public static object Deserialize<T>(T obj, string xmlText)
        XmlSerializer deserializer = new XmlSerializer(typeof(T));
        TextReader textReader = new StringReader(xmlText);
        return (T)deserializer.Deserialize(textReader);
    catch (Exception ex)
        //Catch here.
        return null;


public static XmlDocument Serialize<T>(T obj)
    string xmlString = GerarXml.Gerar<T>(obj);
    if (!xmlString.Contains("xml version="))
        xmlString = PrefixXml + xmlString;
    xmlString = xmlString.Replace(Environment.NewLine, string.Empty);
    XmlDocument doc = new XmlDocument();
    return doc;

And if you want to get the XML as a string:

public static string GetXmlText(XmlDocument doc)
    StringWriter stringWriter = new StringWriter();
    XmlTextWriter xmlTextWriter = new XmlTextWriter(stringWriter);


    string ret = stringWriter.ToString();

    ret = ret.Replace(Environment.NewLine, string.Empty);
    if (!ret.Contains("xml version="))
        return PrefixXml + ret;
    return ret;


Need Your Help

Dart: String concatenation error: expected type is 'num'?

compiler-errors dart string-concatenation

In my Dart app I need to have a const string variable defined like so: