本文整理汇总了Java中org.w3c.dom.Document.appendChild方法的典型用法代码示例。如果您正苦于以下问题:Java Document.appendChild方法的具体用法?Java Document.appendChild怎么用?Java Document.appendChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Document
的用法示例。
在下文中一共展示了Document.appendChild方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addStatisticsAsText
import org.w3c.dom.Document; //导入方法依赖的package包/类
protected Object addStatisticsAsText(String stats, Object result) throws UnsupportedEncodingException{
if (result != null) {
if (stats == null) stats = context.statistics.printStatistics();
if (result instanceof Document) {
Document document = (Document) result;
Comment comment = document.createComment("\n" + stats);
document.appendChild(comment);
}
else if (result instanceof byte[]) {
String encodingCharSet = "UTF-8";
if (context.requestedObject != null)
encodingCharSet = context.requestedObject.getEncodingCharSet();
String sResult = new String((byte[]) result, encodingCharSet);
sResult += "<!--\n" + stats + "\n-->";
result = sResult.getBytes(encodingCharSet);
}
}
return result;
}
示例2: createNewFormBody
import org.w3c.dom.Document; //导入方法依赖的package包/类
private Element createNewFormBody(Document doc, String csFormName, String csTitle)
{
Element eProgram = doc.createElement("Root") ;
doc.appendChild(eProgram) ;
Element eForm = doc.createElement("Form");
eProgram.appendChild(eForm);
Element eName = doc.createElement("Name") ;
eForm.appendChild(eName) ;
eName.appendChild(doc.createTextNode(csFormName));
eForm.setAttribute("Title", csTitle);
Element eBody = doc.createElement("FormBody");
eForm.appendChild(eBody);
return eBody;
}
示例3: exportProcess
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* This method will create a document, append the complete process that contains the given
* operator. The {@link Document} is then returned.
*/
public Document exportProcess(Operator operator, boolean hideDefault) throws IOException {
try {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element rootElement = doc.createElement(ELEMENT_PROCESS);
doc.appendChild(rootElement);
rootElement.setAttribute("version", RapidMiner.getLongVersion());
final Process process = operator.getProcess();
if (process != null) {
rootElement.appendChild(exportProcessContext(process.getContext(), doc));
if (!process.getAnnotations().isEmpty()) {
rootElement.appendChild(exportAnnotations(process.getAnnotations(), doc));
}
}
rootElement.appendChild(exportOperator(operator, hideDefault, doc));
return doc;
} catch (ParserConfigurationException e) {
throw new IOException("Cannot create XML document builder: " + e, e);
}
}
示例4: mediaListToDocument
import org.w3c.dom.Document; //导入方法依赖的package包/类
public static Document mediaListToDocument(List<Media> list) {
Document dom = null;
// instance of a DocumentBuilderFactory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
try {
// use factory to get an instance of document builder
DocumentBuilder db = dbf.newDocumentBuilder();
// create instance of DOM
dom = db.newDocument();
// create the root element
Element rootEle = dom.createElement(root);
for (Media m : list)
rootEle.appendChild(mediaToElement(m,dom));
dom.appendChild(rootEle);
} catch (ParserConfigurationException pce) {
System.out.println("UsersXML: Error trying to instantiate DocumentBuilder " + pce);
}
return dom;
}
示例5: save
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Speichert einen Song in einer XML-Datei an den angegebenen Pfad.<br>
* Datei hat ein zulässiges Music-XML Format, welches offen ist und in allen gängigen Notensatzprogrammen unterstützt wird.<br>
* Mehr Informationen über Music-XML sind auf der <a href="http://www.musicxml.com/">offiziellen Webseite des Formats</a><br>
* Wir verwenden für das Öffnen der Dateien das Open-Source-Programm <a href="https://musescore.org/">MuseScore</a>
*
* @param file Der Pfad an dem die Datei gespeichert werden soll
* @param song Der zu speichernde Song
* @throws XMLException Falls ein Fehler beim Speichern auftritt
*/
public void save( File file, Song song ) throws XMLException {
this.file = file;
this.song = song;
Document doc = createDocument();
this.doc = doc;
Element root = doc.createElement( "score-partwise" );
doc.appendChild( root );
createHead( root );//Erstellt den Kopfteil der Datei
createPartList( root );//Erstellt die Part-Liste
createParts( root );//erstellt die eigentlichen Parts
saveDocumentTo();//speichert das Dokument
}
示例6: makeBlob
import org.w3c.dom.Document; //导入方法依赖的package包/类
protected Document makeBlob(byte[] data){
Document document = XMLUtils.getDefaultDocumentBuilder().newDocument();
Element blob = document.createElement("blob");
document.appendChild(blob);
Header[] heads = context.getResponseHeaders();
for (int i = 0; i < heads.length; i++) {
if (HeaderName.ContentType.is(heads[i].getName()) ||
HeaderName.ContentLength.is(heads[i].getName()) ) {
blob.setAttribute(heads[i].getName(), heads[i].getValue());
}
}
blob.setAttribute("Referer", ((HtmlConnector)context.getConnector()).getReferer());
blob.appendChild(document.createTextNode(Base64.encodeBase64String(data)));
return document;
}
示例7: createVmlDocument
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
*
*/
public static Document createVmlDocument()
{
Document document = createDocument();
Element root = document.createElement("html");
root.setAttribute("xmlns:v", "urn:schemas-microsoft-com:vml");
root.setAttribute("xmlns:o", "urn:schemas-microsoft-com:office:office");
document.appendChild(root);
Element head = document.createElement("head");
Element style = document.createElement("style");
style.setAttribute("type", "text/css");
style.appendChild(document
.createTextNode("<!-- v\\:* {behavior: url(#default#VML);} -->"));
head.appendChild(style);
root.appendChild(head);
Element body = document.createElement("body");
root.appendChild(body);
return document;
}
示例8: test_parseAndWriteDomDocument
import org.w3c.dom.Document; //导入方法依赖的package包/类
public void test_parseAndWriteDomDocument() throws SAXException, ParserConfigurationException, IOException {
// make sure that returned result is not null
final Document document = XMLUtils.parseDom(TEST_FILE, false);
assertNotNull(document);
final Element elem = document.createElement("unittest");
document.appendChild(elem);
XMLUtils.writeDom2File(document, TEST_RESULT);
// make sure that file created by writeDom2File exists
TestHelper.assertExists(TEST_RESULT);
// and make sure that file created by writeDom2File has non-zero length
if (log.isDebugEnabled()) log.debug("new File(TEST_RESULT): " + new File(TEST_RESULT));
if (log.isDebugEnabled()) log.debug("new File(TEST_RESULT).length(): " + new File(TEST_RESULT).length());
assertTrue(TEST_RESULT_FILE.length() > 0);
}
示例9: testGetDocAsString2
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testGetDocAsString2() throws Exception {
final Document doc = builder.newDocument();
final Element element = doc.createElement("test");
element.setAttribute("attr", "\u306f\u3044");
doc.appendChild(element);
assertEquals(
String.format("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>%n<test attr=\"\u306f\u3044\"/>%n"),
XMLConverter.convertToString(doc, true));
}
示例10: exportSingleOperator
import org.w3c.dom.Document; //导入方法依赖的package包/类
public Document exportSingleOperator(Operator operator) throws IOException {
try {
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
doc.appendChild(exportOperator(operator, false, doc));
return doc;
} catch (ParserConfigurationException e) {
throw new IOException("Cannot create XML document builder: " + e, e);
}
}
示例11: testWorkaround
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testWorkaround() {
Document doc;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element el = doc.createElement("x");
doc.appendChild(el);
DOMImplementationLS ls = (DOMImplementationLS) doc.getImplementation().getFeature("LS", "3.0");
System.out.println(ls.createLSSerializer().writeToString(doc));
} catch (ParserConfigurationException ex) {
ex.printStackTrace();
Assert.fail(ex.getMessage());
}
}
示例12: writeResults
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Creates root element and adds schema informations to it
* @param resultsDoc Document root
* @param measure data structure
*/
static protected void writeResults(Document resultsDoc, MeasureDefinition measure) {
Element elem = resultsDoc.createElement(XML_DOCUMENT_ROOT);
resultsDoc.appendChild(elem);
elem.setAttribute("xsi:noNamespaceSchemaLocation", XML_DOCUMENT_XSD);
elem.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
elem.setAttribute(XML_A_ROOT_POLLING, Double.toString(measure.getPollingInterval()));
elem.setAttribute(XML_A_ROOT_ELAPSED, Long.toString(measure.getElapsedTime()));
elem.setAttribute(XML_A_ROOT_LOG_DECIMAL_SEP, measure.getLogDecimalSeparator());
elem.setAttribute(XML_A_ROOT_LOG_DELIMITER, measure.getLogCsvDelimiter());
writeMeasures(resultsDoc, elem, measure);
}
示例13: testNewElement
import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void testNewElement() throws Exception {
final Document doc = builder.newDocument();
final Element element = doc.createElement("test");
doc.appendChild(element);
final Element another = XMLConverter.newElement("another", element);
assertSame(doc, another.getOwnerDocument());
assertEquals("another", another.getNodeName());
}
示例14: toXml
import org.w3c.dom.Document; //导入方法依赖的package包/类
public Document toXml() throws ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();
Element rootEl = document.createElement("testsuites");
document.appendChild(rootEl);
rootEl.setAttribute("time", this.getTime().toString());
rootEl.setAttribute("tests", this.getTests().toString());
rootEl.setAttribute("failures", this.getFailures().toString());
rootEl.setAttribute("name", this.getName());
for (TestSuite t : this.testSuites) {
rootEl.appendChild(document.importNode(t.getXml(), true));
}
return document;
}
示例15: getXML
import org.w3c.dom.Document; //导入方法依赖的package包/类
private Document getXML() {
Document doc;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
} catch (ParserConfigurationException e) {
throw new RuntimeException("Cannot create parser: " + e, e);
}
Element root = doc.createElement("usageStatistics");
if (lastReset != null) {
root.setAttribute("last-reset", getDateFormat().format(lastReset));
}
if (nextTransmission != null) {
root.setAttribute("next-transmission", getDateFormat().format(nextTransmission));
}
root.setAttribute("random-key", this.randomKey);
root.setAttribute("rapidminer-version", new RapidMinerVersion().toString());
root.setAttribute("os-name", System.getProperties().getProperty("os.name"));
root.setAttribute("os-version", System.getProperties().getProperty("os.version"));
License activeLicense = ProductConstraintManager.INSTANCE.getActiveLicense();
if ((activeLicense != null) && (activeLicense.getLicenseID() != null)) {
root.setAttribute("lid", activeLicense.getLicenseID());
}
doc.appendChild(root);
root.appendChild(ActionStatisticsCollector.getInstance().getXML(doc));
return doc;
}