Java 类javax.xml.stream.XMLStreamWriter 实例源码

项目:powsybl-core    文件:TsoOvervoltageSecurityIndex.java   
@Override
public void toXml(XMLStreamWriter xmlWriter) throws XMLStreamException {
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("index");
    xmlWriter.writeAttribute("name", XML_NAME);

    xmlWriter.writeStartElement("computation-succeed");
    xmlWriter.writeCharacters(Boolean.toString(computationSucceed));
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("overvoltage-count");
    xmlWriter.writeCharacters(Integer.toString(overvoltageCount));
    xmlWriter.writeEndElement();

    xmlWriter.writeEndElement();
    xmlWriter.writeEndDocument();
}
项目:openjdk-jdk10    文件:XMLStreamWriterTest.java   
/**
 * Test of main method, of class TestXMLStreamWriter.
 */
@Test
public void testWriteComment() {
    try {
        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><a:html href=\"http://java.sun.com\"><!--This is comment-->java.sun.com</a:html>";
        XMLOutputFactory f = XMLOutputFactory.newInstance();
        // f.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES,
        // Boolean.TRUE);
        StringWriter sw = new StringWriter();
        XMLStreamWriter writer = f.createXMLStreamWriter(sw);
        writer.writeStartDocument("UTF-8", "1.0");
        writer.writeStartElement("a", "html", "http://www.w3.org/TR/REC-html40");
        writer.writeAttribute("href", "http://java.sun.com");
        writer.writeComment("This is comment");
        writer.writeCharacters("java.sun.com");
        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
        sw.flush();
        StringBuffer sb = sw.getBuffer();
        System.out.println("sb:" + sb.toString());
        Assert.assertTrue(sb.toString().equals(xml));
    } catch (Exception ex) {
        Assert.fail("Exception: " + ex.getMessage());
    }
}
项目:powsybl-core    文件:GeographicalRegion.java   
/**
 * Utility to return the content of this class into the CIM XML format
 *
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
private void writeClass(XMLStreamWriter xmlsw) {

    if (currentBitset.get(0)) {
  for (SubGeographicalRegion regions : this.regions){
           try {
             xmlsw.writeEmptyElement(CIMURI.CIMURI,"GeographicalRegion.Regions");
             xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                       + regions.getId());
           } catch (XMLStreamException e) {
             StringBuilder errorMessage = new StringBuilder(
                                "Error while trying to write the reference to ");
             errorMessage.append("GeographicalRegion ");
             errorMessage.append("which ID has been initialized to : ");
             errorMessage.append(getId());
             errorMessage.append(" in the subset ");
             errorMessage.append("Equipment");
             LOGGER.error(errorMessage.toString());
             LOGGER.error(e.toString(), e);
           }
  }
    }

    return;
}
项目:powsybl-core    文件:ConnectivityNodeContainer.java   
/**
 * Utility to write the content into the CIM XML format
 *
 * @param writeID
 *            specifies whether to write the XML "id" attribute (this is used for describing concrete class)
 * @param xmlsw
 *            XMLStreamWriter where are stored the elements to write
 */
@Override
public void write(XMLStreamWriter xmlsw, boolean writeID) {

    /*
     * In previous versions, we used to check the consistency
     * of the instance in the context but this task is now
     * performed by the model before attempting to write.
     * Therefore each instance can now be written even if
     * it is not consistent !
     */

    writeClass(xmlsw);
    super.write(xmlsw, false);
    return;
}
项目:OpenJSharp    文件:XMLCodec.java   
public ContentType encode(Packet packet, OutputStream out) {
            String encoding = (String) packet.invocationProperties
            .get(XMLConstants.OUTPUT_XML_CHARACTER_ENCODING);

    XMLStreamWriter writer = null;

            if (encoding != null && encoding.length() > 0) {
        writer = XMLStreamWriterFactory.create(out, encoding);
    } else {
        writer = XMLStreamWriterFactory.create(out);
    }

    try {
        if (packet.getMessage().hasPayload()){
            writer.writeStartDocument();
            packet.getMessage().writePayloadTo(writer);
            writer.flush();
        }
    } catch (XMLStreamException e) {
        throw new WebServiceException(e);
    }
    return contentType;
}
项目:powsybl-core    文件:EquivalentEquipment.java   
/**
 * Utility to write the content into the CIM XML format
 *
 * @param writeID
 *            specifies whether to write the XML "id" attribute (this is used for describing concrete class)
 * @param xmlsw
 *            XMLStreamWriter where are stored the elements to write
 */
