Java HTML Jsoup Document getJSoupXmlDocument(final String url)

Here you can find the source of getJSoupXmlDocument(final String url)

Description

get J Soup Xml Document

License

Open Source License

Declaration

public static Document getJSoupXmlDocument(final String url) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.parser.Parser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    public static Document getJSoupXmlDocument(final String url) {
        final String rawXml = getTextFromURL(url);

        return Jsoup.parse(rawXml, "", Parser.xmlParser());
    }//from w ww . j  ava2  s.c  o m

    public static String getTextFromURL(final String url) {
        StringBuilder result = new StringBuilder();
        try {
            final URL website = new URL(url);
            final URLConnection connection = website.openConnection();
            final BufferedReader in = new BufferedReader(
                    new InputStreamReader(connection.getInputStream()));

            String inputLine;

            while ((inputLine = in.readLine()) != null)
                result.append(inputLine);

            in.close();

        } catch (MalformedURLException e) {
            e.printStackTrace(); //TODO FCRES: Autogenerated, modify
        } catch (IOException e) {
            e.printStackTrace(); //TODO FCRES: Autogenerated, modify
        }

        return result.toString();
    }
}

Related

  1. getDocument(String url)
  2. getHtmlDocument(String url)
  3. getIcon(Document doc)
  4. getInfoboxLines(final Document html, final boolean stripColor)
  5. getJSoupHtmlDocument(final String url)
  6. getLoginFields(Document doc)
  7. getTextFromAvailableDivID(Document doc, String divID)
  8. getTitleFromDocument(Document doc)
  9. keepLineBreak(Document docRes)