0

I would like to sort my xml for which the inffered schema is placed below.

I would like to sort rows based on one column value (alphabetical)

Is it possible to do that in Linq to Xml? Or XSLT is my only option?

Thanks

Kamil

Ok, I removed schema and provide part of file

    <Matrix>
    ...
    <Rows>
      <Row>
        <Visible>1</Visible>
        <Columns>
          <Column>
            <ID>col_f</ID>
            <Value>
            </Value>
          </Column>
          <Column>
            <ID>col_0</ID>
            <Value>r00329</Value>
          </Column>
          <Column>
            <ID>col_1</ID>
            <Value>Gerbera "Ambiance" rosa-creme</Value>
          </Column>
          <Column>
            <ID>col_2</ID>
            <Value>
            </Value>
          </Column>
          <Column>
            <ID>col_dost</ID>
            <Value>Bl... Holland</Value>
          </Column>
          <Column>
            <ID>col_3</ID>
            <Value>0,000</Value>
          </Column>
          <Column>
            <ID>col_5</ID>
            <Value>0,000</Value>
            ...
1
  • 1
    A simple sample of the XML would be way easier to absorbe than that monsterous XSD. Commented Sep 10, 2009 at 11:50

1 Answer 1

1

Sorted rows can be obtained as follows:

// assume rows is a reference to the <Rows> node
var query = from row in rows.Elements( "Row" )
            let sortValue = (
                from c in row.Element("Columns").Elements("Column")
                where c.Element("ID").Value == "col_1"
                select c.Element("Value").Value
            ).FirstOrDefault()
            orderby sortValue
            select row;

This will give you a collection of "Row" elements sorted by the "col_1" column's "Value".

Adjust as needed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.