Java 8 DOMResult - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 DOMResult class.

This code example shows how to use the following methods:getNode
	@Test
	public void marshalEmptyDOMResult() throws Exception {
		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
		documentBuilderFactory.setNamespaceAware(true);
		DocumentBuilder builder = documentBuilderFactory.newDocumentBuilder();
		DOMResult domResult = new DOMResult();
		marshaller.marshal(flights, domResult);
		assertTrue("DOMResult does not contain a Document", domResult.getNode() instanceof Document);
		Document result = (Document) domResult.getNode();
		Document expected = builder.newDocument();
		Element flightsElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flights");
		Attr namespace = expected.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:tns");
		namespace.setNodeValue("http://samples.springframework.org/flight");
		flightsElement.setAttributeNode(namespace);
		expected.appendChild(flightsElement);
		Element flightElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:flight");
		flightsElement.appendChild(flightElement);
		Element numberElement = expected.createElementNS("http://samples.springframework.org/flight", "tns:number");
		flightElement.appendChild(numberElement);
		Text text = expected.createTextNode("42");
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		assertTrue("Not a StAX Source", StaxUtils.isStaxSource(source));
	} 
 
	@Test
	public void isStaxResultInvalid() throws Exception {
		assertFalse("A StAX Result", StaxUtils.isStaxResult(new DOMResult()));
		assertFalse("A StAX Result", StaxUtils.isStaxResult(new SAXResult()));
		assertFalse("A StAX Result", StaxUtils.isStaxResult(new StreamResult()));
	} 
 
	@Test
	public void isStaxResult() throws Exception {
		XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
		XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(new StringWriter());
		Result result = StaxUtils.createCustomStaxResult(streamWriter);
 
		assertTrue("Not a StAX Result", StaxUtils.isStaxResult(result));
	} 
 
	@Test
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getNode
   
  private static Document copyDoc(Document doc) throws TransformerException {
    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer tx = tfactory.newTransformer();
    DOMSource source = new DOMSource(doc);
    DOMResult result = new DOMResult();
    tx.transform(source, result);
    return (Document) result.getNode();
  } 
   
  /** 
   * @since solr 1.3 
   */ 
  public SolrResourceLoader getResourceLoader() 
  { 
    return loader;
  } 
 
  /** 
   * @since solr 1.3 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		assertEquals("Invalid streamReader returned", streamReader, source.getXMLStreamReader());
		assertNull("EventReader returned", source.getXMLEventReader());
 
		Document expected = documentBuilder.parse(new InputSource(new StringReader(XML)));
		Document result = documentBuilder.newDocument();
		transformer.transform(source, new DOMResult(result));
		assertXMLEqual("Invalid result", expected, result);
	} 
 
	@Test
	public void eventReaderSourceToStreamResult() throws Exception {
		XMLEventReader eventReader = inputFactory.createXMLEventReader(new StringReader(XML));
		StaxSource source = new StaxSource(eventReader);
		assertEquals("Invalid eventReader returned", eventReader, source.getXMLEventReader());
		assertNull("StreamReader returned", source.getXMLStreamReader());
		StringWriter writer = new StringWriter();
		transformer.transform(source, new StreamResult(writer));
		assertXMLEqual("Invalid result", XML, writer.toString());
	} 
 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getNode
        MethodResultMessage result = (MethodResultMessage) next.filter(call, metadata);
        return serializeResult(result);
    } 
 
    private Document serializeResult(MethodResultMessage result) {
        DOMResult domResult = new DOMResult();
        try { 
            JAXBContext jaxbContext =
                JAXBContext.newInstance(MethodResultMessage.class, Class.forName(result.getResult().getClassName()));
            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.marshal(new JAXBElement<MethodResultMessage>(
                new QName(MethodResultMessage.class.getSimpleName()),
                MethodResultMessage.class, result), domResult);
        } catch (JAXBException e) {
            throw new FilterException(e);
        } catch (ClassNotFoundException e) {
            throw new FilterException(e);
        } 
        return (Document) domResult.getNode();
    } 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
		DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
 
		Document expected = documentBuilder.parse(new InputSource(new StringReader(SIMPLE_XML)));
 
		Document result = documentBuilder.newDocument();
		AbstractStaxHandler handler = createStaxHandler(new DOMResult(result));
		xmlReader.setContentHandler(handler);
		xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
 
		xmlReader.setFeature("http://xml.org/sax/features/namespaces", true);
		xmlReader.setFeature("http://xml.org/sax/features/namespace-prefixes", false);
 
		xmlReader.parse(new InputSource(new StringReader(SIMPLE_XML)));
 
		assertXMLEqual(expected, result);
	} 
 
	@Test
	public void namespacePrefixesDom() throws Exception {
		DocumentBuilderFactory documentBuilderFactory =
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getNode
			JaxbValidationEventHandler eventHandler = new JaxbValidationEventHandler();
			eventHandler.setContinue(true);
			 
			// There is no JAXBResult(binder), 
			// so use a  
			DOMResult result = new DOMResult();
			 
			Templates mcPreprocessorXslt = JaxbValidationEventHandler.getMcPreprocessor();
			XmlUtils.transform(doc, mcPreprocessorXslt, null, result);
			 
			doc = (org.w3c.dom.Document)result.getNode();
			 
			try { 
				binder = jc.createBinder(); 
//				eventHandler.setContinue(false); // review  
				binder.setEventHandler(eventHandler);
				jaxbElement =  (Sld) binder.unmarshal( doc );
			} catch (ClassCastException cce) {
  
				log.warn("Binder not available for this slide"); 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getNode
            throw new FilterException(e);
        } 
    } 
 
    private Document serializeRequest(MethodCallMessage result) {
        DOMResult domResult = new DOMResult();
        try { 
            @SuppressWarnings("unchecked") 
            List<Class<?>> classes = ClassUtils.convertClassNamesToClasses(result.getMethodCall().getClasses());
            if (classes.contains(null)) {
                throw new FilterException("Could not load all required classes. Require: " 
                        + result.getMethodCall().getClasses() + " got: " + classes);
            } 
            classes.add(MethodCallMessage.class);
            JAXBContext jaxbContext =
                JAXBContext.newInstance(classes.toArray(new Class<?>[classes.size()]));
            Marshaller marshaller = jaxbContext.createMarshaller();
            marshaller.marshal(new JAXBElement<MethodCallMessage>(new QName(MethodCallMessage.class.getSimpleName()),
                MethodCallMessage.class, result), domResult);
        } catch (JAXBException e) {

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getNode
 
		//this.writeXml(((DOMSource)source).getNode().getOwnerDocument()); 
		DOMResult result = null;
		try { 
			Transformer transformer = transformerFactory.newTransformer();
			result = new DOMResult();
			transformer.transform(source, result);
		} catch (Exception e) {
			throw new MarshallingFailureException("Failed to unmarshal SOAP Response", e);
		} 
		Weather weather = new Weather();
		String expression = xpathPrefix + "p:City";
		String city = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
		weather.setCity(city);
		expression = xpathPrefix + "p:State";
		String state = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
		weather.setState(state);
		expression = xpathPrefix + "p:Temperature";
		String temperature = XPathExpressionFactory.createXPathExpression(expression, namespacePrefixes).evaluateAsString(result.getNode());
		weather.setTemperature(temperature);

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getNode
        Source xml = new StreamSource(report);
        Source xslt = new StreamSource(new File(cd,
                "src/main/resources/org/jbehave/hudson/"+new JBehaveInputMetric().getXslName())); 
 
        Result resultOutput = new StreamResult(System.out);
        DOMResult result = new DOMResult();
 
        Transformer transformer = TransformerFactory.newInstance().newTransformer(xslt);
        transformer.transform(xml, result);
        transformer.transform(xml, resultOutput);
        return (Document) result.getNode();
    } 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Java 8 DOMResult Methods: