I am having trouble removing the SSP and /SSP tags from the output of my code which appears in a dialogue box that i am outputting to.
I have tried a few different methods to removing the tags but cant seem to Please can you advise how to amend the code below so that i these tags can be removed. I am pretty new to 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);
}
}
}
In your dialog
JOptionPane.showMessageDialog(null, SSPparagraphs, "Cashout Prices", JOptionPane.PLAIN_MESSAGE);
add '.text()' to SSparagraphs
JOptionPane.showMessageDialog(null, SSPparagraphs.text(), "Cashout Prices", JOptionPane.PLAIN_MESSAGE);
Then, to get the output on different lines, I changed the code. I assigned the output to a string, then split it on the spaces. I then showed the formatted string in the dialog box, and in console output.
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);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.