@Override
public void write(XMLStreamWriter xmlsw, boolean writeID) {

    /*
     * In previous versions, we used to check the consistency
     * of the instance in the context but this task is now
     * performed by the model before attempting to write.
     * Therefore each instance can now be written even if
     * it is not consistent !
     */

    writeClass(xmlsw);
    super.write(xmlsw, false);
    return;
}
项目:powsybl-core    文件:Conductor.java   
/**
 * Utility to write the content this class into the CIM/XML format according
 * to a subset
 *
 * @param subset
 *            the subset defining the context in which to write this class
 * @param writeID
 *            specifies whether to write the XML "id" attribute (this is used for describing concrete class)
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
@Override
public void write(XMLStreamWriter xmlsw, final Subset subset,
        boolean writeID) {

    /*
     * In previous versions, we used to check the consistency
     * of the instance in the context but this task is now
     * performed by the model before attempting to write.
     * Therefore each instance can now be written even if
     * it is not consistent !
     */

    // abstract class
    writeClass(xmlsw);
    super.write(xmlsw, subset, false);
    return;
}
项目:powsybl-core    文件:Line.java   
/**
 * Utility to write the content this class into the CIM/XML format according
 * to a subset
 *
 * @param subset
 *            the subset defining the context in which to write this class
 * @param writeID
 *            specifies whether to write the XML "id" attribute (this is used for describing concrete class)
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
@Override
public void write(XMLStreamWriter xmlsw, final Subset subset,
        boolean writeID) {

    /*
     * In previous versions, we used to check the consistency
     * of the instance in the context but this task is now
     * performed by the model before attempting to write.
     * Therefore each instance can now be written even if
     * it is not consistent !
     */

    // abstract class
    writeClass(xmlsw);
    super.write(xmlsw, subset, false);
    return;
}
项目:powsybl-core    文件:RegulatingCondEq.java   
/**
 * Utility to write the content this class into the CIM/XML format according
 * to a subset
 *
 * @param subset
 *            the subset defining the context in which to write this class
 * @param writeID
 *            specifies whether to write the XML "id" attribute (this is used for describing concrete class)
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
@Override
public void write(XMLStreamWriter xmlsw, final Subset subset,
        boolean writeID) {

    /*
     * In previous versions, we used to check the consistency
     * of the instance in the context but this task is now
     * performed by the model before attempting to write.
     * Therefore each instance can now be written even if
     * it is not consistent !
     */

    // abstract class
    writeClass(xmlsw);
    super.write(xmlsw, subset, false);
    return;
}
项目:openjdk-jdk10    文件:UnprefixedNameTest.java   
@Test
public void testBoundPrefix() throws Exception {

    try {
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        XMLStreamWriter w = xof.createXMLStreamWriter(System.out);
        // here I'm trying to write
        // <bar xmlns="foo" />
        w.writeStartDocument();
        w.writeStartElement("foo", "bar", "http://namespace");
        w.writeCharacters("---");
        w.writeEndElement();
        w.writeEndDocument();
        w.close();

        // Expected success
        System.out.println("Expected success.");
    } catch (Exception exception) {
        // Unexpected Exception
        String FAIL_MSG = "Unexpected Exception: " + exception.toString();
        System.err.println(FAIL_MSG);
        Assert.fail(FAIL_MSG);
    }
}
项目:powsybl-core    文件:Curve.java   
/**
 * Utility to return the content of this class into the CIM XML format
 *
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
private void writeClass(XMLStreamWriter xmlsw) {

    if (currentBitset.get(0)) {
  for (CurveData curveScheduleDatas : this.curveScheduleDatas){
           try {
             xmlsw.writeEmptyElement(CIMURI.CIMURI,"Curve.CurveScheduleDatas");
             xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                       + curveScheduleDatas.getId());
           } catch (XMLStreamException e) {
             StringBuilder errorMessage = new StringBuilder(
                                "Error while trying to write the reference to ");
             errorMessage.append("Curve ");
             errorMessage.append("which ID has been initialized to : ");
             errorMessage.append(getId());
             errorMessage.append(" in the subset ");
             errorMessage.append("${subsetModel.getSubset($class).getName()}");
             LOGGER.error(errorMessage.toString());
             LOGGER.error(e.toString(), e);
           }
  }
    }

    return;
}
项目:powsybl-core    文件:VoltageControlZone.java   
/**
 * Utility to write the content into the CIM XML format
 *
 * @param writeID
 *            specifies whether to write the XML "id" attribute (this is used for describing concrete class)
 * @param xmlsw
 *            XMLStreamWriter where are stored the elements to write
 */
