Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
Dear sir,

the below algorithm  is working fine. for the XML File as below.

but according to requirement no use dataset.

so i have created the above algorithm as follows but looping not happening.because index like

row[i][0] not  there.

<?xml version="1.0"?>

-<DocumentElement>

-<test>

<c0>manas</c0>

<c1>100</c1>

<c2>20</c2>

<c3>33</c3>

<c4>54</c4>

 <c5>65</c5>

<c6>78</c6>

</test>

 -<test>

<c0>manasi</c0>

<c1>101</c1>

<c2>25</c2>

 <c3>76</c3>

<c4>90</c4>

<c5>12</c5>

<c6>74</c6>

</test>

 -<test>

<c0>mani</c0>

<c1>115</c1>

<c2>29</c2>

<c3>56</c3>

<c4>11</c4>

<c5>95</c5>

<c6>78</c6>

</test>

 </DocumentElement>

 static void GetXmlValue(int NoOfColumn)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(@"D:\Prod.xml");

            XmlNode nodeCol = xmldoc.DocumentElement.FirstChild;
            XmlNode nodeRow = xmldoc.DocumentElement;
            XmlNodeList lstRows = nodeRow.ChildNodes;
            XmlNodeList lstColumns = nodeCol.ChildNodes;

            for (int i = 0; i < lstRows.Count; i++)
            {
                string names = lstColumns[i].InnerText.ToString();
                if (i > 0)  Response.Write("<br/>");
                string lines = names + " ";
                for (int j = 1; j < lstColumns.Count; j++) //Check with no of columns
                {
                    lines += lstColumns[j].InnerText.ToString() + " ";
                    if (j % NoOfColumn == 0)//When it is equla with your no of columns upto last stage
                    {
                       Response.Write("<br/>");
                        lines = names + " ";
                    }
                    if (j == lstColumns.Count - 1 && j % NoOfColumn != 0) //Check at last column
                    {
                       Response.Write(lines + "<br/>");
                    }
                }
            }


        }
now the output is like:

manas 100 20 33 54

manas 65    78  ..   ..

correct for first row

100   100   20  33  54

100    65     78  ...   ...

20      100   20  33  54

20        65     78  ...   ...






Aim is to


For first Node Test:

manas
100
20
33
manas
54
65
78
For Second Node Test:

manasi
101
25
76
manasi
90
12
74
For Third Node Test:

mani
115
29
56
mani
11
95
78
Sir,

Aim is to split multiple number of columns .

Actually 7 columns values for First node Test like manas 100 20 33 54 65 78

My requirement is to display first column(manas) with 3 other row, again it will create a break and write like first column(manas) with next 3 columns.

Then same type it will create for second Node Test.

Then same type it will create for Third Node Test.

thanks in adv.
Posted
Comments
_Asif_ 5-Jul-13 5:39am    
You can use XPath or XQuery to solve these kind of problems. It is very handy and powerful

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900