Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
package de.tutorials.xml;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;
public class ChangeDemo {
ChangeDemo() {
final String XMLFILENAME = "tableConfig.xml";
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(XMLFILENAME);
String tableName = document.getElementsByTagName("tableName").item(0).getTextContent();
String title = document.getElementsByTagName("title").item(0).getTextContent();
String color = document.getElementsByTagName("color").item(0).getTextContent();
System.out.println("Old Values:");
System.out.println(tableName);
System.out.println(title);
System.out.println(color);
tableName = "neueTabelle";
title = "Hallo Universum";
color = "giftgelb";
System.out.println("\nNew Values:");
System.out.println(tableName);
System.out.println(title);
System.out.println(color);
document.getElementsByTagName("tableName").item(0).setTextContent(tableName);
document.getElementsByTagName("title").item(0).setTextContent(title);
document.getElementsByTagName("color").item(0).setTextContent(color);
TransformerFactory.newInstance().newTransformer().transform(
new DOMSource(document), new StreamResult(new FileOutputStream(XMLFILENAME)));
} catch (ParserConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerFactoryConfigurationError e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
new ChangeDemo();
}
}
TransformerFactory.newInstance().newTransformer().transform(
new DOMSource(document), new StreamResult(new FileOutputStream(XMLFILENAME)));