[Solved] LINQ multiple columns


The idea was to just select X nodes out of a pool of Y and the example here is simplified to show you the problem. In general it is like that I have a multi level xml that I needed to flat out to only have one sublevel (aka root + level1) but from the source I only need to have certain elements that are of interest to me.

Anyway the issiue is solved cos I done it with foreach cos I found out that if you have an shema specified in the xml but not accessable LINQ dosent whant to work anyway.

the solution was like this:

  1. I made a function:

    public System.Xml.XmlElement GetSubElement(XmlElement Parent, string element)
    {
     System.Xml.XmlElement ret = null;
     if (Parent == null)
      return ret;
    
     XmlNodeList ContentNodes = Parent.GetElementsByTagName(element);
     if (ContentNodes.Count > 0)
     {
      XmlNode node = ContentNodes.Item(0);
      ret = (XmlElement)node;
     }
    
     return ret;
    }
    
  2. I made a foreach loop on the area that was repeating

  3. I got the elements that where out of the repeating context with the above function.

Anyway that solved it for me.

Edit:
Don’t know how to get this code to appear properly cos Ctrl+K dosent seem to do it

solved LINQ multiple columns