本文整理汇总了Java中javax.xml.stream.XMLStreamWriter.writeEndElement方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamWriter.writeEndElement方法的具体用法?Java XMLStreamWriter.writeEndElement怎么用?Java XMLStreamWriter.writeEndElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.xml.stream.XMLStreamWriter
的用法示例。
在下文中一共展示了XMLStreamWriter.writeEndElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeGroup
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private void writeGroup(final XMLStreamWriter writer, final Group group) throws XMLStreamException {
List<String> users = new ArrayList<>(group.getUsers());
Collections.sort(users);
writer.writeStartElement(GROUP_ELEMENT);
writer.writeAttribute(IDENTIFIER_ATTR, group.getIdentifier());
writer.writeAttribute(NAME_ATTR, group.getName());
for (String user : users) {
writer.writeStartElement(GROUP_USER_ELEMENT);
writer.writeAttribute(IDENTIFIER_ATTR, user);
writer.writeEndElement();
}
writer.writeEndElement();
}
示例2: writeCurrentLimits
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public static void writeCurrentLimits(Integer index, CurrentLimits limits, XMLStreamWriter writer, String nsUri) throws XMLStreamException {
if (!Float.isNaN(limits.getPermanentLimit())
|| !limits.getTemporaryLimits().isEmpty()) {
if (limits.getTemporaryLimits().isEmpty()) {
writer.writeEmptyElement(nsUri, CURRENT_LIMITS + indexToString(index));
} else {
writer.writeStartElement(nsUri, CURRENT_LIMITS + indexToString(index));
}
XmlUtil.writeFloat("permanentLimit", limits.getPermanentLimit(), writer);
for (CurrentLimits.TemporaryLimit tl : limits.getTemporaryLimits()) {
writer.writeEmptyElement(IIDM_URI, "temporaryLimit");
writer.writeAttribute("name", tl.getName());
XmlUtil.writeOptionalInt("acceptableDuration", tl.getAcceptableDuration(), Integer.MAX_VALUE, writer);
XmlUtil.writeOptionalFloat("value", tl.getValue(), Float.MAX_VALUE, writer);
XmlUtil.writeOptionalBoolean("fictitious", tl.isFictitious(), false, writer);
}
if (!limits.getTemporaryLimits().isEmpty()) {
writer.writeEndElement();
}
}
}
示例3: toXml
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Override
protected void toXml(XMLStreamWriter xmlWriter) throws XMLStreamException {
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement(TAG_INDEX);
xmlWriter.writeAttribute(TAG_NAME, XML_NAME);
xmlWriter.writeStartElement(TAG_CONVERGE);
xmlWriter.writeCharacters(Boolean.toString(converge));
xmlWriter.writeEndElement();
toXml(xmlWriter, TAG_CRITERIA1, criteria1);
toXml(xmlWriter, TAG_CRITERIA2, criteria2);
xmlWriter.writeStartElement(TAG_CRITERIA3);
for (String underVoltageBus : criteria3) {
xmlWriter.writeStartElement(TAG_BUS);
xmlWriter.writeCharacters(underVoltageBus);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
}
示例4: testSAXResult
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Test
public void testSAXResult() {
DefaultHandler handler = new DefaultHandler();
final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"?><root></root>";
try {
SAXResult saxResult = new SAXResult(handler);
// saxResult.setSystemId("jaxp-ri/unit-test/javax/xml/stream/XMLOutputFactoryTest/cr6846132.xml");
XMLOutputFactory ofac = XMLOutputFactory.newInstance();
XMLStreamWriter writer = ofac.createXMLStreamWriter(saxResult);
writer.writeStartDocument("1.0");
writer.writeStartElement("root");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
writer.close();
} catch (Exception e) {
if (e instanceof UnsupportedOperationException) {
// expected
} else {
e.printStackTrace();
Assert.fail(e.toString());
}
}
}
示例5: generateXML
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private void generateXML(XMLStreamWriter writer, String sequence)
throws XMLStreamException {
char[] seqArr = sequence.toCharArray();
writer.writeStartDocument();
writer.writeStartElement("root");
// Use writeCharacters( String ) to write characters
writer.writeStartElement("writeCharactersWithString");
writer.writeCharacters(sequence);
writer.writeEndElement();
// Use writeCharacters( char [], int , int ) to write characters
writer.writeStartElement("writeCharactersWithArray");
writer.writeCharacters(seqArr, 0, seqArr.length);
writer.writeEndElement();
// Close root element and document
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
writer.close();
}
示例6: writeRow
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private void writeRow(final Row row, final XMLStreamWriter out, final Map<String, String> columns) {
try {
int rowIndex = row.getRowNum();
out.writeStartElement("row");
final String rowNum = String.valueOf(rowIndex);
out.writeAttribute("row", rowNum);
int count = 0;
Iterator<Cell> cellIterator = row.iterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
int columnIndex = cell.getColumnIndex();
if (this.exportEmptyCells) {
while (count < columnIndex) {
this.writeAnyCell(rowIndex, count, null, out, columns);
count++;
}
}
this.writeCell(cell, out, columns);
count++;
}
out.writeEndElement();
} catch (XMLStreamException e) {
e.printStackTrace();
}
}
示例7: toXml
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Override
public void toXml(XMLStreamWriter xmlWriter) throws XMLStreamException {
xmlWriter.writeStartDocument();
xmlWriter.writeStartElement("index");
xmlWriter.writeAttribute("name", XML_NAME);
xmlWriter.writeStartElement("synchro-loss-count");
xmlWriter.writeCharacters(Integer.toString(synchroLossCount));
xmlWriter.writeEndElement();
for (Map.Entry<String, Float> e : desynchronizedGenerators.entrySet()) {
String id = e.getKey();
float p = e.getValue();
xmlWriter.writeStartElement(GENERATOR);
xmlWriter.writeAttribute("id", id);
xmlWriter.writeCharacters(Float.toString(p));
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
}
示例8: testStreamWriterWithStAXResultNStreamWriter
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Test
public void testStreamWriterWithStAXResultNStreamWriter() {
final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"?><root></root>";
try {
XMLOutputFactory ofac = XMLOutputFactory.newInstance();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
XMLStreamWriter writer = ofac.createXMLStreamWriter(buffer);
StAXResult res = new StAXResult(writer);
writer = ofac.createXMLStreamWriter(res);
writer.writeStartDocument("1.0");
writer.writeStartElement("root");
writer.writeEndElement();
writer.writeEndDocument();
writer.close();
Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.toString());
}
}
示例9: writeRelation
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private void writeRelation(XMLStreamWriter xmlStreamWriter, DatasetConfig datasetConfig) throws XMLStreamException {
DatasetPath dataset = new DatasetPath(datasetConfig.getFullPathList());
final String name = dataset.getLeaf().getName();
// If dataset schema contains a dot '.' in one of its component
// Tableau won't be able to open it
final String schema = Joiner.on('.').join(dataset.toParentPathList());
xmlStreamWriter.writeStartElement("relation");
xmlStreamWriter.writeAttribute("name", name);
xmlStreamWriter.writeAttribute("type", "table");
xmlStreamWriter.writeAttribute("table", format("[%s].[%s]", tableauEncode(schema), tableauEncode(name)));
xmlStreamWriter.writeEndElement();
}
示例10: print
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
* Outputs a Smile representation of {@code fields} to {@code output}.
*/
public void print(final UnknownFieldSet fields, OutputStream output, Charset cs) throws IOException {
try {
XMLStreamWriter generator = createGenerator(output);
generator.writeStartElement(MESSAGE_ELEMENT);
printUnknownFields(fields, generator);
generator.writeEndElement();
generator.close();
} catch (XMLStreamException e) {
throw new IOException(e);
}
}
示例11: writeXml
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public static void writeXml(Path configDir, Path xmlFile) throws IOException, XMLStreamException {
XMLOutputFactory output = XMLOutputFactory.newInstance();
try (Writer writer = Files.newBufferedWriter(xmlFile, StandardCharsets.UTF_8)) {
XMLStreamWriter xmlWriter = output.createXMLStreamWriter(writer);
try {
xmlWriter.writeStartDocument(StandardCharsets.UTF_8.toString(), "1.0");
xmlWriter.writeStartElement("config");
try (DirectoryStream<Path> ds = Files.newDirectoryStream(configDir, entry -> Files.isRegularFile(entry) && entry.getFileName().toString().endsWith(".properties"))) {
for (Path file : ds) {
String fileName = file.getFileName().toString();
String fileNameWithoutExtension = fileName.substring(0, fileName.length() - 11);
xmlWriter.writeStartElement(fileNameWithoutExtension);
Properties properties = new Properties();
try (Reader reader = Files.newBufferedReader(file, StandardCharsets.UTF_8)) {
properties.load(reader);
}
for (String name : properties.stringPropertyNames()) {
String value = properties.getProperty(name);
xmlWriter.writeStartElement(name);
xmlWriter.writeCharacters(value);
xmlWriter.writeEndElement();
}
xmlWriter.writeEndElement();
}
}
xmlWriter.writeEndElement();
xmlWriter.writeEndDocument();
} finally {
xmlWriter.close();
}
}
}
示例12: writePolicy
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private void writePolicy(final XMLStreamWriter writer, final AccessPolicy policy) throws XMLStreamException {
// sort the users for the policy
List<String> policyUsers = new ArrayList<>(policy.getUsers());
Collections.sort(policyUsers);
// sort the groups for this policy
List<String> policyGroups = new ArrayList<>(policy.getGroups());
Collections.sort(policyGroups);
writer.writeStartElement(POLICY_ELEMENT);
writer.writeAttribute(IDENTIFIER_ATTR, policy.getIdentifier());
writer.writeAttribute(RESOURCE_ATTR, policy.getResource());
writer.writeAttribute(ACTIONS_ATTR, policy.getAction().name());
for (String policyUser : policyUsers) {
writer.writeStartElement(POLICY_USER_ELEMENT);
writer.writeAttribute(IDENTIFIER_ATTR, policyUser);
writer.writeEndElement();
}
for (String policyGroup : policyGroups) {
writer.writeStartElement(POLICY_GROUP_ELEMENT);
writer.writeAttribute(IDENTIFIER_ATTR, policyGroup);
writer.writeEndElement();
}
writer.writeEndElement();
}
示例13: writeTo
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public void writeTo(XMLStreamWriter writer) throws XMLStreamException {
try {
writer.writeStartDocument();
if (!parsedMessage) {
DOMUtil.serializeNode(sm.getSOAPPart().getEnvelope(), writer);
} else {
SOAPEnvelope env = sm.getSOAPPart().getEnvelope();
DOMUtil.writeTagWithAttributes(env, writer);
if (hasHeaders()) {
if(env.getHeader() != null) {
DOMUtil.writeTagWithAttributes(env.getHeader(), writer);
} else {
writer.writeStartElement(env.getPrefix(), "Header", env.getNamespaceURI());
}
for (Header h : headers.asList()) {
h.writeTo(writer);
}
writer.writeEndElement();
}
DOMUtil.serializeNode(sm.getSOAPBody(), writer);
writer.writeEndElement();
}
writer.writeEndDocument();
writer.flush();
} catch (SOAPException ex) {
throw new XMLStreamException2(ex);
//for now. ask jaxws team what to do.
}
}
示例14: writeTo
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
* Default implementation that relies on {@link #writePayloadTo(XMLStreamWriter)}
*/
@Override
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
writeToBodyStart(w);
writePayloadTo(w);
w.writeEndElement();
w.writeEndElement();
w.writeEndDocument();
}
示例15: writeValue
import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
protected void writeValue(Map<String,Object> object, XMLStreamWriter writer) throws IOException, XMLStreamException {
for (Map.Entry<String,Object> entry: object.entrySet()) {
writer.writeStartElement(entry.getKey().replaceAll(XML_NAME_CHARS_REGEX, "_"));
writeValue(entry.getValue(), writer);
writer.writeEndElement();
}
}