久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在線讀取 XML 并存儲它(使用 Java)

Reading XML online and Storing It (Using Java)(在線讀取 XML 并存儲它(使用 Java))
本文介紹了在線讀取 XML 并存儲它(使用 Java)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我發現并遵循了 Stackoverflow (http://stackoverflow.com/questions/2310139/how-to-read-xml-response-from-a-url-in-java) 中關于如何讀取 XML 的示例來自 URL 的文件(如您在下面粘貼的代碼中所見).我唯一的麻煩是,既然我得到了讀取 XML 的程序,我該如何讓它來存儲它呢?例如,我可以讓它將信息保存到項目中內置的 XML 文件中嗎(如果可能的話,這對我來說是最好的解決方案)?例如,例如,我在項目中內置了一個空白 XML 文件.程序運行,從 URL 中讀取 XML 代碼,并將其全部存儲到預先構建的空白 XML 文件中.我可以這樣做嗎?

I found and followed an example from Stackoverflow (http://stackoverflow.com/questions/2310139/how-to-read-xml-response-from-a-url-in-java) of how to read an XML file from a URL (as you can see in my code pasted below). My only trouble is that now that I got the program to read the XML, how do I get it to store it? For example, could I make it save the information to a XML file built into the project (this would be the best solution for me, if it's possible)? Such as, take for example, I have a blank XML file built into the project. The program runs, reads the XML code off of the URL, and stores it all into the pre-built blank XML file. Could I do this?

如果我對任何事情感到困惑或不清楚,請讓我澄清我在尋找什么.

If I sound confusing or un-clear about anything, just ask me to clarify what I'm looking for.

這是我的代碼,如果你想看看我目前的代碼:

And here is my code, if you'd like to look at what I have so far:

package xml.parsing.example;

import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.xml.sax.SAXException;

public class XmlParser {
    public static void main (String[] args) throws IOException, ParserConfigurationException, SAXException, TransformerException {
        URL url = new URL("http://totheriver.com/learn/xml/code/employees.xml");
        URLConnection conn = url.openConnection();

        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        Document doc = builder.parse(conn.getInputStream());

        TransformerFactory tfactory = TransformerFactory.newInstance();
        Transformer xform = tfactory.newTransformer();

        // that’s the default xform; use a stylesheet to get a real one
        xform.transform(new DOMSource(doc), new StreamResult(System.out));
    }
}

推薦答案

很簡單:

File myOutput = new File("c:\myDirectory\myOutput.xml");
xform.transform(new DOMSource(doc), new StreamResult(myOutput));

這篇關于在線讀取 XML 并存儲它(使用 Java)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Upload progress listener not fired (Google drive API)(上傳進度偵聽器未觸發(Google 驅動器 API))
Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 將文件保存在特定文件夾中)
Google Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 無效的 DriveId 和 Null ResourceId)
Google drive api services account view uploaded files to google drive using java(谷歌驅動api服務賬戶查看上傳文件到谷歌驅動使用java)
Google Drive service account returns 403 usageLimits(Google Drive 服務帳號返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例中缺少)
主站蜘蛛池模板: 欧美综合一区二区三区 | 日韩免费一区 | 欧美在线观看网站 | 在线视频一区二区三区 | 亚洲视频在线免费观看 | 日韩在线资源 | 国产福利小视频 | 99久久国产综合精品麻豆 | 久草中文网 | 日本粉嫩一区二区三区视频 | 成人精品视频 | 国产精品无码专区在线观看 | 国产一区久久精品 | 四虎在线播放 | 日本精品久久 | 免费色网址 | 91久久综合亚洲鲁鲁五月天 | 91成人| 欧美日韩亚洲国产综合 | 久久成人精品视频 | 天天综合干 | 成人欧美一区二区三区在线播放 | 欧洲亚洲一区二区三区 | 特级丰满少妇一级aaaa爱毛片 | 成人毛片一区二区三区 | 九九99九九精彩46 | 亚洲综合三区 | 视频一区二区在线观看 | 福利视频网站 | 美女视频黄色的 | 久久久99国产精品免费 | 欧美成人精品激情在线观看 | 久草网在线视频 | 亚洲成av人片在线观看 | 特黄色一级毛片 | 日本一二三区电影 | 黄网站在线播放 | 国产永久免费 | 久久av一区二区三区 | 中文字幕二区 | 免费观看av |