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


Java DOMResult.setNode方法代码示例

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


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

示例1: DomSerializer

import javax.xml.transform.dom.DOMResult; //导入方法依赖的package包/类
public DomSerializer(DOMResult domResult) {
    Node node = domResult.getNode();

    if (node == null) {
        try {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            DocumentBuilder db = dbf.newDocumentBuilder();
            Document doc = db.newDocument();
            domResult.setNode(doc);
            serializer = new SaxSerializer(new Dom2SaxAdapter(doc),null,false);
        } catch (ParserConfigurationException pce) {
            throw new TxwException(pce);
        }
    } else {
        serializer = new SaxSerializer(new Dom2SaxAdapter(node),null,false);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:19,代码来源:DomSerializer.java

示例2: test3

import javax.xml.transform.dom.DOMResult; //导入方法依赖的package包/类
@Test
public void test3() throws Exception {
    SAXTransformerFactory sf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
    Transformer t = sf.newTransformer();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder parser = dbf.newDocumentBuilder();
    Document dom = parser.parse(Bug5072946.class.getResourceAsStream("Bug5072946.xml"));

    DOMResult r = new DOMResult();

    t.transform(new DOMSource(dom), r);
    Assert.assertNotNull(r.getNode());

    Node n = r.getNode().getFirstChild();
    r.setNode(n);
    t.transform(new DOMSource(dom), r);
    Assert.assertNotNull(r.getNode());
    Assert.assertSame(r.getNode(), n);

    r.setNextSibling(r.getNode().getFirstChild());
    t.transform(new DOMSource(dom), r);
    Assert.assertNotNull(r.getNode());
    Assert.assertSame(r.getNode(), n);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:Bug5072946.java

示例3: setupDOMResultHandler

import javax.xml.transform.dom.DOMResult; //导入方法依赖的package包/类
/**
 * Sets up handler for <code>DOMResult</code>.
 */
private void setupDOMResultHandler(DOMSource source, DOMResult result) throws SAXException {
    // If there's no DOMResult, unset the validator handler
    if (result == null) {
        fDOMValidatorHandler = null;
        fSchemaValidator.setDocumentHandler(null);
        return;
    }
    final Node nodeResult = result.getNode();
    // If the source node and result node are the same use the DOMResultAugmentor.
    // Otherwise use the DOMResultBuilder.
    if (source.getNode() == nodeResult) {
        fDOMValidatorHandler = fDOMResultAugmentor;
        fDOMResultAugmentor.setDOMResult(result);
        fSchemaValidator.setDocumentHandler(fDOMResultAugmentor);
        return;
    }
    if (result.getNode() == null) {
        try {
            DocumentBuilderFactory factory = fComponentManager.getFeature(Constants.ORACLE_FEATURE_SERVICE_MECHANISM) ?
                                DocumentBuilderFactory.newInstance() : new DocumentBuilderFactoryImpl();
            factory.setNamespaceAware(true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            result.setNode(builder.newDocument());
        }
        catch (ParserConfigurationException e) {
            throw new SAXException(e);
        }
    }
    fDOMValidatorHandler = fDOMResultBuilder;
    fDOMResultBuilder.setDOMResult(result);
    fSchemaValidator.setDocumentHandler(fDOMResultBuilder);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:DOMValidatorHelper.java

示例4: test1

import javax.xml.transform.dom.DOMResult; //导入方法依赖的package包/类
@Test
public void test1() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder parser = dbf.newDocumentBuilder();
    Document dom = parser.parse(Bug5073477.class.getResourceAsStream("Bug5073477.xml"));

    DOMResult r = new DOMResult();

    r.setNode(dom.getDocumentElement());
    r.setNextSibling(r.getNode().getFirstChild());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:13,代码来源:Bug5073477.java

示例5: deserialize

import javax.xml.transform.dom.DOMResult; //导入方法依赖的package包/类
/**
 * @param ctx
 * @param source
 * @return the Node resulting from the parse of the source
 * @throws XMLEncryptionException
 */
private Node deserialize(Node ctx, Source source) throws XMLEncryptionException {
    try {
        Document contextDocument = null;
        if (Node.DOCUMENT_NODE == ctx.getNodeType()) {
            contextDocument = (Document)ctx;
        } else {
            contextDocument = ctx.getOwnerDocument();
        }

        if (transformerFactory == null) {
            transformerFactory = TransformerFactory.newInstance();
            transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
        }
        Transformer transformer = transformerFactory.newTransformer();

        DOMResult res = new DOMResult();

        Node placeholder = contextDocument.createDocumentFragment();
        res.setNode(placeholder);

        transformer.transform(source, res);

        // Skip dummy element
        Node dummyChild = placeholder.getFirstChild();
        Node child = dummyChild.getFirstChild();

        if (child != null && child.getNextSibling() == null) {
            return child;
        }

        DocumentFragment docfrag = contextDocument.createDocumentFragment();
        while (child != null) {
            dummyChild.removeChild(child);
            docfrag.appendChild(child);
            child = dummyChild.getFirstChild();
        }

        return docfrag;
    } catch (Exception e) {
        throw new XMLEncryptionException(e);
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:49,代码来源:TransformSerializer.java

示例6: marshalDomResult

import javax.xml.transform.dom.DOMResult; //导入方法依赖的package包/类
/**
 * Template method for handling {@code DOMResult}s.
 * <p>This implementation delegates to {@code marshalDomNode}.
 * @param graph the root of the object graph to marshal
 * @param domResult the {@code DOMResult}
 * @throws XmlMappingException if the given object cannot be marshalled to the result
 * @throws IllegalArgumentException if the {@code domResult} is empty
 * @see #marshalDomNode(Object, org.w3c.dom.Node)
 */
protected void marshalDomResult(Object graph, DOMResult domResult) throws XmlMappingException {
	if (domResult.getNode() == null) {
		domResult.setNode(buildDocument());
	}
	marshalDomNode(graph, domResult.getNode());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:16,代码来源:AbstractMarshaller.java


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