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;
import java.io.StringReader;
import java.util.Arrays;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Text;
import org.xml.sax.InputSource;
/**
* @author Tom
*
*/
public class XMLFromStringExample {
/**
* @param args
*/
public static void main(String[] args) throws Exception {
String xml = "<a><b>dfs</b><c>df</c></a>";
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(
new InputSource(new StringReader(xml)));
treeWalk(doc, 0);
}
private static void treeWalk(Node node, int level) {
System.out.print(makeWhiteSpaces(level));
if (node instanceof Text) {
System.out.print("Value: ");
System.out.println(((Text) node).getTextContent());
} else {
System.out.println(node.getNodeName());
}
if (node.hasChildNodes()) {
NodeList children = node.getChildNodes();
++level;
for (int i = 0, len = children.getLength(); i < len; i++) {
treeWalk(children.item(i), level);
}
}
}
private static String makeWhiteSpaces(int len) {
char[] c = new char[len];
Arrays.fill(c, ' ');
return new String(c);
}
}