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
Afficher la suite