本文整理匯總了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);
}
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
}
示例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());
}