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 me any ideas and suggest any websites and examples regarding this issue.
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 in a two dimensional array. Suppose I have an xml array [10] [40]. In this array, I want to display as xml [0] [0] = symbol and xml [0] [1] = keys using a java program. Please suggest any idea.
a source to share
I would recommend reading it on a map.
Use the DocumentBuilder API:
http://java.sun.com/j2se/1.4.2/docs/api/javax/xml/parsers/DocumentBuilder.html
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.parse( new File(fileName) );
Then you can use the DocumentBuilder methods to grab the data as needed, for example:
document.getElementsByTagName("NameOfTag");
a source to share
I worked on this and was able to do it here on my GitHub repository . Basically, I am using the XStream API to create a DataProvider for TestNG tests. It reads data into a 2-D object array.
a source to share