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.
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class convert
{
static Document document;
String[] list;
String[] head;
public static void main(String string[])
{
convert demo = new convert("C:/temp/serpil.xml");
demo.createXMLBasic();
demo.loadCSV("C:/temp/serpil.csv");
demo.speichern("C:/temp/serpil.xml");
}
public convert(String string)
{
newXMLFile(string);
}
public void newXMLFile(String string)
{
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();
}
catch (ParserConfigurationException pce)
{
pce.printStackTrace();
}
catch (Throwable t)
{
t.printStackTrace();
}
}
public void createXMLBasic()
{
Element root = document.createElement("Person");
document.appendChild(root);
}
public void loadCSV(String string)
{
// Methode zum Laden von CSV
String Zeile = "";
try
{
FileReader Eingabestrom = new FileReader(string);
BufferedReader input = new BufferedReader(Eingabestrom);
if((Zeile = input.readLine()) != null){
head = Zeile.split(";");
while ((Zeile = input.readLine()) != null)
{
list = Zeile.split(";");
addData(list);
}
}
while (Zeile != null);
input.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void addData(String[] data)
{
Element root = document.getDocumentElement();
try
{
for(int i =0; i<head.length ;i++)
{
Element element = document.createElement(head[i]);
root.appendChild(element);
element.appendChild(document.createTextNode(data[i]));
}
}
catch (DOMException ex)
{
ex.printStackTrace();
}
}
public void speichern(String string)
{
try
{
XMLOutputter outputter = new XMLOutputter();
outputter.output(document,new FileOutputStream(string));
}
catch (IOException e)
{
e.printStackTrace();
}
}
import java.io.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
public class convert
{
static Document document;
String[] list;
String[] head;
public static void main(String string[])
{
convert demo = new convert("C:/temp/test.xml");
demo.createXMLBasic();
demo.loadCSV("d:/test.csv");
demo.speichern("d:/test.xml");
}
public convert(String string)
{
newXMLFile(string);
}
public void newXMLFile(String string)
{
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
document = builder.newDocument();
}
catch (ParserConfigurationException pce)
{
pce.printStackTrace();
}
catch (Throwable t)
{
t.printStackTrace();
}
}
public void createXMLBasic()
{
Element root = document.createElement("Person");
document.appendChild(root);
}
public void loadCSV(String string)
{
// Methode zum Laden von CSV
String zeile = "";
try
{
FileReader Eingabestrom = new FileReader(string);
BufferedReader input = new BufferedReader(Eingabestrom);
if((zeile = input.readLine()) != null){
head = zeile.split(";");
while ((zeile = input.readLine()) != null)
{
list = makeArrayForXML(zeile);
addData(list);
}
}
input.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void addData(String[] data)
{
Element root = document.getDocumentElement();
try
{
for(int i =0; i<head.length ;i++)
{
Element element = document.createElement(head[i]);
root.appendChild(element);
if(!data[i].equals("nullString"))
element.appendChild(document.createTextNode(data[i]));
}
}
catch (DOMException ex)
{
ex.printStackTrace();
}
}
private String[] makeArrayForXML (String zeile){
if(zeile.startsWith(";")){
zeile = ";"+zeile;
}
for(int i = 0; i < 2; i++){
zeile = zeile.replaceAll(";;", ";nullString;");
}
return zeile.split(";");
}
public void speichern(String string)
{
try
{
XMLOutputter outputter = new XMLOutputter();
outputter.output(document,new FileOutputStream(string));
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
*
*/
public class XMLOutputter
{
public void output(Document document, OutputStream out ){
PrintWriter writer = new PrintWriter(out);
travers(document,writer);
writer.close();
}
private void travers(Node node, PrintWriter out){
switch(node.getNodeType()){
case Document.DOCUMENT_NODE:
NodeList list=node.getChildNodes();
out.println("<?xml version='1.0' encoding='iso-8859-1' ?>");
for(int i=0; i< list.getLength();i++){
travers(list.item(i), out);
}
break;
case Document.ELEMENT_NODE:
list=node.getChildNodes();
out.println("<"+node.getNodeName()+">");
for(int i=0; i< list.getLength();i++){
travers(list.item(i), out);
}
out.println("</"+node.getNodeName()+">");
break;
case Document.TEXT_NODE:
out.println(node.getNodeValue());
break;
}
}
}