@Override
public void write(XMLStreamWriter xmlsw, boolean writeID) {

    /*
     * In previous versions, we used to check the consistency
     * of the instance in the context but this task is now
     * performed by the model before attempting to write.
     * Therefore each instance can now be written even if
     * it is not consistent !
     */

    writeClass(xmlsw);
    super.write(xmlsw, false);
    return;
}
项目:powsybl-core    文件:PowerTransformer.java   
/**
 * Utility to return the content of this class into the CIM XML format
 *
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
private void writeClass(XMLStreamWriter xmlsw) {

    if (currentBitset.get(0)) {
  for (TransformerWinding contains_TransformerWindings : this.contains_TransformerWindings){
           try {
             xmlsw.writeEmptyElement(CIMURI.CIMURI,"PowerTransformer.Contains_TransformerWindings");
             xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                       + contains_TransformerWindings.getId());
           } catch (XMLStreamException e) {
             StringBuilder errorMessage = new StringBuilder(
                                "Error while trying to write the reference to ");
             errorMessage.append("PowerTransformer ");
             errorMessage.append("which ID has been initialized to : ");
             errorMessage.append(getId());
             errorMessage.append(" in the subset ");
             errorMessage.append("Equipment");
             LOGGER.error(errorMessage.toString());
             LOGGER.error(e.toString(), e);
           }
  }
    }

    return;
}
项目:powsybl-core    文件:AbstractConnectableXml.java   
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();
        }
    }
}
项目:powsybl-core    文件:MultiCriteriaVoltageStabilityIndex.java   
@Override
protected void toXml(XMLStreamWriter xmlWriter) throws XMLStreamException {
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement(TAG_INDEX);
    xmlWriter.writeAttribute(TAG_NAME, XML_NAME);
    toXml(xmlWriter, TAG_LOCKED_TAP_CHANGER_LOAD, lockedTapChangerLoads);
    toXml(xmlWriter, TAG_STOPPED_TAP_CHANGER_LOAD, stoppedTapChangerLoads);
    toXml(xmlWriter, TAG_UNDER_VOLTAGE_AUTOMATON_GENERATOR, underVoltageAutomatonGenerators);

    for (String underVoltageBus : underVoltageBuses) {
        xmlWriter.writeStartElement(TAG_UNDER_BUS_VOLTAGE);
        xmlWriter.writeCharacters(underVoltageBus);
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();
    xmlWriter.writeEndDocument();
}
项目:powsybl-core    文件:TsoSynchroLossSecurityIndex.java   
@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();
}
项目:alevin-svn2    文件:XMLExporter.java   
static void exportDemand(XMLStreamWriter writer, AbstractDemand ad, String type, String exportId) throws XMLStreamException {
    writer.writeStartElement(type);
    writer.writeAttribute("type", ad.getClass().getSimpleName());
    if (exportId != null)
        writer.writeAttribute("exportId", exportId);
    //Export additional construction parameters
    exportConstructParameters(writer, ad);
    exportParameters(writer, ad);
    exportMappings(writer, ad);
    writer.writeEndElement();//End of Demand
}
项目:openjdk-jdk10    文件:OldBridge.java   
public final void marshal(T object,XMLStreamWriter output, AttachmentMarshaller am) throws JAXBException {
    Marshaller m = context.marshallerPool.take();
    m.setAttachmentMarshaller(am);
    marshal(m,object,output);
    m.setAttachmentMarshaller(null);
    context.marshallerPool.recycle(m);
}
项目:alevin-svn2    文件:XMLExporter.java   
/**
 * This Method exports the Mappings
 * 
 * @param writer WriterObject
 * @param ad Demand
 * @throws XMLStreamException 
 */
