开发者

How to read XML file into two dimensional array using Java

How to read XML file into two dimensional array using java. I am new to this concept. Please suggest to me any ideas and suggest any websites and examples regarding this question.

My 2-D xml file will look like this:

<Base>
    <Map>
        <Display>0B85</Display>
        <Keys>61</Keys开发者_高级运维>
    </Map>
    <Map>
        <Display>0B86</Display>
        <Keys>62</Keys>
    </Map>
</Base>

I want to read this xml file into a two-dimensional array. Suppose I have an array xml[10][40]. In this array I want to display as xml[0][0]=character and xml[0][1]=keys using java program. Please suggest any idea.


I would recommend reading it into a map. Use the DocumentBuilder API:

DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse( new File(fileName) );

You can then use the DocumentBuilder's methods to grab the data as required, e.g.

document.getElementsByTagName("NameOfTag");


I worked on this and managed to do it here, in my GitHub repo. Basically, I use XStream API to create a DataProvider for TestNG tests. It reads data into a 2-D object array.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