从对话框中删除标签

时间:2014-10-04 15:40:57

标签: java

我无法从我输出的对话框中显示的代码输出中删除SSP和/ SSP标记。

我已经尝试了一些不同的方法来删除标签,但似乎不能请您建议如何修改下面的代码,以便我可以删除这些标签。我对Java很新。

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package simpledialogbox;

import javax.swing.JOptionPane;
import java.io.IOException;
import java.util.logging.*;
import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.select.*;

public class SimpleDialogBox {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try {
        String url = "http://bmreports.com/bsp/additional/soapfunctions.php?element=SYSPRICE&dT=NRT";
        Document doc = Jsoup.connect(url).get();
         Elements SSPparagraphs;
  SSPparagraphs = doc.select("SSP");  
  //paragraphs = doc.select("SBP");
  System.out.println(SSPparagraphs.text());

       (Element SSPparagraphs : paragraphs)
      JOptionPane.showMessageDialog(

        null, SSPparagraphs, "Cashout Prices", JOptionPane.PLAIN_MESSAGE);
        System.exit(0);


    }   

        catch (IOException ex) {
  Logger.getLogger(SimpleDialogBox.class.getName())
        .log(Level.SEVERE, null, ex);
   }
}


} 

1 个答案:

答案 0 :(得分:1)

在对话框中

 JOptionPane.showMessageDialog(null, SSPparagraphs, "Cashout Prices", JOptionPane.PLAIN_MESSAGE);

添加' .text()'到SSparagraphs

 JOptionPane.showMessageDialog(null, SSPparagraphs.text(), "Cashout Prices", JOptionPane.PLAIN_MESSAGE);

然后,为了在不同的行上获得输出,我改变了代码。我将输出分配给一个字符串,然后将其拆分为空格。然后我在对话框和控制台输出中显示格式化的字符串。

 package stackoverflow;

 import javax.swing.JOptionPane;
 import java.io.IOException;
 import java.util.logging.*;
 import org.jsoup.*;
 import org.jsoup.nodes.*;
 import org.jsoup.select.*;

 public class SimpleDialogBox 
 {
     public static void main(String[] args) 
     {
         // TODO code application logic here
        try 
        {
            String url = "http://bmreports.com/bsp/additional/soapfunctions.php?element=SYSPRICE&dT=NRT";
            Document doc = Jsoup.connect(url).get();
            Elements SSPparagraphs;
            SSPparagraphs = doc.select("SSP");  
            //paragraphs = doc.select("SBP");

            String[] numbers = SSPparagraphs.text().toString().split(" ");
            String formattedText = new String("");
            for (int x = 0; x < numbers.length; x++)
            {
                formattedText += numbers[x] + "\n";
            }

            System.out.println(formattedText);

            //(Element paragraphs : SSPparagraphs)
            JOptionPane.showMessageDialog(
                null, formattedText, "Cashout Prices", JOptionPane.PLAIN_MESSAGE);
            System.exit(0);
        }   
        catch (IOException ex) 
        {
            Logger.getLogger(SimpleDialogBox.class.getName())
            .log(Level.SEVERE, null, ex);
        }
      }
 }