static void exportMappings(XMLStreamWriter writer, AbstractDemand ad) throws XMLStreamException {
    for(Mapping map : ad.getMappings()) {
        String type = map.getResource().getClass().getSimpleName();
        long entityID = map.getResource().getOwner().getId();

        writer.writeEmptyElement("Mapping");
        writer.writeAttribute("resourceType", type);
        writer.writeAttribute("substrateEntity", entityID+"");
    }

}
项目:hashsdn-controller    文件:NormalizedNodeXMLOutput.java   
public static void toStream(OutputStream outStream, NormalizedNode<?, ?> node)
        throws XMLStreamException, IOException {
    XMLStreamWriter xmlWriter = XOF.createXMLStreamWriter(outStream);

    IndentingXMLStreamWriter indenting = new IndentingXMLStreamWriter(xmlWriter);
    try (NormalizedNodeStreamWriter streamWriter = XMLStreamNormalizedNodeStreamWriter.createSchemaless(
            indenting)) {
        NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(streamWriter);
        nodeWriter.write(node);
        nodeWriter.flush();
    }
}
项目:OpenJSharp    文件:DOMMessage.java   
public void writePayloadTo(XMLStreamWriter sw) {
    try {
        if (payload != null)
            DOMUtil.serializeNode(payload, sw);
    } catch (XMLStreamException e) {
        throw new WebServiceException(e);
    }
}
项目:powsybl-core    文件:PropertiesPlatformConfig.java   
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();
        }
    }
}
项目:dremio-oss    文件:TableauMessageBodyGenerator.java   
private void writeDatasource(final XMLStreamWriter xmlStreamWriter, DatasetConfig datasetConfig, String hostname, MediaType mediaType) throws XMLStreamException {
  xmlStreamWriter.writeStartElement("datasource");
  xmlStreamWriter.writeAttribute("inline", "true");

  if (WebServer.MediaType.APPLICATION_TDS_TYPE.equals(mediaType)) {
    writeConnection(xmlStreamWriter, datasetConfig, hostname);
  } else if (WebServer.MediaType.APPLICATION_TDS_DRILL_TYPE.equals(mediaType)) {
    writeNativeDrillConnection(xmlStreamWriter, datasetConfig, hostname);
  } else {
    throw new RuntimeException("Unsupported media type " + mediaType);
  }

  xmlStreamWriter.writeEndElement();
}
项目:powsybl-core    文件:BusbarSection.java   
/**
 * Utility to return the content of this class into the CIM XML format
 *
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
private void writeClass(XMLStreamWriter xmlsw) {

    if (currentBitset.get(0)) {

/*
 * Careful here : we may write an association "twice" if
 * the association is 1..1 one and if
 * both ends belong to the same subset
 */

    if (idVoltageControlZone != null &&
            !idVoltageControlZone.isEmpty()) {

        try {
            // xmlsw.writeCharacters("\t");
            xmlsw.writeEmptyElement(CIMURI.CIMURI,
                    "BusbarSection.VoltageControlZone");
            xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                    + idVoltageControlZone);
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the resource attribute ");
            errorMessage.append("VoltageControlZone");
            errorMessage.append(" in class ");
            errorMessage.append("BusbarSection ");
            errorMessage.append("which ID has been initialized to : ");
            errorMessage.append(getId());
            LOGGER.error(errorMessage.toString());
            LOGGER.error(e.toString(), e);
        }
    }
    }

    return;
}
项目:openjdk-jdk10    文件:SourceUtils.java   
/**
 * sets undeclared prefixes on the writer
 * @param prefix
 * @param writer
 * @throws XMLStreamException
 */
private static void setUndeclaredPrefix(String prefix, String readerURI, XMLStreamWriter writer) throws XMLStreamException {
    String writerURI = null;
    if (writer.getNamespaceContext() != null) {
        writerURI = writer.getNamespaceContext().getNamespaceURI(prefix);
    }

    if (writerURI == null) {
        writer.setPrefix(prefix, readerURI != null ? readerURI : "");
        writer.writeNamespace(prefix, readerURI != null ? readerURI : "");
    }
}
项目:powsybl-core    文件:CurrentLimit.java   
/**
 * Utility to return the content of this class into the CIM XML format
 *
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
private void writeClass(XMLStreamWriter xmlsw) {

    if (currentBitset.get(0)) {

    try {
        // xmlsw.writeCharacters("\t");
        xmlsw.writeStartElement(CIMURI.CIMURI,
                "CurrentLimit.value");
        xmlsw.writeCharacters(String.valueOf(getValue()));
        xmlsw.writeEndElement();
        // xmlsw.writeCharacters("\n");
    } catch(XMLStreamException e) {
        StringBuilder errorMessage = new StringBuilder(
                "Error while trying to write the value of the attribute ");
        errorMessage.append("Value");
        errorMessage.append(" in class ");
        errorMessage.append("CurrentLimit ");
        errorMessage.append("which ID has been initialized to : ");
        errorMessage.append(getId());
        LOGGER.error(errorMessage.toString());
        LOGGER.error(e.toString(), e);
    }
    }

    return;
}
项目:openjdk-jdk10    文件:DOMMessage.java   
public void writePayloadTo(XMLStreamWriter sw) {
    try {
        if (payload != null)
            DOMUtil.serializeNode(payload, sw);
    } catch (XMLStreamException e) {
        throw new WebServiceException(e);
    }
}
项目:OpenJSharp    文件:DXMLPrinter.java   
/**
 * @param out Output stream.
 */
