[XML] How do I get every child tag separately?

Discussion in 'Plugin Development' started by skipperguy12, Mar 28, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    skipperguy12

    Hello! With this Java to parse some XML:
    Code:
        Node rs = doc.getElementsByTagName("redspawn").item(0);
                    for(int i = 0 ; i < doc.getElementsByTagName("redspawn").getLength() ; i++){
       
                        String x = doc.getElementsByTagName("redspawn").item(0).getTextContent();
                        System.out.print(x);
                    
                    }
    It returns one string..."010"

    But my XML is structured like this:
    Code:
        <redspawn>
            <x>0</x>
            <y>1</y>
            <z>0</z>
        </redspawn>
    How can I get x, y, and z separately?
    Is there a way to get every int separately out of a String?

    Please don't suggest YAML, i'm trying to work with XML for specific reasons...
     
  2. Offline

    Tirelessly

    skipperguy12 Each of those is separate, but because you're using print and not println it puts them next to each other.
     
  3. Offline

    skipperguy12

    Tirelessly
    But when I add:
    System.out.println(one);
    System.out.println("--");
    it looks like this:
    0
    1
    0
    --

    Same exact result with System.out.println(one + "--");
    so basically, it is one string. Why?
     
  4. Offline

    Tirelessly

    Change the print to a println and don't do anything else. Tell me what happens.
     
  5. Offline

    skipperguy12

    Tirelessly
    Okay, it's still 010 but with a bunch of spaces, causing it to appear multilined.

    I added System.out.println(i) during forloop, it only goes up to 0...
     
  6. Offline

    Tirelessly

    Don't really know how XML works, so I can't really help then. Sorry. If it's always going to be one letter you can split it into a char array?
     
  7. Offline

    skipperguy12

    Tirelessly
    Not very good with string manipulation, example?
     
  8. Offline

    Tirelessly

    String.toCharArray()
     
Thread Status:
Not open for further replies.

Share This Page