Kimossab

Load XML

Dec 18th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.78 KB | None | 0 0
  1. void LoadXML(String ^link)
  2. {
  3.     Lista<XMLObject> *LLS = new Lista<XMLObject>();
  4.     XmlTextReader ^reader = gcnew XmlTextReader(link);
  5.                
  6.     String ^SEl = gcnew String("");
  7.     int cont = 0;
  8.     XMLObject *Obj = NULL;
  9.     string valor = "";
  10.     string campo = "";
  11.     while(reader->Read())
  12.     {
  13.         switch(reader->NodeType)
  14.         {
  15.             case XmlNodeType::Element: // The node is an element
  16.                 if((reader->Value!="" && cont<3) || cont < 3)
  17.                     cont++;
  18.  
  19.                 campo = CoisasUteis::ConverterStringTostring(reader->Name);
  20.                 if(cont == 2)  
  21.                     Obj = new XMLObject(campo);
  22.                 SEl += "<"+cont+" " + reader->Name+">";
  23.                 while(reader->MoveToNextAttribute()) // Read the attributes.
  24.                     SEl += reader->Value;
  25.  
  26.                 valor = "";
  27.                 break;
  28.             case XmlNodeType::Text: //Display the text in each element.
  29.                 SEl += reader->Value;
  30.                 valor = CoisasUteis::ConverterStringTostring(reader->Value);
  31.                 if(Obj) Obj->Add(new XMLTxtVal(campo, valor));
  32.                     break;
  33.             case XmlNodeType::EndElement: //Display the end of the element.
  34.                 SEl += "</"+cont + " " + reader->Name+">";
  35.                 SEl = "";
  36.                 cont--;
  37.                 if(cont == 1)
  38.                     LLS->AddEnd(Obj);
  39.                 valor = "";
  40.                 break;
  41.         }
  42.     }
  43.     reader->Close();
  44.    
  45.     Lista<XMLTxtVal> *lp;
  46.     int n;
  47.     for(int i = 0; i < LLS->NElem(); i++)
  48.     {
  49.         lp = (*LLS)[i]->GetCampos();
  50.         for(int j = 0; j < lp->NElem(); j++)
  51.         {
  52.             if((*lp)[j]->GetCampo() != "categoria")
  53.                 continue;
  54.             for(n=0; n<LC.NElem(); n++)
  55.             {
  56.                 if((*lp)[j]->GetValor() != LC.GetInfo(n)->GetNomeCat())
  57.                     continue;
  58.                 produto *x = new produto((*LLS)[i]);
  59.                 LC[n]->GetLP()->AddEnd(x);
  60.                 break;
  61.             }
  62.             if(n == LC.NElem())
  63.             {
  64.                 categoria *c = new categoria((*LLS)[i]);
  65.                 produto *p= new produto((*LLS)[i]);
  66.                 LC.AddEnd(c);
  67.                 LC[n]->GetLP()->AddEnd(p);
  68.             }
  69.             break;
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment