[C#] INI -> XML - Code de gruick ou non ?

scoubidou944 Messages postés 714 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 19 janvier 2017 - 26 avril 2005 à 00:39
scoubidou944 Messages postés 714 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 19 janvier 2017 - 26 avril 2005 à 17:57
voici la structure XML à partir du fichier INI :







3













3


5


7









2



4



6













et donc voilà le code qui marche. Maintenant, est ce la solution la
plus propre, rapide, efficace, portable, utilisable ou bonne pour la
poubelle ?



abstract public class glcConfig

{

abstract public bool Init (string _szFilename);

abstract public void AddNewSection (string _szSectionName, int _iOffset, int _iMax);

abstract public void AddNewSectionItem (string _szSectionName, string _szItemName, string []_aszItemValue, int _iOffset, int _iMax);

};



public class glcXMLConfig : glcConfig

{

public glcXMLConfig ()

{

}



override public void AddNewSection (
string
_szSectionName, int _iOffset, int _iMax)

{

#if DEBUG

Console.WriteLine ("");

Console.WriteLine ("[{0}] // [{1}/{2}[", _szSectionName, _iOffset, _iMax);

#else

#endif

}



override public void AddNewSectionItem (
string
_szSectionName,
string
_szItemName,
string
[]_aszItemValue, int _iOffset, int _iMax)

{

#if DEBUG


string
szTmp =
string
.Concat (_aszItemValue);



Console.WriteLine ("{0} = {1} // [{2}/{3}[", _szItemName.PadRight (16, ' '), szTmp, _iOffset, _iMax);

#else

#endif

}



override public bool Init (
string
_szFilename)

{

int iAttributesCounter;

int iChildsCounter;

int iChildAttributesCounter;

int iSubValuesCounter;

XmlAttribute oAttribute, oChildAttribute;

string szSectionName = String.Empty;



XmlDocument oXmlDoc = new XmlDocument();

oXmlDoc.Load(_szFilename);



XmlNodeList oSectionList = oXmlDoc.GetElementsByTagName ("section");

for (int i = 0; i < oSectionList.Count; i++)

{

// Found section

XmlNode oCurrentSection = oSectionList[i];



// Browse attributes

for (iAttributesCounter = 0; iAttributesCounter < oCurrentSection.Attributes.Count; iAttributesCounter++)

{


oAttribute =
oCurrentSection.Attributes [iAttributesCounter];



if (oAttribute.Name == "name")

{


szSectionName
= oAttribute.Value; // Save section for item use

this.AddNewSection (szSectionName, i, oSectionList.Count);

}

else

{

// Other attributes

}

}



//

// Browse childs item name

//

for (iChildsCounter = 0; iChildsCounter < oCurrentSection.ChildNodes.Count; iChildsCounter++)

{

XmlNode oChildItem = oCurrentSection.ChildNodes[iChildsCounter];



for (iChildAttributesCounter = 0; iChildAttributesCounter < oChildItem.Attributes.Count; iChildAttributesCounter++)

{



oChildAttribute = oChildItem.Attributes [iChildAttributesCounter];



if (oChildAttribute.Name == "key")

{



string []aszItemValue = new string [oChildItem.ChildNodes.Count];





// Browse all sub values for key



for (iSubValuesCounter = 0; iSubValuesCounter < oChildItem.ChildNodes.Count; iSubValuesCounter++)



{



XmlNode oItemValue = oChildItem.ChildNodes[iSubValuesCounter];



aszItemValue[iSubValuesCounter] =
oItemValue.InnerText;



}





this.AddNewSectionItem (szSectionName, oChildAttribute.Value, aszItemValue, iChildAttributesCounter, oChildItem.Attributes.Count);

}

else

{



// Other attributes

}

}

}

}

return true;

}

};



----------------------------
C++ forever
C# amateur

2 réponses

sebmafate Messages postés 4936 Date d'inscription lundi 17 février 2003 Statut Membre Dernière intervention 14 février 2014 37
26 avril 2005 à 15:48
Je pense que le plus propre est d'utiliser la Sérialisation --> Tu vas gagner un temps fou en développement...
Pour avoir une idée, regarde ma classe : http://www.csharpfr.com/code.aspx?ID=26172

(c'est pas une pub... juste un axe de recherche)

Sébastien FERRAND

Blog :
http://blogs.developpeur.org/sebmafate</FO< body>
0
scoubidou944 Messages postés 714 Date d'inscription mardi 22 avril 2003 Statut Membre Dernière intervention 19 janvier 2017
26 avril 2005 à 17:57
Je download, je teste et je te dis ;p

Le pb avec la serialisation de mer... C lorsque tu as un objet qui derive de hastable...


Genre :

une classe dérivant de CollectionBase

et chaque element contient une classe qui dérive d'une hastable.

Et la la sérialisation part dans les choux :(


----------------------------
C++ forever
C# amateur
0
Rejoignez-nous