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


Java XMLOutputFactory.setProperty方法代码示例

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


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

示例1: test1

import javax.xml.stream.XMLOutputFactory; //导入方法依赖的package包/类
@Test
public void test1() throws Exception {
    XMLOutputFactory xof = XMLOutputFactory.newInstance();
    xof.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);

    StringWriter sw = new StringWriter();
    XMLStreamWriter w = xof.createXMLStreamWriter(sw);
    w.writeStartDocument();
    w.writeStartElement("foo", "bar", "zot");
    w.writeDefaultNamespace(null);
    w.writeCharacters("---");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:NullUriDetectionTest.java

示例2: 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

示例3: testDuplicateNSDeclaration

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

    // expect only 1 Namespace Declaration
    final String EXPECTED_OUTPUT = "<?xml version=\"1.0\" ?>" + "<ns1:foo" + " xmlns:ns1=\"http://example.com/\">" + "</ns1:foo>";

    // have XMLOutputFactory repair Namespaces
    XMLOutputFactory ofac = XMLOutputFactory.newInstance();
    ofac.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, new Boolean(true));

    // send output to a Stream
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    StreamResult sr = new StreamResult(buffer);
    XMLStreamWriter w = null;

    // write a duplicate Namespace Declaration
    try {
        w = ofac.createXMLStreamWriter(sr);
        w.writeStartDocument();
        w.writeStartElement("ns1", "foo", "http://example.com/");
        w.writeNamespace("ns1", "http://example.com/");
        w.writeNamespace("ns1", "http://example.com/");
        w.writeEndElement();
        w.writeEndDocument();
        w.close();
    } catch (XMLStreamException xmlStreamException) {
        xmlStreamException.printStackTrace();
        Assert.fail(xmlStreamException.toString());
    }

    // debugging output for humans
    System.out.println();
    System.out.println("actual:   \"" + buffer.toString() + "\"");
    System.out.println("expected: \"" + EXPECTED_OUTPUT + "\"");

    // are results as expected?
    Assert.assertEquals(EXPECTED_OUTPUT, buffer.toString());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:DuplicateNSDeclarationTest.java

示例4: 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


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