use of javax.xml.transform.dom.DOMSource in project spring-framework by spring-projects.
the class AbstractUnmarshallerTests method unmarshalDomSource.
@Test
public void unmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.newDocument();
Element flightsElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flights");
document.appendChild(flightsElement);
Element flightElement = document.createElementNS("http://samples.springframework.org/flight", "tns:flight");
flightsElement.appendChild(flightElement);
Element numberElement = document.createElementNS("http://samples.springframework.org/flight", "tns:number");
flightElement.appendChild(numberElement);
Text text = document.createTextNode("42");
numberElement.appendChild(text);
DOMSource source = new DOMSource(document);
Object flights = unmarshaller.unmarshal(source);
testFlights(flights);
}
use of javax.xml.transform.dom.DOMSource in project spring-framework by spring-projects.
the class XStreamUnmarshallerTests method unmarshalDomSource.
@Test
public void unmarshalDomSource() throws Exception {
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document document = builder.parse(new InputSource(new StringReader(INPUT_STRING)));
DOMSource source = new DOMSource(document);
Object flight = unmarshaller.unmarshal(source);
testFlight(flight);
}
use of javax.xml.transform.dom.DOMSource in project dbeaver by serge-rider.
the class DBDDocumentXML method serializeDocument.
@Override
public void serializeDocument(@NotNull DBRProgressMonitor monitor, @NotNull OutputStream stream, String encoding) throws DBException {
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
Result output = new StreamResult(new OutputStreamWriter(stream, encoding));
transformer.transform(new DOMSource(document), output);
} catch (Exception e) {
throw new DBException("Error serializing XML document", e);
}
}
use of javax.xml.transform.dom.DOMSource in project nokogiri by sparklemotion.
the class XmlRelaxng method getSchema.
private Schema getSchema(Source source, ThreadContext context) {
InputStream is;
VerifierFactory factory = new com.thaiopensource.relaxng.jarv.VerifierFactoryImpl();
if (source instanceof StreamSource) {
StreamSource ss = (StreamSource) source;
is = ss.getInputStream();
} else {
//if (this.source instanceof DOMSource)
DOMSource ds = (DOMSource) source;
StringWriter xmlAsWriter = new StringWriter();
StreamResult result = new StreamResult(xmlAsWriter);
try {
TransformerFactory.newInstance().newTransformer().transform(ds, result);
} catch (TransformerConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (TransformerException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
try {
is = new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
}
}
try {
return factory.compileSchema(is);
} catch (VerifierConfigurationException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (SAXException ex) {
throw context.getRuntime().newRuntimeError("Could not parse document: " + ex.getMessage());
} catch (IOException ex) {
throw context.getRuntime().newIOError(ex.getMessage());
}
}
use of javax.xml.transform.dom.DOMSource in project nokogiri by sparklemotion.
the class XmlSchema method validate.
protected void validate(Document document) throws SAXException, IOException {
DOMSource docSource = new DOMSource(document);
validator.validate(docSource);
}
Aggregations