Java Code Examples for javax.xml.stream.XMLStreamWriter#setNamespaceContext()
The following examples show how to use
javax.xml.stream.XMLStreamWriter#setNamespaceContext() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Marshalling.java From proxymusic with GNU Lesser General Public License v3.0 | 5 votes |
/** * Creates a new {@code MyXMLStreamWriter} object. * * @param writer the real XML stream writer * @param indentValue desired indentation value, if any (null, 0 or n) * * @throws XMLStreamException for any processing error */ public MyStreamWriter (XMLStreamWriter writer, Integer indentValue) throws XMLStreamException { super(writer); writer.setNamespaceContext(nc); INDENT = getIndentString(indentValue); }
Example 2
Source File: CosmoDavException.java From cosmo with Apache License 2.0 | 5 votes |
public void writeTo(XMLStreamWriter writer) throws XMLStreamException { writer.setNamespaceContext(nsc); writer.writeStartElement("DAV:", "error"); for (String uri : nsc.getNamespaceURIs()) { writer.writeNamespace(nsc.getPrefix(uri), uri); } writeContent(writer); writer.writeEndElement(); }
Example 3
Source File: AbstractAegisTest.java From cxf with Apache License 2.0 | 5 votes |
protected ElementWriter getElementWriter(Element element, NamespaceContext namespaceContext) { XMLStreamWriter writer = new W3CDOMStreamWriter(element); try { writer.setNamespaceContext(namespaceContext); } catch (XMLStreamException e) { throw new RuntimeException(e); } return new ElementWriter(writer); }
Example 4
Source File: WriterTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test public void testTwo() { System.out.println("Test StreamWriter's Namespace Context"); try { String outputFile = USER_DIR + files[1] + ".out"; System.out.println("Writing output to " + outputFile); xtw = outputFactory.createXMLStreamWriter(System.out); xtw.writeStartDocument(); xtw.writeStartElement("elemTwo"); xtw.setPrefix("html", "http://www.w3.org/TR/REC-html40"); xtw.writeNamespace("html", "http://www.w3.org/TR/REC-html40"); xtw.writeEndDocument(); NamespaceContext nc = xtw.getNamespaceContext(); // Got a Namespace Context.class XMLStreamWriter xtw1 = outputFactory.createXMLStreamWriter(new FileOutputStream(outputFile), ENCODING); xtw1.writeComment("all elements here are explicitly in the HTML namespace"); xtw1.setNamespaceContext(nc); xtw1.writeStartDocument("utf-8", "1.0"); xtw1.setPrefix("htmlOne", "http://www.w3.org/TR/REC-html40"); NamespaceContext nc1 = xtw1.getNamespaceContext(); xtw1.close(); Iterator it = nc1.getPrefixes("http://www.w3.org/TR/REC-html40"); // FileWriter fw = new FileWriter(outputFile); while (it.hasNext()) { System.out.println("Prefixes :" + it.next()); // fw.write((String)it.next()); // fw.write(";"); } // fw.close(); // assertTrue(checkResults(testTwo+".out", testTwo+".org")); System.out.println("Done"); } catch (Exception ex) { Assert.fail("testTwo Failed " + ex); ex.printStackTrace(); } }