public DXMLPrinter(XMLStreamWriter out) {
    this.out = out;
    this.visitor = new DXMLPrinterVisitor();
    this.ncVisitor = new NameClassXMLPrinterVisitor();
    this.domPrinter = new DOMPrinter(out);
}
项目:openjdk-jdk10    文件:StreamWriterBufferProcessor.java   
public void process(XMLStreamWriter writer) throws XMLStreamException {
    if(_fragmentMode){
        writeFragment(writer);
    }else{
        write(writer);
    }
}
项目:powsybl-core    文件:RegulatingCondEq.java   
/**
 * Utility to return the content of this class into the CIM XML format
 *
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
private void writeClass(XMLStreamWriter xmlsw) {

    if (currentBitset.get(0)) {
    if (idRegulatingControl != null) {
        try {
            // xmlsw.writeCharacters("\t");
            xmlsw.writeEmptyElement(CIMURI.CIMURI,
                    "RegulatingCondEq.RegulatingControl");
            xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                    + idRegulatingControl);
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the resource attribute ");
            errorMessage.append("RegulatingControl");
            errorMessage.append(" in class ");
            errorMessage.append("RegulatingCondEq ");
            errorMessage.append("which ID has been initialized to : ");
            errorMessage.append(getId());
            LOGGER.error(errorMessage.toString());
            LOGGER.error(e.toString(), e);
        }
    }
    }

    return;
}
项目:OpenJSharp    文件:ProblemActionHeader.java   
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
    w.writeStartElement("", getLocalPart(), getNamespaceURI());
    w.writeDefaultNamespace(getNamespaceURI());
    w.writeStartElement(actionLocalName);
    w.writeCharacters(action);
    w.writeEndElement();
    if (soapAction != null) {
        w.writeStartElement(soapActionLocalName);
        w.writeCharacters(soapAction);
        w.writeEndElement();
    }
    w.writeEndElement();
}
项目:openjdk-jdk10    文件:Bug6452107.java   
/**
 * Ensure that charset aliases are checked. The encoding ISO-8859-1 is
 * returned as ISO8859_1 by the underlying writer. Thus, if alias are not
 * inspected, this test throws an exception.
 */
