Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.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
Android 如何在textview中显示Internet上文件中的信息_Android - Fatal编程技术网

Android 如何在textview中显示Internet上文件中的信息

Android 如何在textview中显示Internet上文件中的信息,android,Android,需要帮助,有一个文档位于类似的链接 其结构如下: <data> <Connections/> <Current_Listeners>3</Current_Listeners> <Description/> <Currently_Playing> <Name>Black Sun Empire -

需要帮助,有一个文档位于类似的链接

其结构如下:

<data>
      <Connections/>
            <Current_Listeners>3</Current_Listeners>
            <Description/>
            <Currently_Playing>
                   <Name>Black Sun Empire - Salvador (Feat. Bless)</Name>
            </Currently_Playing>
            <Source/>
      <Connections/>
      <Current_Listeners>0</Current_Listeners>
      <Description/>
            <Currently_Playing>
                   <Name>Black Sun Empire - Salvador (Feat. Bless)</Name>
            </Currently_Playing>
      <Source/>
</data>

3.
黑太阳帝国-萨尔瓦多(壮举,祝福)
0
黑太阳帝国-萨尔瓦多(壮举,祝福)

如何读取文件以从标记之间的框中选择信息,并将其显示在我的文本视图中。

您可以尝试以下操作:

            // Get your file from internet
    URL url = new URL("http://url.com/info.xsl");
    URLConnection connection = url.openConnection();
    InputStream in = connection.getInputStream();
    String filePath = Environment.getExternalStorageDirectory().getAbsolutePath()+ "/filename.xml"
    File file = new File (filePath);

    CreateFileFromInputStream(in,  filePath) ;

            // Parse it with document builder factory
    DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder dBuilder = null;
    dBuilder = dbFactory.newDocumentBuilder();
    Document doc = null;
    doc = dBuilder.parse(file);
    doc.getDocumentElement().normalize();
    // The root element is 
    doc.getDocumentElement().getNodeName();

    NodeList nList =    doc.getElementsByTagName("Name");

    for ( int i = 0 ; i < nList.getLength() ; i++ ) {

        Element element = (Element) nList.item(i) ;
        String name = getCharacterDataFromElement(element);

    }
以及:


我希望它能有所帮助…

u是说你想读取特定节点并在textview中显示???你可以使用xml parsing我想读取标记之间的一行并显示它这一行???xml解析文件会使用XSL吗?非常感谢,我将尝试只迭代数组或java.lang.Iterable的实例,在nList上显示(Node:nList){好的,我不记得NodeList是不可编辑的。我编辑了我的问题,我用fortach替换了foreach,非常感谢你,有一点要完成,不想加载到行上,必须通过AsyncTask完成,并在清单中添加一行用于写入外部存储
public static String getCharacterDataFromElement(Element e)
{
    Node node = e.getFirstChild();
    if (node instanceof CharacterData)
    {
        CharacterData cd = (CharacterData) node;
        return cd.getData();
    }
    return "";
}
public void CreateFileFromInputStream(InputStream inStream, String path) throws IOException {
    // write the inputStream to a FileOutputStream
    OutputStream out = new FileOutputStream(new File(path));

    int read = 0;
    byte[] bytes = new byte[1024];

    while ((read = inStream.read(bytes)) != -1) {
        out.write(bytes, 0, read);
    }

    inStream.close();
    out.flush();
    out.close();

}