1
public class XmlResourceReader
2
{
3
private string _fileName = "";
4
5
private System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();
6
public XmlResourceReader(string fileName)
7
{
8
this._fileName = fileName;
9
Initial();
10
}
11
12
public string fileName
13
{
14
get
15
{
16
return this._fileName;
17
}
18
}
19
20
private void Initial()
21
{
22
if (System.IO.File.Exists(this.fileName))
23
{
24
xDoc.Load(this.fileName);
25
}
26
}
27
28
public string GetString(string ID)
29
{
30
ID = ID.Replace("'", "'");
31
string xPath = @"//Localizations/Loc[@_locID='" + ID + "']";
32
System.Xml.XmlNode node = xDoc.SelectSingleNode(xPath);
33
if (node != null)
34
{
35
return node.InnerText;
36
}
37
else
38
{
39
return null;
40
}
41
}
42
43
}
public class XmlResourceReader2
{3
private string _fileName = "";4

5
private System.Xml.XmlDocument xDoc = new System.Xml.XmlDocument();6
public XmlResourceReader(string fileName)7
{8
this._fileName = fileName;9
Initial();10
}11

12
public string fileName13
{14
get15
{16
return this._fileName;17
}18
}19

20
private void Initial()21
{22
if (System.IO.File.Exists(this.fileName))23
{24
xDoc.Load(this.fileName);25
}26
}27

28
public string GetString(string ID)29
{30
ID = ID.Replace("'", "'");31
string xPath = @"//Localizations/Loc[@_locID='" + ID + "']";32
System.Xml.XmlNode node = xDoc.SelectSingleNode(xPath);33
if (node != null)34
{35
return node.InnerText;36
}37
else38
{39
return null;40
}41
}42
43
}Xml resource file:
<?xml version="1.0" encoding="Unicode"?>
<Localizations>
<_locDefinition>
<_locDefault _loc="locNone"/>
<_locTag _loc="locData">Loc</_locTag>
</_locDefinition>
<Loc_locID="ui.fonts.defaultfamily_strings.resx">Tahoma</Loc><Delim><![CDATA[
]]></Delim>
<Loc_locID="ui.fonts.secondfamily_strings.resx">Franklin Gothic Demi</Loc>
</Localizations>

浙公网安备 33010602011771号