Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
61
Task/XML-Output/Java/xml-output-1.java
Normal file
61
Task/XML-Output/Java/xml-output-1.java
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
import java.io.StringWriter;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Source;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class XmlCreation {
|
||||
|
||||
private static final String[] names = {"April", "Tam O'Shanter", "Emily"};
|
||||
private static final String[] remarks = {"Bubbly: I'm > Tam and <= Emily",
|
||||
"Burns: \"When chapman billies leave the street ...\"",
|
||||
"Short & shrift"};
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// Create a new XML document
|
||||
final Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
|
||||
|
||||
// Append the root element
|
||||
final Element root = doc.createElement("CharacterRemarks");
|
||||
doc.appendChild(root);
|
||||
|
||||
// Read input data and create a new <Character> element for each name.
|
||||
for(int i = 0; i < names.length; i++) {
|
||||
final Element character = doc.createElement("Character");
|
||||
root.appendChild(character);
|
||||
character.setAttribute("name", names[i]);
|
||||
character.appendChild(doc.createTextNode(remarks[i]));
|
||||
}
|
||||
|
||||
// Serializing XML in Java is unnecessary complicated
|
||||
// Create a Source from the document.
|
||||
final Source source = new DOMSource(doc);
|
||||
|
||||
// This StringWriter acts as a buffer
|
||||
final StringWriter buffer = new StringWriter();
|
||||
|
||||
// Create a Result as a transformer target.
|
||||
final Result result = new StreamResult(buffer);
|
||||
|
||||
// The Transformer is used to copy the Source to the Result object.
|
||||
final Transformer transformer = TransformerFactory.newInstance().newTransformer();
|
||||
transformer.setOutputProperty("indent", "yes");
|
||||
transformer.transform(source, result);
|
||||
|
||||
// Now the buffer is filled with the serialized XML and we can print it
|
||||
// to the console.
|
||||
System.out.println(buffer.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
5
Task/XML-Output/Java/xml-output-2.java
Normal file
5
Task/XML-Output/Java/xml-output-2.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<CharacterRemarks>
|
||||
<Character name="April">Bubbly: I'm > Tam and <= Emily</Character>
|
||||
<Character name="Tam O'Shanter">Burns: "When chapman billies leave the street ..."</Character>
|
||||
<Character name="Emily">Short & shrift</Character>
|
||||
38
Task/XML-Output/Java/xml-output-3.java
Normal file
38
Task/XML-Output/Java/xml-output-3.java
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import java.io.StringWriter;
|
||||
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import javax.xml.stream.XMLStreamWriter;
|
||||
|
||||
public class XmlCreationStax {
|
||||
|
||||
private static final String[] names = {"April", "Tam O'Shanter", "Emily"};
|
||||
private static final String[] remarks = {"Bubbly: I'm > Tam and <= Emily",
|
||||
"Burns: \"When chapman billies leave the street ...\"",
|
||||
"Short & shrift"};
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
final StringWriter buffer = new StringWriter();
|
||||
|
||||
final XMLStreamWriter out = XMLOutputFactory.newInstance()
|
||||
.createXMLStreamWriter(buffer);
|
||||
|
||||
out.writeStartDocument("UTF-8", "1.0");
|
||||
out.writeStartElement("CharacterRemarks");
|
||||
|
||||
for(int i = 0; i < names.length; i++) {
|
||||
out.writeStartElement("Character");
|
||||
out.writeAttribute("name", names[i]);
|
||||
out.writeCharacters(remarks[i]);
|
||||
out.writeEndElement();
|
||||
}
|
||||
|
||||
out.writeEndElement();
|
||||
out.writeEndDocument();
|
||||
|
||||
System.out.println(buffer);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
1
Task/XML-Output/Java/xml-output-4.java
Normal file
1
Task/XML-Output/Java/xml-output-4.java
Normal file
|
|
@ -0,0 +1 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><CharacterRemarks><Character name="April">Bubbly: I'm > Tam and <= Emily</Character><Character name="Tam O'Shanter">Burns: "When chapman billies leave the street ..."</Character><Character name="Emily">Short & shrift</Character></CharacterRemarks>
|
||||
Loading…
Add table
Add a link
Reference in a new issue