c# xml file access [closed]
I have two xml files, one of them is dev.xml which has this code
<mapping>
<character>अ</character>
<itrans>a</itrans>
</mapping>
the second file is guj.xml
<mapping>
<character>અ</character>
<itrans>a</itrans>
<mapping>
i need to access these xml files and store the characters in an two dimensional array in global.asa!! i am using C# visual studio 2008!! thanks!!
I HAVE DONE THINGS SO FAR
sbyte[,] a = new sbyte[100, 100];
sbyte[,] b = new sbyte[100, 100开发者_开发知识库];
int count = 0;
XDocument xmlDoc = XDocument.Load("dev.xml");
while (!eof)
{
if (documentcontent.childnode == "true")
count = count + 1;
}
for(int i=0;i<count;i++)
{
for(int j=0;j<count;j++)
{
if(j==0)
a[i][j]=documentcontent.childnode.childnode[0].data;
else
a[i][j]=documentcontent.childnode.childnode[1].data;
}
}
IS the END OF FILE c ondition correct? i am getting an error!! how to use end of file in c#?
This should help you out:
XElement xdoc = XElement.Load("dev.xml");
var myMapping = xdoc.Descendants("mapping")
.ToDictionary(x => x.Element("character").Value,
x => x.Element("itrans").Value);
This assumes this XML structure for dev.xml (added outer element mappings
so you can store multiple mapping
elements:
<mappings>
<mapping>
<character>अ</character>
<itrans>a</itrans>
</mapping>
<mapping>
<character>foo</character>
<itrans>bar</itrans>
</mapping>
</mappings>
You can use it like:
string itrans = myMapping["foo"]; //returns bar
精彩评论