本文整理汇总了Java中org.w3c.dom.ls.LSSerializer.getNewLine方法的典型用法代码示例。如果您正苦于以下问题:Java LSSerializer.getNewLine方法的具体用法?Java LSSerializer.getNewLine怎么用?Java LSSerializer.getNewLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.ls.LSSerializer
的用法示例。
在下文中一共展示了LSSerializer.getNewLine方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: newInputSource
import org.w3c.dom.ls.LSSerializer; //导入方法依赖的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;
}
示例2: newInputSource
import org.w3c.dom.ls.LSSerializer; //导入方法依赖的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;
}