当前位置: 首页>>代码示例>>Java>>正文


Java XMLStreamWriter.writeCharacters方法代码示例

本文整理汇总了Java中javax.xml.stream.XMLStreamWriter.writeCharacters方法的典型用法代码示例。如果您正苦于以下问题:Java XMLStreamWriter.writeCharacters方法的具体用法?Java XMLStreamWriter.writeCharacters怎么用?Java XMLStreamWriter.writeCharacters使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.stream.XMLStreamWriter的用法示例。


在下文中一共展示了XMLStreamWriter.writeCharacters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeXMLByStAX

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public static void writeXMLByStAX() throws XMLStreamException, FileNotFoundException {
	XMLOutputFactory factory = XMLOutputFactory.newInstance();
	XMLStreamWriter writer = factory.createXMLStreamWriter(new FileOutputStream("output.xml"));
	writer.writeStartDocument();
	writer.writeCharacters(" ");
	writer.writeComment("testing comment");
	writer.writeCharacters(" ");
	writer.writeStartElement("catalogs");
	writer.writeNamespace("myNS", "http://blog.csdn.net/Chinajash");
	writer.writeAttribute("owner", "sina");
	writer.writeCharacters(" ");
	writer.writeStartElement("http://blog.csdn.net/Chinajash", "catalog");
	writer.writeAttribute("id", "007");
	writer.writeCharacters("Apparel");
	// 写入catalog元素的结束标签
	writer.writeEndElement();
	// 写入catalogs元素的结束标签
	writer.writeEndElement();
	// 结束 XML 文档
	writer.writeEndDocument();
	writer.close();
	System.out.println("ok");
}
 
开发者ID:leon66666,项目名称:JavaCommon,代码行数:24,代码来源:StaxDemo.java

示例2: writeTo

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
    w.writeStartElement("", name.getLocalPart(), name.getNamespaceURI());
    w.writeDefaultNamespace(name.getNamespaceURI());
    if (mustUnderstand) {
        //Writing the ns declaration conditionally checking in the NSContext breaks XWSS. as readHeader() adds ns declaration,
        // where as writing alonf with the soap envelope does n't add it.
        //Looks like they expect the readHeader() and writeTo() produce the same infoset, Need to understand their usage

        //if(w.getNamespaceContext().getPrefix(soapVersion.nsUri) == null) {
        w.writeNamespace("S", soapVersion.nsUri);
        w.writeAttribute("S", soapVersion.nsUri, MUST_UNDERSTAND, getMustUnderstandLiteral(soapVersion));
        // } else {
        // w.writeAttribute(soapVersion.nsUri,MUST_UNDERSTAND, getMustUnderstandLiteral(soapVersion));
        // }
    }
    w.writeCharacters(value);
    w.writeEndElement();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:StringHeader.java

示例3: 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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:SurrogatesTest.java

