2010-11-25 24 views
44

Bir rehber takip ediyorum ve bana aşağıdaki kodu verir:Bir String'den org.xml.sax.InputSource nasıl oluştururum?

InputSource inputSource = new InputSource(new FileInputStream(new File("/path/to/xml/file.xml")))); 

Bilmek istiyorum Ne, hala bunun yerine bir dosya, kullanım içeriği okuyan bir org.xml.sax.InputSource oluşturabilir nasıl Zaten sahip olduğum bir String değişken.

cevap

76

FileInputStream yerine StringReader kullanın. o org.xml.sax.InputSource ise

InputSource inputSource = new InputSource(new StringReader(myString)); 
+0

Bir çekicilik gibi çalıştım. Teşekkürler dostum. – Chiggins

3

InputSource inputSource = new InputSource(new java.io.StringReader(string));:

StringReader

örneğin belgelere bakın.

İlgili konular