Java HTML Parse Jsoup getDoctypeName(InputStream s)

Here you can find the source of getDoctypeName(InputStream s)

Description

get Doctype Name

License

Open Source License

Declaration

static String getDoctypeName(InputStream s) throws IOException 

Method Source Code


//package com.java2s;
/*/*from w w  w  .j av  a  2 s  .  c  o  m*/
   Copyright 2012-2018 Michael Pozhidaev <michael.pozhidaev@gmail.com>
    
   This file is part of LUWRAIN.
    
   LUWRAIN is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.
    
   LUWRAIN is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.
*/

import java.util.*;
import java.io.*;

public class Main {
    static String getDoctypeName(InputStream s) throws IOException {
        final org.jsoup.nodes.Document doc = org.jsoup.Jsoup.parse(s, "us-ascii", "",
                org.jsoup.parser.Parser.xmlParser());
        List<org.jsoup.nodes.Node> nods = doc.childNodes();
        for (org.jsoup.nodes.Node node : nods)
            if (node instanceof org.jsoup.nodes.DocumentType) {
                org.jsoup.nodes.DocumentType documentType = (org.jsoup.nodes.DocumentType) node;
                final String res = documentType.attr("name");
                if (res != null)
                    return res;
            }
        for (org.jsoup.nodes.Node node : nods)
            if (node instanceof org.jsoup.nodes.Element) {
                org.jsoup.nodes.Element el = (org.jsoup.nodes.Element) node;
                final String res = el.tagName();
                if (res != null)
                    return res;
            }
        return "";
    }
}

Related

  1. getDistinctImageUrls(String htmlContent)
  2. getDoc(Connection conn)
  3. getDoc(File file)
  4. getDoc(String path)
  5. getDoc(String url)
  6. getErrorMessage(String htmlStr)
  7. getExplanation(String html)
  8. getFirstImageSrc(String html)
  9. getFirstSentence(final String html)