示例4: writeTo

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
public void writeTo(XMLStreamWriter output) throws IOException, XMLStreamException {
    if (data==null) {
        try {
            InputStream is = dataHandler.getDataSource().getInputStream();
            ByteArrayOutputStream outStream = new ByteArrayOutputStream(); // dev-null stream
            Base64EncoderStream encWriter = new Base64EncoderStream(output, outStream);
            int b;
            byte[] buffer = new byte[CHUNK_SIZE];
            while ((b = is.read(buffer)) != -1) {
                encWriter.write(buffer, 0, b);
            }
            outStream.close();
            encWriter.close();
        } catch (IOException e) {
            dataLen = 0;    // recover by assuming length-0 data
            throw e;
        }
    } else {
        // the data is already in memory and not streamed
        String s = Base64Encoder.print(data, 0, dataLen);
        output.writeCharacters(s);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:24,代码来源:Base64Data.java

示例5: 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("computation-succeed");
    xmlWriter.writeCharacters(Boolean.toString(computationSucceed));
    xmlWriter.writeEndElement();

    xmlWriter.writeStartElement("undervoltage-count");
    xmlWriter.writeCharacters(Integer.toString(undervoltageCount));
    xmlWriter.writeEndElement();

    xmlWriter.writeEndElement();
    xmlWriter.writeEndDocument();
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:18,代码来源:TsoUndervoltageSecurityIndex.java

示例6: toXml

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Override
protected void toXml(XMLStreamWriter xmlWriter) throws XMLStreamException {
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("index");
    xmlWriter.writeAttribute("name", XML_NAME);
    for (Map.Entry<String, Float> e : disconnectedGenerators.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();
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:17,代码来源:TsoDisconnectedGenerator.java

示例7: writeClass

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:33,代码来源:CurrentLimit.java

示例8: writeClass

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
 * 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,
                "VoltageLimit.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("VoltageLimit ");
        errorMessage.append("which ID has been initialized to : ");
        errorMessage.append(getId());
        LOGGER.error(errorMessage.toString());
        LOGGER.error(e.toString(), e);
    }
    }

    return;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:33,代码来源:VoltageLimit.java

示例9: 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("j");
    xmlWriter.writeCharacters(Double.toString(j));
    xmlWriter.writeEndElement();
    xmlWriter.writeEndElement();
    xmlWriter.writeEndDocument();
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:12,代码来源:TransientSecurityIndex.java

示例10: serializeNode

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
 * Traverses a DOM node and writes out on a streaming writer.
 *
 * @param node
 * @param writer
 */
public static void serializeNode(Element node, XMLStreamWriter writer) throws XMLStreamException {
    writeTagWithAttributes(node, writer);

    if (node.hasChildNodes()) {
        NodeList children = node.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            switch (child.getNodeType()) {
                case Node.PROCESSING_INSTRUCTION_NODE:
                    writer.writeProcessingInstruction(child.getNodeValue());
                    break;
                case Node.DOCUMENT_TYPE_NODE:
                    break;
                case Node.CDATA_SECTION_NODE:
                    writer.writeCData(child.getNodeValue());
                    break;
                case Node.COMMENT_NODE:
                    writer.writeComment(child.getNodeValue());
                    break;
                case Node.TEXT_NODE:
                    writer.writeCharacters(child.getNodeValue());
                    break;
                case Node.ELEMENT_NODE:
                    serializeNode((Element) child, writer);
                    break;
                default: break;
            }
        }
    }
    writer.writeEndElement();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:DOMUtil.java

示例11: 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("fx");
    xmlWriter.writeCharacters(Double.toString(indexValue));
    xmlWriter.writeEndElement();
    xmlWriter.writeEndElement();
    xmlWriter.writeEndDocument();
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:12,代码来源:OverloadSecurityIndex.java

示例12: writeAnyCell

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
/**
 * Writes out an XML cell based on coordinates and provided value
 * 
 * @param row
 *            the row index of the cell
 * @param col
 *            the column index
 * @param cellValue
 *            value of the cell, can be null for an empty cell
 * @param out
 *            the XML output stream
 * @param columns
 *            the Map with column titles
 */
private void writeAnyCell(final int row, final int col, final String cellValue, final XMLStreamWriter out,
		final Map<String, String> columns) {
	try {
		out.writeStartElement("cell");
		String colNum = String.valueOf(col);
		out.writeAttribute("row", String.valueOf(row));
		out.writeAttribute("col", colNum);
		if (columns.containsKey(colNum)) {
			out.writeAttribute("title", columns.get(colNum));
		}
		if (cellValue != null) {
			if (cellValue.contains("<") || cellValue.contains(">")) {
				out.writeCData(cellValue);
			} else {
				out.writeCharacters(cellValue);
			}
		} else {
			out.writeAttribute("empty", "true");
		}
		out.writeEndElement();

	} catch (XMLStreamException e) {
		e.printStackTrace();
	}

}
 
开发者ID:Stwissel,项目名称:Excel2XML,代码行数:41,代码来源:E2xCmdline.java

示例13: toXml

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
private static void toXml(XMLStreamWriter xmlWriter, String xmlTagName, Map<String, Float> values) throws XMLStreamException {
    for (Map.Entry<String, Float> e : values.entrySet()) {
        String id = e.getKey();
        float p = e.getValue();
        xmlWriter.writeStartElement(xmlTagName);
        xmlWriter.writeAttribute(TAG_ID, id);
        xmlWriter.writeCharacters(Float.toString(p));
        xmlWriter.writeEndElement();
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:11,代码来源:MultiCriteriaVoltageStabilityIndex.java

示例14: writeTo

import javax.xml.stream.XMLStreamWriter; //导入方法依赖的package包/类
@Override
public void writeTo(XMLStreamWriter w) throws XMLStreamException {
    w.writeStartElement("", name.getLocalPart(), name.getNamespaceURI());
    w.writeDefaultNamespace(name.getNamespaceURI());
    if (type != null)
        w.writeAttribute("type", type);
    w.writeCharacters(value);
    w.writeEndElement();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:RelatesToHeader.java

示例15: 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("vx");
    xmlWriter.writeCharacters(Double.toString(indexValue));
    xmlWriter.writeEndElement();
    xmlWriter.writeEndElement();
    xmlWriter.writeEndDocument();
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:12,代码来源:UnderOverVoltageSecurityIndex.java


注:本文中的javax.xml.stream.XMLStreamWriter.writeCharacters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。