Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有树结构的javaxml_Java_Regex_Xml - Fatal编程技术网

具有树结构的javaxml

具有树结构的javaxml,java,regex,xml,Java,Regex,Xml,我知道如何使用这种代码获取文件的xml元素: 因为有一个根元素和一个包含一些信息的电影元素 但在这一环节: 我需要电影的嵌入代码,这是树的第三个元素,我只知道如何为max 2结构执行。 另外,我应该只在我的webview元素中使用iframe代码,但我没有在java中使用regex的经验。我建议您不要尝试使用regex,而是尝试以下方法: import java.io.InputStream; import java.net.URL; import java.net.URLConnectio

我知道如何使用这种代码获取文件的xml元素:

因为有一个根元素和一个包含一些信息的电影元素

但在这一环节:

我需要电影的嵌入代码,这是树的第三个元素,我只知道如何为max 2结构执行。
另外,我应该只在我的webview元素中使用iframe代码,但我没有在java中使用regex的经验。

我建议您不要尝试使用regex,而是尝试以下方法:

import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public static void main(String[] args) throws Exception {
    String url = "http://api.traileraddict.com/?film=fifty-shades-of-grey&count=1";
    parse(url);
}

public static void parse(String strUrl) throws Exception {
    URL url = new URL(strUrl);
    URLConnection connection = url.openConnection();
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    try (InputStream is = connection.getInputStream()) {
        Document doc = db.parse(is);
        NodeList nList = doc.getElementsByTagName("embed");
        Node embedItem = nList.item(0);
        System.out.println(embedItem.getTextContent());
    }
}

注意:这里我使用了DOM解析器,您可以试试sax或stax

我不了解节点列表的部分…它是一个名为“嵌入”的节点列表,因为只有一个名为“嵌入”的标记,获取第一个(其索引以0开头)我想在webview中使用代码我真正需要的是什么。因为我在网上搜索解决方案,但我只找到YouTube的例子。我需要一个像webview.getEngine()这样的代码。load(???)你是说,在iframe中?如果是这样,那么可以使用html解析器解析文本(如果我没有错的话,jSoup就是其中之一)