本文整理匯總了Java中org.w3c.dom.ls.LSInput.setEncoding方法的典型用法代碼示例。如果您正苦於以下問題:Java LSInput.setEncoding方法的具體用法?Java LSInput.setEncoding怎麽用?Java LSInput.setEncoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.ls.LSInput
的用法示例。
在下文中一共展示了LSInput.setEncoding方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testExternalEncoding
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
@Test
public void testExternalEncoding() {
try {
LSInput src = null;
LSParser dp = null;
src = createLSInputEncoding();
dp = createLSParser();
src.setEncoding("UTF-16");
Document doc = dp.parse(src);
Assert.assertTrue("encodingXML".equals(doc.getDocumentElement().getNodeName()), "XML document is not parsed correctly");
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
}
}
示例2: newInputSource
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
public InputSource newInputSource(String filename) throws Exception {
// Create DOMImplementationLS, and DOM L3 LSParser
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
DocumentBuilder bldr = fact.newDocumentBuilder();
DOMImplementationLS impl = (DOMImplementationLS) bldr.getDOMImplementation();
LSParser domparser = impl.createLSParser(MODE_SYNCHRONOUS, null);
domparser.setFilter(new MyDOMBuilderFilter());
// Parse the xml document to create the DOM Document using
// the DOM L3 LSParser and a LSInput (formerly LSInputSource)
Document doc = null;
LSInput src = impl.createLSInput();
// register the input file with the input source...
String systemId = filenameToURL(filename);
src.setSystemId(systemId);
try (Reader reader = new FileReader(filename)) {
src.setCharacterStream(reader);
src.setEncoding("UTF-8");
doc = domparser.parse(src);
}
// Use DOM L3 LSSerializer (previously called a DOMWriter)
// to serialize the xml doc DOM to a file stream.
String tmpCatalog = Files.createTempFile(Paths.get(USER_DIR), "catalog.xml", null).toString();
LSSerializer domserializer = impl.createLSSerializer();
domserializer.setFilter(new MyDOMWriterFilter());
domserializer.getNewLine();
DOMConfiguration config = domserializer.getDomConfig();
config.setParameter("xml-declaration", Boolean.TRUE);
String result = domserializer.writeToString(doc);
try (FileWriter os = new FileWriter(tmpCatalog, false)) {
os.write(result);
os.flush();
}
// Return the Input Source created from the Serialized DOM L3 Document.
InputSource catsrc = new InputSource(new InputStreamReader(new ByteArrayInputStream(Files.readAllBytes(Paths.get(tmpCatalog)))));
catsrc.setSystemId(systemId);
return catsrc;
}
示例3: newInputSource
import org.w3c.dom.ls.LSInput; //導入方法依賴的package包/類
public InputSource newInputSource(String filename) throws Exception {
// Create DOMImplementationLS, and DOM L3 LSParser
DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
DocumentBuilder bldr = fact.newDocumentBuilder();
DOMImplementationLS impl = (DOMImplementationLS) bldr.getDOMImplementation();
LSParser domparser = impl.createLSParser(MODE_SYNCHRONOUS, null);
domparser.setFilter(new MyDOMBuilderFilter());
// Parse the xml document to create the DOM Document using
// the DOM L3 LSParser and a LSInput (formerly LSInputSource)
Document doc = null;
LSInput src = impl.createLSInput();
// register the input file with the input source...
String systemId = filenameToURL(filename);
src.setSystemId(systemId);
try (Reader reader = new FileReader(filename)) {
src.setCharacterStream(reader);
src.setEncoding("UTF-8");
doc = domparser.parse(src);
}
// Use DOM L3 LSSerializer (previously called a DOMWriter)
// to serialize the xml doc DOM to a file stream.
String tmpCatalog = Files.createTempFile(Paths.get("").toAbsolutePath(), "catalog.xml", null).toString();
LSSerializer domserializer = impl.createLSSerializer();
domserializer.setFilter(new MyDOMWriterFilter());
domserializer.getNewLine();
DOMConfiguration config = domserializer.getDomConfig();
config.setParameter("xml-declaration", Boolean.TRUE);
String result = domserializer.writeToString(doc);
try (FileWriter os = new FileWriter(tmpCatalog, false)) {
os.write(result);
os.flush();
}
// Return the Input Source created from the Serialized DOM L3 Document.
InputSource catsrc = new InputSource(new InputStreamReader(new ByteArrayInputStream(Files.readAllBytes(Paths.get(tmpCatalog)))));
catsrc.setSystemId(systemId);
return catsrc;
}