Problème lecture fichier XML
Bonjour,
j'ai un petit problème dans la lecture d'un fichier XML. Voici le fichier XML :
Code:
1 2 3 4 5 6 7
| <?xml version="1.0" encoding="utf-8" ?>
<configuration>
<client name="idClient" value="14"/>
<serveur name="ipServeur" value ="169.254.221.190"/>
<port name="portServeur" value="8001"/>
</configuration> |
Et la classe qui lit le fichier XML et qui me retourne la valeur que je souhaite :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| public class ConfigManager
{
private XmlTextReader txtReader = null;
public ConfigManager(String _fileName)
{
try
{
FileStream fic = null;
String appPath = Path.GetFullPath(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
String fileName = appPath +_fileName;
fic = new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
txtReader = new XmlTextReader(fic);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
}
public String getValue(String identification, String key)
{
try
{
while (txtReader.Read())
{
XmlNodeType nType = txtReader.NodeType;
if (nType == XmlNodeType.Element)
{
if (txtReader.Name.Equals(identification) && txtReader.GetAttribute("name").Equals(key))
{
String strValue = txtReader.GetAttribute("value");
return strValue;
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Exception : " + ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
}
return null;
}
} |
Mon fichier XML se trouve dans un Folder que j'ai créé dans mon projet. Le folder s'appelle "XML". Dedans il y ma classe de lecture de fichier XML et le fichier XML. Lorsque j'appelle ma fonction de recherche ainsi :
Code:
1 2 3 4
| ConfigManager config = new ConfigManager("XML\\ApplicationConfiguration.xml");
String adresseServeur = config.getValue("serveur", "ipServeur");
String portServeur = config.getValue("port", "portServeur"); |
Il me lance une exception du type :
Citation:
Could not find a part of the path 'Program Files\GAP.install\GAP.exeXML\ApplicationConfiguration.xml'
Pourriez-vous m'aider ?
Merci d'avance,
Julien