Hi all,
Could someone help me? I have programm that reads xml file and displays it in window with StringGrid. I need to replace my code with a function that has xml file as a parameter and returns two-dementional array of strings (instead of StringGrid). You can see my code below.
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
XMLDocument1->Active = false;
if(OpenDialog1->Execute())
XMLDocument1->LoadFromFile(OpenDialog1->FileName); // xml file load to parser
XMLDocument1->Active = true;
int k = 0;
AnsiString S,S1; // here code receiving attributes of xml nodes
for (int i = 1; i < XMLDocument1->ChildNodes->Nodes[1]->ChildNodes->Count + 1; i++)
{
for (int j = 1; j < XMLDocument1->ChildNodes->Nodes[1]->ChildNodes->Nodes[i-1]->ChildNodes->Count + 1; j++)
{
k = k++;
StringGrid1->RowCount++;
StringGrid1->Cells[0][k] = XMLDocument1->ChildNodes->Nodes[1]->ChildNodes->Nodes[i-1]->ChildNodes->Nodes[j-1]->NodeName;
for (int m = 1; m < XMLDocument1->ChildNodes->Nodes[1]->ChildNodes->Nodes[i-1]->ChildNodes->Nodes[j-1]->AttributeNodes->Count + 1; m++)
{
if(!XMLDocument1->ChildNodes->Nodes[1]->ChildNodes->Nodes[i-1]->ChildNodes->Nodes[j-1]->AttributeNodes->Nodes[m-1]->NodeValue.IsNull())
{
S = XMLDocument1->ChildNodes->Nodes[1]->ChildNodes->Nodes[i-1]->ChildNodes->Nodes[j-1]->AttributeNodes->Nodes[m-1]->NodeValue;
int i2 = 1;
int len = S.Length(); S1.Delete(0,len); // here code to catch unwanted simbols
for (int i1 = 1; i1 <= len; i1++)
{
if(S[i1] == '-')
{
i2 = i1; S1 = '-';
break;
}
}
for (i2+1; i2 <= len; i2++)
{
if(S[i2] == '0') S1 = S1 + S[i2];
if(S[i2] == '1') S1 = S1 + S[i2];
if(S[i2] == '2') S1 = S1 + S[i2];
if(S[i2] == '3') S1 = S1 + S[i2];
if(S[i2] == '4') S1 = S1 + S[i2];
if(S[i2] == '5') S1 = S1 + S[i2];
if(S[i2] == '6') S1 = S1 + S[i2];
if(S[i2] == '7') S1 = S1 + S[i2];
if(S[i2] == '8') S1 = S1 + S[i2];
if(S[i2] == '9') S1 = S1 + S[i2];
}
StringGrid1->Cells[m][k] = S1; // filling stringgrid with parameters of xml nodes
S1.Delete(1,i2);
}
else
StringGrid1->Cells[m][k] = "n/a";
}
}
}
XMLDocument1->Active = false;
}
catch(...)
{
ShowMessage("error load XML");
}
}