开发者

submitting data to an array to be pulled later

So I've got the following:

NodeList nodeList = element.getElementsByTagName("rowset");

    if (nodeLis开发者_如何转开发t.getLength() > 0) {
     for (int i = 0; i < nodeList.getLength(); i++) {
      Element entry = (Element) nodeList.item(i); 

      Element _titleE = (Element) entry.getElementsByTagName("row").item(0);  
      Node _title = _titleE.getAttributes().getNamedItem("name");

      t1.setText(_title.getNodeValue());

     }
    }

I've got the following XML layout:

<row name="" characterID="" corporationName="" corporationID="" />

(couple of lines of these)

the ideal way would be to create an array right? and then call the data from the array?

EDIT: What I'm trying to do is read an XML File and store the values so that they can be accessed later so I'm assuming the ideal way would be to use an array?


(as my girlfriends name is jenny, too, I will be guessing what you want)

If you just want to store one value, an array or a ArrayList is good for that. If you need to store all 4 given attributes of your row, you should think about creating a class (lets call it MyRow) that contains those values. Than you can put all your rows into one ArrayList with the type of your class.

Pseudocode:

ArrayList<MyRow> myRowList = new ArrayList<MyRow>();
while reading each row
   MyRow row = new MyRow();
   row.mName = getAttributes().getNamesItem("name");
   row.mCharacterId = getAttributes().getNamesItem("characterID");
   // more setting...
}

A last tip for the next time: take some time to explain and specify your next question. That will improve the answers you get as well.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