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


Java XMLOutputFactory.newInstance方法代码示例

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


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

示例1: testXMLStreamWriter

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
/**
 * Test XMLStreamWriter parsing a file with an external entity reference.
 */
@Test
public void testXMLStreamWriter() {

    try {
        XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
        XMLEventWriter eventWriter = outputFactory.createXMLEventWriter(System.out);
        XMLInputFactory inputFactory = XMLInputFactory.newInstance();
        String file = getClass().getResource("XMLEventWriterTest.xml").getPath();
        XMLEventReader eventReader = inputFactory.createXMLEventReader(new StreamSource(new File(file)));

        // adds the event to the consumer.
        eventWriter.add(eventReader);
        eventWriter.flush();
        eventWriter.close();

        // expected success
    } catch (Exception exception) {
        exception.printStackTrace();
        Assert.fail(exception.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:XMLEventWriterTest.java

示例2: writeXMLFile

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
public void writeXMLFile(HashMap<String,String> lines,String path) throws IOException, XMLStreamException{
    XMLOutputFactory xof =  XMLOutputFactory.newInstance();
    final XMLStreamWriter xtw = xof.createXMLStreamWriter(new FileWriter(path));
    xtw.writeStartDocument("utf-8","1.0");
    xtw.writeCharacters("\n");
    
    lines.forEach((key,value) ->{
        try {
            xtw.writeStartElement(key);
            xtw.writeCharacters(value);
            xtw.writeEndElement();
            xtw.writeCharacters("\n");
        } catch (XMLStreamException ex) {
            Logger.getLogger(XMLController.class.getName()).log(Level.SEVERE, null, ex);
        }
    });
    xtw.writeEndDocument();
    xtw.flush();
    xtw.close();
}
 
开发者ID:Obsidiam,项目名称:amelia,代码行数:21,代码来源:XMLController.java

示例3: testBoundPrefix

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
@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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:UnprefixedNameTest.java

示例4: testStreamReader

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
@Test
public void testStreamReader() {
    XMLInputFactory ifac = XMLInputFactory.newInstance();
    XMLOutputFactory ofac = XMLOutputFactory.newInstance();

    try {
        ifac.setProperty(ifac.IS_REPLACING_ENTITY_REFERENCES, new Boolean(false));

        XMLStreamReader re = ifac.createXMLStreamReader(this.getClass().getResource(INPUT_FILE).toExternalForm(),
                this.getClass().getResourceAsStream(INPUT_FILE));

        while (re.hasNext()) {
            int event = re.next();
            if (event == XMLStreamConstants.START_ELEMENT && re.getLocalName().equals("bookurn")) {
                Assert.assertTrue(re.getAttributeCount() == 0, "No attributes are expected for <bookurn> ");
                Assert.assertTrue(re.getNamespaceCount() == 2, "Two namespaces are expected for <bookurn> ");
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail("Exception occured: " + e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:DefaultAttributeTest.java

示例5: testRepairingPrefix

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
@Test
public void testRepairingPrefix() throws Exception {

    try {

        // repair namespaces
        // use new XMLOutputFactory as changing its property settings
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        xof.setProperty(xof.IS_REPAIRING_NAMESPACES, new Boolean(true));
        XMLStreamWriter w = xof.createXMLStreamWriter(System.out);

        // here I'm trying to write
        // <bar xmlns="foo" />
        w.writeStartDocument();
        w.writeStartElement("foo", "bar");
        w.writeDefaultNamespace("foo");
        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);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:31,代码来源:UnprefixedNameTest.java

示例6: test

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
/**
 * 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());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:Bug6452107.java

示例7: serializeCompany

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
public static void serializeCompany(File output, Company c)
throws 	JAXBException,
		FileNotFoundException,
		XMLStreamException 
{
	initializeJaxbContext();
    OutputStream os = new FileOutputStream(output);
	Marshaller marshaller = jaxbContext.createMarshaller();
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
       XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
	marshaller.marshal(c, writer); // TODO: need a stream writer that does indentation		
}
 
开发者ID:amritbhat786,项目名称:DocIT,代码行数:13,代码来源:Serialization.java

示例8: testStreamWriterWithStAXResultNEventWriter

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
@Test
public void testStreamWriterWithStAXResultNEventWriter() throws Exception {
    try {
        XMLOutputFactory ofac = XMLOutputFactory.newInstance();
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        XMLEventWriter writer = ofac.createXMLEventWriter(buffer);
        StAXResult res = new StAXResult(writer);
        XMLStreamWriter swriter = ofac.createXMLStreamWriter(res);
        Assert.fail("Expected an Exception as XMLStreamWriter can't be created " + "with a StAXResult which has EventWriter.");
    } catch (Exception e) {
        System.out.println(e.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:StreamResultTest.java

示例9: writeCompany

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
public static void writeCompany(File output, Company c)
throws 	JAXBException,
		FileNotFoundException,
		XMLStreamException 
{
	initializeJaxbContext();
    OutputStream os = new FileOutputStream(output);
	Marshaller marshaller = jaxbContext.createMarshaller();
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
       XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
	marshaller.marshal(c, writer); // TODO: need a stream writer that does indentation		
}
 
开发者ID:amritbhat786,项目名称:DocIT,代码行数:13,代码来源:Serialization.java

示例10: setUp

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
@BeforeMethod
public void setUp() {
    try {
        outputFactory = XMLOutputFactory.newInstance();
        inputFactory = XMLInputFactory.newInstance();
    } catch (Exception ex) {
        Assert.fail("Could not create XMLInputFactory");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:WriterTest.java

示例11: createInitXML

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

示例12: producePureXMLLogoutRequest

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
private ByteArrayOutputStream producePureXMLLogoutRequest(String logoutUrl, String nameID, String format, String sessionIndex, String issuer, String issueInstant) throws XMLStreamException, UnsupportedEncodingException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    XMLStreamWriter writer = factory.createXMLStreamWriter(baos);

    writer.writeStartElement("saml2p", "LogoutRequest", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeNamespace("saml2p", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeAttribute("ID", "_" + UUID.randomUUID().toString());
    writer.writeAttribute("Version", "2.0");
    writer.writeAttribute("Destination", logoutUrl);
    writer.writeAttribute("IssueInstant", issueInstant + "Z");

    writer.writeStartElement("saml2", "Issuer", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeNamespace("saml2", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeCharacters(issuer);
    writer.writeEndElement();

    writer.writeStartElement("saml", "NameID", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeNamespace("saml", "urn:oasis:names:tc:SAML:2.0:assertion");
    writer.writeAttribute("Format", format);
    writer.writeCharacters(nameID);
    writer.writeEndElement();

    writer.writeStartElement("saml2p", "SessionIndex", "urn:oasis:names:tc:SAML:2.0:protocol");
    writer.writeCharacters(sessionIndex);
    writer.writeEndElement();

    writer.writeEndElement();
    writer.flush();

    return baos;
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:33,代码来源:LogoutRequestGenerator.java

示例13: toXml

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
/**
 * Returns a string containing the specified document in GATE XML
 * format.
 * 
 * @param doc the document
 */
public static String toXml(Document doc) {
  try {
    if(outputFactory == null) {
      outputFactory = XMLOutputFactory.newInstance();
    }
    StringWriter sw = new StringWriter(doc.getContent().size().intValue()
            * DocumentXmlUtils.DOC_SIZE_MULTIPLICATION_FACTOR);
    XMLStreamWriter xsw = outputFactory.createXMLStreamWriter(sw);

    // start the document
    if(doc instanceof TextualDocument) {
      xsw.writeStartDocument(((TextualDocument)doc).getEncoding(), "1.0");
    }
    else {
      xsw.writeStartDocument("1.0");
    }
    newLine(xsw);
    writeDocument(doc, xsw, "");
    xsw.close();

    return sw.toString();
  }
  catch(XMLStreamException xse) {
    throw new GateRuntimeException("Error converting document to XML", xse);
  }
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:33,代码来源:DocumentStaxUtils.java

示例14: testXMLOutputFactory

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
public void testXMLOutputFactory() {
    XMLOutputFactory factory = XMLOutputFactory.newInstance();
    factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, true);
    success("testXMLOutputFactory passed");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:6,代码来源:JAXP15RegTest.java

示例15: testCR6420953

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
@Test
public void testCR6420953() {

    try {
        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        StringWriter sw = new StringWriter();
        XMLStreamWriter w = xof.createXMLStreamWriter(sw);

        w.writeStartDocument();
        w.writeStartElement("element");

        w.writeDefaultNamespace(XML_CONTENT);
        w.writeNamespace("prefix", XML_CONTENT);

        w.writeAttribute("attribute", XML_CONTENT);
        w.writeAttribute(XML_CONTENT, "attribute2", XML_CONTENT);
        w.writeAttribute("prefix", XML_CONTENT, "attribute3", XML_CONTENT);

        w.writeCharacters("\n");
        w.writeCharacters(XML_CONTENT);
        w.writeCharacters("\n");
        w.writeCharacters(XML_CONTENT.toCharArray(), 0, XML_CONTENT.length());
        w.writeCharacters("\n");

        w.writeEndElement();
        w.writeEndDocument();
        w.flush();

        System.out.println(sw);

        // make sure that the generated XML parses
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        dbf.newDocumentBuilder().parse(new InputSource(new StringReader(sw.toString())));
    } catch (XMLStreamException xmlStreamException) {
        xmlStreamException.printStackTrace();
        Assert.fail(xmlStreamException.toString());
    } catch (SAXException saxException) {
        saxException.printStackTrace();
        Assert.fail(saxException.toString());
    } catch (ParserConfigurationException parserConfigurationException) {
        parserConfigurationException.printStackTrace();
        Assert.fail(parserConfigurationException.toString());
    } catch (IOException ioException) {
        ioException.printStackTrace();
        Assert.fail(ioException.toString());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:AttributeEscapeTest.java


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