[問題] 讀取xml字串

看板java作者 (frog)時間11年前 (2012/10/24 17:25), 編輯推噓3(304)
留言7則, 6人參與, 最新討論串1/2 (看更多)
最近在研究讀取xml的問題 是使用dom去呼叫 但找到的範例大多都是直接讀取檔案 ex: File f=new File("data_10k.xml");    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();    DocumentBuilder builder=factory.newDocumentBuilder();    Document doc = builder.parse(f); NodeList nl = doc.getElementsByTagName("VALUE"); . . . 想請問如果不是讀取檔案的模式 而是直接讀取一個字串 要如何修正呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.163.194.240

10/24 17:31, , 1F
硬幹,把字串放進 inputstream 丟進去
10/24 17:31, 1F

10/24 17:38, , 2F
拿的到字串就有API可以用吧@@?
10/24 17:38, 2F

10/24 17:40, , 3F
ByteArrayInputStream(str.getBytes()) 可以用嗎?
10/24 17:40, 3F
經過修改後,加入這樣 InputStream xml = new ByteArrayInputStream(fff.getHello().getBytes("UTF-8")); Document doc = builder.parse(xml); 但還是讀不出來~"~

10/24 17:47, , 4F
我是用 SAX DefaultHandler
10/24 17:47, 4F
※ 編輯: jackyeah1213 來自: 118.163.194.240 (10/24 17:57)

10/24 18:06, , 5F
document 哪家的? jdom 我記得可以從strReader build出來
10/24 18:06, 5F

10/24 18:38, , 6F
==.=== 有錯誤訊息要給錯誤訊息阿
10/24 18:38, 6F

10/25 23:17, , 7F
InputSource + StringReader
10/25 23:17, 7F
文章代碼(AID): #1GXxG3Md (java)
討論串 (同標題文章)
文章代碼(AID): #1GXxG3Md (java)