0

I have an XML file which I saved in notepad:

<Layouts>
<BinCode>11111</BinCode>
<BinCode>11111</BinCode>
<BinCode>11112</BinCode>
<BinCode>11121</BinCode>
<BinCode>11111</BinCode>
<BinCode>11211</BinCode>
</Layouts>

I want to Convert this XML file to array then rotate the array to -90 Degree.

Alice Tay
  • 11
  • 4

1 Answers1

0

Please note that the conversion back to XML and chosen data types are just illustrative.

I've just put an algorithm pointer for you to get you started.

Basically, what we do is we create a main array which the length of is the number of digits which is 5, each of those arrays will contain an array of 6 digits.

We're going to populate them from the back, so we'll reverse the strings from the bottom up.

XmlDocument xml = new XmlDocument();
xml.LoadXml(@"
            <Layouts>
            <BinCode>11111</BinCode>
            <BinCode>11111</BinCode>
            <BinCode>11112</BinCode>
            <BinCode>11121</BinCode>
            <BinCode>11111</BinCode>
            <BinCode>11211</BinCode>
            </Layouts>
        ");


        var binCodes = xml.DocumentElement.ChildNodes;
        int digitsInMatrix = binCodes[0].InnerText.Length;
        int[][] ints = new int[digitsInMatrix][];

        for (int d = binCodes.Count - 1; d >= 0; d--)
        {
            for (int i = digitsInMatrix - 1; i >= 0; i--)
            {
                if (ints[i] == null)
                    ints[i] = new int[binCodes.Count];

                char item = binCodes[d].InnerText[i];
                ints[i][d] = int.Parse(item.ToString());
            }
        }

        string updatedXML = string.Format("<Layouts>{0}</Layouts>", 
            string.Join("", 
                ints.Select(x => 
                    string.Format("<BinCode>{0}</BinCode>", string.Join("", x)))));
Adrian
  • 8,271
  • 2
  • 26
  • 43
  • What i want is to convert from: 11111 11111 11112 11121 11111 11211 to 112111 111211 111112 111111 111111 – Alice Tay Dec 16 '21 at 12:00
  • That's cool... it isn't something you said in your question though. I'm not going to be posting answers to your problems so you can change the scope of the question each time. Update your question with all the details. Input/Output what you've tried and what you expect. – Adrian Dec 16 '21 at 12:25