문제

I am trying to grab some data from an XML File, however I am getting null data, it appears to be picking up that there are 3 results, but its returning Null 3 times instead of the relivant data.

The XML is as follows

<eveapi version="2">
  <currentTime>2014-03-10 11:12:27</currentTime>
  <result>
   <rowset name="characters" key="characterID" columns="name,characterID,corporationName,corporationID">
     <row name="Char 1" characterID="0000000" corporationName="Test Corp" corporationID="000000"/>
     <row name="Char 3" characterID="0000000" corporationName="Test Corp" corporationID="000000"/>
     <row name="Char 2" characterID="0000000" corporationName="Test Corp" corporationID="000000"/>
   </rowset>
  </result>
  <cachedUntil>2014-03-10 11:40:26</cachedUntil>
</eveapi>

Code Grabbing the XML

public static void APIGetChar(){

....         
            Element RootElement = document.getRootElement() ;                       
            Element windowManager = RootElement.getChild("result")
                                            .getChild("rowset");
            List namedChildren = windowManager.getChildren("row");


            for (int i = 0; i < namedChildren.size(); i++) {

                Element node = (Element) namedChildren.get(i);


                String rowset = node.getChildText("row name");
                String row = node.getChildText("row");
                String result = node.getChildText("result");
                String result1 = node.getChildText("name");
                System.out.println("Row Name: "+rowset);
                System.out.println("Row: "+row);
                System.out.println("Name: "+result1);
....

As you can see I have tried varied names, even compared it to my other XML grabber, my only guess is that RowSets are handled differently, but no amount of googleing is coming up with the answer, so any help would be great.

I need to grab the data from the XML, and pass it to a string so I can display the results in the program

도움이 되었습니까?

해결책

So it appears that the items in that rowset are actually attributes, hence when getting the ChildText did not work, so I used

String name = node.getAttributeValue("name");

allowed me to get the names, all the other code was correct.

xml attribute
Web definitions
In XML,  a designation that represents a combination of a name and value and is used to
provide additional information about an XML element, for example, <FONT SIZE=2>. In this
case,   FONT is an element and SIZE=2 is an attribute.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top