开发者

c# xml file access [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