List of usage examples for javax.xml.stream XMLStreamWriter writeStartElement
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException;
From source file:MainClass.java
public static void main(String[] args) throws XMLStreamException { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.writeStartDocument("1.0"); writer.writeStartElement("http://www.t.com/f", "sample"); writer.writeAttribute("attribute", "true"); writer.writeAttribute("http://www.t.com/f", "attribute2", "false"); writer.writeCharacters("some text"); writer.writeCData("<test>"); writer.writeEndElement();//from w w w . j a va 2 s. c o m writer.writeEndDocument(); writer.flush(); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); XMLStreamWriter writer = outputFactory.createXMLStreamWriter(System.out); writer.setDefaultNamespace("http://www.example.com/ns1"); writer.writeStartElement("http://www.example.com/ns1", "sample"); writer.writeDefaultNamespace("http://www.example.com/ns1"); writer.writeEmptyElement("inner"); writer.setDefaultNamespace("http://www.example.com/ns2"); writer.writeStartElement("http://www.example.com/ns2", "inner2"); writer.writeDefaultNamespace("http://www.example.com/ns2"); writer.writeNamespace("ns1", "http://www.example.com/ns1"); writer.writeEmptyElement("http://www.example.com/ns1", "inner"); writer.writeEndDocument();/*w w w . ja va2 s . co m*/ writer.flush(); }
From source file:CursorWriter.java
public static void main(String[] args) throws Exception { String fileName = "yourXML.xml"; XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xtw = null; xtw = xof.createXMLStreamWriter(new FileWriter(fileName)); xtw.writeComment("all elements here are explicitly in the HTML namespace"); xtw.writeStartDocument("utf-8", "1.0"); xtw.setPrefix("html", "http://www.w3.org/TR/REC-html40"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "html"); xtw.writeNamespace("html", "http://www.w3.org/TR/REC-html40"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "head"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "title"); xtw.writeCharacters("character"); xtw.writeEndElement();/*from w w w . j av a 2s . c o m*/ xtw.writeEndElement(); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "body"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "p"); xtw.writeCharacters("another character"); xtw.writeStartElement("http://www.w3.org/TR/REC-html40", "a"); xtw.writeAttribute("href", "http://www.java2s.com"); xtw.writeCharacters("here"); xtw.writeEndElement(); xtw.writeEndElement(); xtw.writeEndElement(); xtw.writeEndElement(); xtw.writeEndDocument(); xtw.flush(); xtw.close(); System.out.println("Done"); }
From source file:Main.java
public static void main(String[] args) throws Exception { XMLStreamWriter writer = XMLOutputFactory.newFactory().createXMLStreamWriter(System.out); writer.setDefaultNamespace("http://www.java2s.com"); JAXBContext jc = JAXBContext.newInstance(WorkSet.class); Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); writer.writeStartDocument();//from w w w. ja v a 2s. co m writer.writeStartElement("http://www.java2s.com", "Import"); writer.writeNamespace("", "http://www.java2s.com"); writer.writeStartElement("WorkSets"); m.marshal(new WorkSet(), writer); m.marshal(new WorkSet(), writer); writer.writeEndDocument(); writer.close(); }
From source file:com.rockhoppertech.music.midi.js.xml.ModeFactoryXMLHelper.java
public static void write(List<Scale> modeList, String fileName) { XMLOutputFactory xof = XMLOutputFactory.newInstance(); XMLStreamWriter xtw = null; // <mode> // <name>Peruvian tritonic 2</name> // <interval>3</interval> // <interval>4</interval> // <interval>5</interval> // </mode> String ns = "http://rockhoppertech.com/modes-1.0"; // StringWriter sw = new StringWriter(); try {//from w ww. ja v a 2 s .c o m xtw = xof.createXMLStreamWriter(new FileWriter(fileName)); // xtw = xof.createXMLStreamWriter(sw); xtw.writeComment("all elements here are explicitly in the mode namespace"); xtw.writeStartDocument("utf-8", "1.0"); xtw.setPrefix("modes", ns); xtw.writeStartElement(ns, "modes"); xtw.writeNamespace("modes", ns); for (Scale scale : modeList) { // xtw.writeStartElement(ns, "mode"); xtw.writeStartElement("mode"); // xtw.writeStartElement(ns, "name"); xtw.writeStartElement("name"); xtw.writeCharacters(scale.getName()); xtw.writeEndElement(); // xtw.writeStartElement(ns, "intervals"); // xtw.writeStartElement(ns, "interval"); xtw.writeStartElement("intervals"); int[] intervals = scale.getIntervals(); for (int i = 0; i < intervals.length; i++) { xtw.writeStartElement("interval"); xtw.writeCharacters("" + intervals[i]); xtw.writeEndElement(); } xtw.writeEndElement(); // intervals xtw.writeEndElement(); // mode } xtw.writeEndElement(); // modes xtw.writeEndDocument(); xtw.flush(); xtw.close(); // System.err.println(sw.toString()); } catch (XMLStreamException | IOException e) { logger.error(e.getLocalizedMessage(), e); e.printStackTrace(); } }
From source file:org.unitedinternet.cosmo.dav.CosmoDavException.java
protected void writeContent(XMLStreamWriter writer) throws XMLStreamException { writer.writeStartElement(NS_COSMO, "internal-server-error"); if (getMessage() != null) { writer.writeCharacters(getMessage()); }/*from w ww .j ava2s . c om*/ writer.writeEndElement(); }
From source file:org.unitedinternet.cosmo.dav.CosmoDavException.java
public void writeTo(XMLStreamWriter writer) throws XMLStreamException { writer.setNamespaceContext(nsc);/*from w ww . j a va2 s . c o m*/ writer.writeStartElement("DAV:", "error"); for (String uri : nsc.getNamespaceURIs()) { writer.writeNamespace(nsc.getPrefix(uri), uri); } writeContent(writer); writer.writeEndElement(); }
From source file:com.pocketsoap.salesforce.soap.SoapRequestEntity.java
protected void writeElementString(XMLStreamWriter w, String elemNamespace, String elemName, String elemValue) throws XMLStreamException { if (elemValue == null) return;//w ww. ja va 2 s.c o m w.writeStartElement(elemNamespace, elemName); w.writeCharacters(elemValue); w.writeEndElement(); }
From source file:com.adobe.acs.commons.wcm.impl.SiteMapServlet.java
private void writeElement(final XMLStreamWriter stream, final String elementName, final String text) throws XMLStreamException { stream.writeStartElement(NS, elementName); stream.writeCharacters(text);// w w w. ja va 2 s. c o m stream.writeEndElement(); }
From source file:com.adobe.acs.commons.wcm.impl.SiteMapServlet.java
private void writeAsset(Asset asset, XMLStreamWriter stream, ResourceResolver resolver) throws XMLStreamException { stream.writeStartElement(NS, "url"); String loc = externalizer.externalLink(resolver, externalizerDomain, asset.getPath()); writeElement(stream, "loc", loc); if (includeLastModified) { long lastModified = asset.getLastModified(); if (lastModified > 0) { writeElement(stream, "lastmod", DATE_FORMAT.format(lastModified)); }//from w w w .j a v a 2 s .c o m } Resource contentResource = asset.adaptTo(Resource.class).getChild(JcrConstants.JCR_CONTENT); if (contentResource != null) { if (includeInheritValue) { HierarchyNodeInheritanceValueMap hierarchyNodeInheritanceValueMap = new HierarchyNodeInheritanceValueMap( contentResource); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, hierarchyNodeInheritanceValueMap); writeFirstPropertyValue(stream, "priority", priorityProperties, hierarchyNodeInheritanceValueMap); } else { ValueMap properties = contentResource.getValueMap(); writeFirstPropertyValue(stream, "changefreq", changefreqProperties, properties); writeFirstPropertyValue(stream, "priority", priorityProperties, properties); } } stream.writeEndElement(); }