@Test
public void test() {
    final String ENCODING = "ISO-8859-1";

    try {
        OutputStream out = new ByteArrayOutputStream();
        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLStreamWriter writer = factory.createXMLStreamWriter(out, ENCODING);
        writer.writeStartDocument(ENCODING, "1.0");
    } catch (XMLStreamException e) {
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
项目:OpenJSharp    文件:XMLStreamWriterUtil.java   
/**
 * Gives the encoding with which XMLStreamWriter is created.
 *
 * @param writer XMLStreamWriter for which encoding is required
 * @return null if cannot be found, else the encoding
 */
public static @Nullable String getEncoding(XMLStreamWriter writer) {
    /*
     * TODO Add reflection logic to handle woodstox writer
     * as it implements XMLStreamWriter2#getEncoding()
     * It's not that important since woodstox writer is typically wrapped
     * in a writer with HasEncoding
     */
    return (writer instanceof HasEncoding)
            ? ((HasEncoding)writer).getEncoding()
            : null;
}
项目:amelia    文件:XMLController.java   
public void createInitXML(String xml_path,String subnet,String count) throws SAXException, ParserConfigurationException, IOException, XMLStreamException{
    XMLOutputFactory xof =  XMLOutputFactory.newInstance();
    XMLStreamWriter xtw = null;
    xtw = xof.createXMLStreamWriter(new FileWriter("init.xml"));
    xtw.writeStartDocument("utf-8","1.0");
    xtw.writeCharacters("\n");
    xtw.writeStartElement("SETTINGS");
    xtw.writeCharacters("\n");
    xtw.writeStartElement("XML_PATH");
    xtw.writeCharacters("\n");
    xtw.writeCharacters(xml_path);
    xtw.writeCharacters("\n");
    xtw.writeEndElement();
    xtw.writeCharacters("\n");
    xtw.writeStartElement("SUBNET");
    xtw.writeCharacters("\n");
    xtw.writeCharacters(subnet);
    xtw.writeCharacters("\n");
    xtw.writeEndElement();
    xtw.writeCharacters("\n");
    xtw.writeStartElement("count");
    xtw.writeCharacters("\n");
    xtw.writeCharacters(count);
    xtw.writeCharacters("\n");
    xtw.writeEndElement();
    xtw.writeCharacters("\n");
    xtw.writeEndElement();
    xtw.writeCharacters("\n");
    xtw.writeEndDocument();
    xtw.flush();
    xtw.close();
}
项目:OpenJSharp    文件:SourceUtils.java   
/**
 * sets undeclared prefixes on the writer
 * @param prefix
 * @param writer
 * @throws XMLStreamException
 */
private static void setUndeclaredPrefix(String prefix, String readerURI, XMLStreamWriter writer) throws XMLStreamException {
    String writerURI = null;
    if (writer.getNamespaceContext() != null) {
        writerURI = writer.getNamespaceContext().getNamespaceURI(prefix);
    }

    if (writerURI == null) {
        writer.setPrefix(prefix, readerURI != null ? readerURI : "");
        writer.writeNamespace(prefix, readerURI != null ? readerURI : "");
    }
}
项目:powsybl-core    文件:RatioTapChanger.java   
/**
 * Utility to return the content of this class into the CIM XML format
 *
 * @param xmlsw
 *            the stream in which are stored the elements to write
 */
private void writeClass(XMLStreamWriter xmlsw) {

    if (currentBitset.get(0)) {

/*
 * Careful here : we may write an association "twice" if
 * the association is 1..1 one and if
 * both ends belong to the same subset
 */

    if (idTransformerWinding != null &&
            !idTransformerWinding.isEmpty()) {

        try {
            // xmlsw.writeCharacters("\t");
            xmlsw.writeEmptyElement(CIMURI.CIMURI,
                    "RatioTapChanger.TransformerWinding");
            xmlsw.writeAttribute(CIMModel.rdfURI, "resource", "#"
                    + idTransformerWinding);
            // xmlsw.writeCharacters("\n");
        } catch(XMLStreamException e) {
            StringBuilder errorMessage = new StringBuilder(
                    "Error while trying to write the resource attribute ");
            errorMessage.append("TransformerWinding");
            errorMessage.append(" in class ");
            errorMessage.append("RatioTapChanger ");
            errorMessage.append("which ID has been initialized to : ");
            errorMessage.append(getId());
            LOGGER.error(errorMessage.toString());
            LOGGER.error(e.toString(), e);
        }
    }
    }

    return;
}
项目:OperatieBRP    文件:WriterContext.java   
/**
 * Maakt een nieuw WriterContext object.
 *
 * @param writer de XMLStreamWriter
 */
WriterContext(final XMLStreamWriter writer) {
    ValidatieHelper.controleerOpNullWaarde(writer, "writer");
    this.writer = writer;
    this.state = SEEN_NOTHING;
    this.stateStack = new LinkedList<>();
    this.identationDepth = 0;
}
项目:powsybl-core    文件:AbstractConnectableXml.java   
protected static void writePQ(Integer index, Terminal t, XMLStreamWriter writer) throws XMLStreamException {
    if (!Float.isNaN(t.getP())) {
        XmlUtil.writeFloat("p" + indexToString(index), t.getP(), writer);
    }
    if (!Float.isNaN(t.getQ())) {
        XmlUtil.writeFloat("q" + indexToString(index), t.getQ(), writer);
    }
}
项目:powsybl-core    文件:SmallSignalSecurityIndex.java   
@Override
public void toXml(XMLStreamWriter xmlWriter) throws XMLStreamException {
    try {
        toXml(this, xmlWriter);
    } catch (JAXBException e) {
        throw new UncheckedJaxbException(e);
    }
}
项目:jigsaw-payment    文件:XmlJavaxFormat.java   
/**
 * 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);
    }
}