當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。