本文整理汇总了Java中javax.xml.transform.dom.DOMResult类的典型用法代码示例。如果您正苦于以下问题:Java DOMResult类的具体用法?Java DOMResult怎么用?Java DOMResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DOMResult类属于javax.xml.transform.dom包,在下文中一共展示了DOMResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: LoadXML
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public static Document LoadXML(Source file)
{
try
{
DocumentBuilderFactory dbf = DocumentBuilderFactoryImpl.newInstance() ;
DocumentBuilder db = dbf.newDocumentBuilder() ;
Document doc = db.newDocument() ;
Result res = new DOMResult(doc) ;
TransformerFactory tr = TransformerFactory.newInstance();
Transformer xformer = tr.newTransformer();
xformer.transform(file, res);
return doc ;
}
catch (Exception e)
{
String csError = e.toString();
Log.logImportant(csError);
Log.logImportant("ERROR while loading XML "+file.toString());
}
return null;
}
示例2: testCreateStartDocument_DOMWriter
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
/**
* @bug 8139584
* Verifies that the resulting XML contains the standalone setting.
*/
@Test
public void testCreateStartDocument_DOMWriter()
throws ParserConfigurationException, XMLStreamException {
XMLOutputFactory xof = XMLOutputFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
XMLEventWriter eventWriter = xof.createXMLEventWriter(new DOMResult(doc));
XMLEventFactory eventFactory = XMLEventFactory.newInstance();
XMLEvent event = eventFactory.createStartDocument("iso-8859-15", "1.0", true);
eventWriter.add(event);
eventWriter.flush();
Assert.assertEquals(doc.getXmlEncoding(), "iso-8859-15");
Assert.assertEquals(doc.getXmlVersion(), "1.0");
Assert.assertTrue(doc.getXmlStandalone());
}
示例3: transformToDocument
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public Document transformToDocument()
{
try
{
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
transformTo(new DOMResult(document));
return document;
}
catch (ParserConfigurationException ex)
{
throw new FluentXmlConfigurationException(ex);
}
}
示例4: cloneDoc
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public Document cloneDoc ( final Document doc ) throws TransformerException
{
final Transformer tx = this.tf.newTransformer ();
final DOMSource source = new DOMSource ( doc );
final DOMResult result = new DOMResult ();
tx.transform ( source, result );
return (Document)result.getNode ();
}
示例5: createResult
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
/**
* Retrieves a new Result for setting the XML value designated by this
* SQLXML instance.
*
* @param resultClass The class of the result, or null.
* @throws java.sql.SQLException if there is an error processing the XML
* value or the state is not writable
* @return for setting the XML value designated by this SQLXML instance.
*/
protected <T extends Result>T createResult(
Class<T> resultClass) throws SQLException {
checkWritable();
setWritable(false);
setReadable(true);
if (JAXBResult.class.isAssignableFrom(resultClass)) {
// Must go first presently, since JAXBResult extends SAXResult
// (purely as an implmentation detail) and it's not possible
// to instantiate a valid JAXBResult with a Zero-Args
// constructor(or any subclass thereof, due to the finality of
// its private UnmarshallerHandler)
// FALL THROUGH... will throw an exception
} else if ((resultClass == null)
|| StreamResult.class.isAssignableFrom(resultClass)) {
return createStreamResult(resultClass);
} else if (DOMResult.class.isAssignableFrom(resultClass)) {
return createDOMResult(resultClass);
} else if (SAXResult.class.isAssignableFrom(resultClass)) {
return createSAXResult(resultClass);
} else if (StAXResult.class.isAssignableFrom(resultClass)) {
return createStAXResult(resultClass);
}
throw JDBCUtil.invalidArgument("resultClass: " + resultClass);
}
示例6: writeTo
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public void writeTo(SOAPMessage saaj) throws SOAPException {
try {
// TODO what about in-scope namespaces
// Not very efficient consider implementing a stream buffer
// processor that produces a DOM node from the buffer.
TransformerFactory tf = XmlUtil.newTransformerFactory();
Transformer t = tf.newTransformer();
XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
DOMResult result = new DOMResult();
t.transform(source, result);
Node d = result.getNode();
if(d.getNodeType() == Node.DOCUMENT_NODE)
d = d.getFirstChild();
SOAPHeader header = saaj.getSOAPHeader();
if(header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
Node node = header.getOwnerDocument().importNode(d, true);
header.appendChild(node);
} catch (Exception e) {
throw new SOAPException(e);
}
}
示例7: createDOM
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
private Document createDOM(SDDocument doc) {
// Get infoset
ByteArrayBuffer bab = new ByteArrayBuffer();
try {
doc.writeTo(null, resolver, bab);
} catch (IOException ioe) {
throw new WebServiceException(ioe);
}
// Convert infoset to DOM
Transformer trans = XmlUtil.newTransformer();
Source source = new StreamSource(bab.newInputStream(), null); //doc.getURL().toExternalForm());
DOMResult result = new DOMResult();
try {
trans.transform(source, result);
} catch(TransformerException te) {
throw new WebServiceException(te);
}
return (Document)result.getNode();
}
示例8: 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);
}
}
示例9: getElement
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public Element getElement(DOMResult r) {
// JAXP spec is ambiguous about what really happens in this case,
// so work defensively
Node n = r.getNode();
if( n instanceof Document ) {
return ((Document)n).getDocumentElement();
}
if( n instanceof Element )
return (Element)n;
if( n instanceof DocumentFragment )
return (Element)n.getChildNodes().item(0);
// if the result object contains something strange,
// it is not a user problem, but it is a JAXB provider's problem.
// That's why we throw a runtime exception.
throw new IllegalStateException(n.toString());
}
示例10: setDOMResult
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public void setDOMResult(DOMResult result) {
fCurrentNode = null;
fFragmentRoot = null;
fIgnoreChars = false;
fTargetChildren.clear();
if (result != null) {
fTarget = result.getNode();
fNextSibling = result.getNextSibling();
fDocument = (fTarget.getNodeType() == Node.DOCUMENT_NODE) ? (Document) fTarget : fTarget.getOwnerDocument();
fDocumentImpl = (fDocument instanceof CoreDocumentImpl) ? (CoreDocumentImpl) fDocument : null;
fStorePSVI = (fDocument instanceof PSVIDocumentImpl);
return;
}
fTarget = null;
fNextSibling = null;
fDocument = null;
fDocumentImpl = null;
fStorePSVI = false;
}
示例11: createXMLStreamWriter
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public javax.xml.stream.XMLStreamWriter createXMLStreamWriter(javax.xml.transform.Result result) throws javax.xml.stream.XMLStreamException {
if (result instanceof StreamResult) {
return createXMLStreamWriter((StreamResult) result, null);
} else if (result instanceof DOMResult) {
return new XMLDOMWriterImpl((DOMResult) result);
} else if (result instanceof StAXResult) {
if (((StAXResult) result).getXMLStreamWriter() != null) {
return ((StAXResult) result).getXMLStreamWriter();
} else {
throw new java.lang.UnsupportedOperationException("Result of type " + result + " is not supported");
}
} else {
if (result.getSystemId() !=null) {
//this is not correct impl of SAXResult. Keep it for now for compatibility
return createXMLStreamWriter(new StreamResult(result.getSystemId()));
} else {
throw new java.lang.UnsupportedOperationException("Result of type " + result + " is not supported. " +
"Supported result types are: DOMResult, StAXResult and StreamResult.");
}
}
}
示例12: XMLDOMWriterImpl
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
/**
* Creates a new instance of XMLDOMwriterImpl
* @param result DOMResult object @javax.xml.transform.dom.DOMResult
*/
public XMLDOMWriterImpl(DOMResult result) {
node = result.getNode();
if( node.getNodeType() == Node.DOCUMENT_NODE){
ownerDoc = (Document)node;
currentNode = ownerDoc;
}else{
ownerDoc = node.getOwnerDocument();
currentNode = node;
}
getDLThreeMethods();
stringBuffer = new StringBuffer();
needContextPop = new boolean[resizeValue];
namespaceContext = new NamespaceSupport();
}
示例13: loadXML
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public static Document loadXML(ByteArrayInputStream byteArrayInputStream)
{
try
{
StreamSource streamSource = new StreamSource(byteArrayInputStream);
DocumentBuilderFactory dbf = DocumentBuilderFactoryImpl.newInstance() ;
DocumentBuilder db = dbf.newDocumentBuilder() ;
Document doc = db.newDocument() ;
Result res = new DOMResult(doc) ;
TransformerFactory tr = TransformerFactory.newInstance();
Transformer xformer = tr.newTransformer();
xformer.transform(streamSource, res);
return doc ;
}
catch (Exception e)
{
String csError = e.toString();
Log.logImportant(csError);
Log.logImportant("ERROR while loading XML from byteArrayInputStream "+byteArrayInputStream.toString());
}
return null;
}
示例14: load
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public boolean load(InputStream s)
{
try
{
Source file = new StreamSource(s) ;
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument() ;
Result res = new DOMResult(doc) ;
TransformerFactory tr = TransformerFactory.newInstance();
Transformer xformer = tr.newTransformer();
xformer.transform(file, res);
m_doc = doc;
m_elem = m_doc.getDocumentElement();
return true;
}
catch (Exception e)
{
LogTagError.log(e);
return false;
}
}
示例15: writeTo
import javax.xml.transform.dom.DOMResult; //导入依赖的package包/类
public void writeTo(SOAPMessage saaj) throws SOAPException {
try {
// TODO what about in-scope namespaces
// Not very efficient consider implementing a stream buffer
// processor that produces a DOM node from the buffer.
TransformerFactory tf = XmlUtil.newTransformerFactory(true);
Transformer t = tf.newTransformer();
XMLStreamBufferSource source = new XMLStreamBufferSource(_mark);
DOMResult result = new DOMResult();
t.transform(source, result);
Node d = result.getNode();
if(d.getNodeType() == Node.DOCUMENT_NODE)
d = d.getFirstChild();
SOAPHeader header = saaj.getSOAPHeader();
if(header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
Node node = header.getOwnerDocument().importNode(d, true);
header.appendChild(node);
} catch (Exception e) {
throw new SOAPException(e);
}
}