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


Java DOMSource类代码示例

本文整理汇总了Java中javax.xml.transform.dom.DOMSource的典型用法代码示例。如果您正苦于以下问题:Java DOMSource类的具体用法?Java DOMSource怎么用?Java DOMSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: marshalSamlXmlObject

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
/**
 * Marshal the saml xml object to raw xml.
 *
 * @param object the object
 * @param writer the writer
 * @return the xml string
 */
public String marshalSamlXmlObject(final XMLObject object, final StringWriter writer)  {
    try {
        final MarshallerFactory marshallerFactory = XMLObjectProviderRegistrySupport.getMarshallerFactory();
        final Marshaller marshaller = marshallerFactory.getMarshaller(object);
        if (marshaller == null) {
            throw new IllegalArgumentException("Cannot obtain marshaller for object " + object.getElementQName());
        }
        final Element element = marshaller.marshall(object);
        element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", SAMLConstants.SAML20_NS);
        element.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xenc", "http://www.w3.org/2001/04/xmlenc#");

        final TransformerFactory transFactory = TransformerFactory.newInstance();
        final Transformer transformer = transFactory.newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.transform(new DOMSource(element), new StreamResult(writer));
        return writer.toString();
    } catch (final Exception e) {
        throw new IllegalStateException("An error has occurred while marshalling SAML object to xml", e);
    }
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:29,代码来源:AbstractSamlObjectBuilder.java

示例2: writeOut

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
private static void writeOut(Document doc) throws TransformerException {
	TransformerFactory transformerFactory = TransformerFactory
			.newInstance();
	Transformer transformer = transformerFactory.newTransformer();
	transformer.setOutputProperty(OutputKeys.INDENT, "yes");
	transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
	transformer.setOutputProperty(OutputKeys.STANDALONE, "no");
	DOMSource source = new DOMSource(doc);
	File f = new File("splFile.xml");
	f.delete();
	StreamResult result = new StreamResult(f);

	// Output to console for testing
	// StreamResult result = new StreamResult(System.out);

	transformer.transform(source, result);

	System.out.println("File saved!");

}
 
开发者ID:NeoRoy,项目名称:KeYExperienceReport,代码行数:21,代码来源:SPL2OpltionGenerator.java

示例3: createDocumentFragment

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
/**
 * Method createDocumentFragment
 *
 *
 * NEEDSDOC (createDocumentFragment) @return
 */
synchronized public DTM createDocumentFragment()
{

  try
  {
    DocumentBuilderFactory dbf = FactoryImpl.getDOMFactory(super.useServicesMechnism());
    dbf.setNamespaceAware(true);

    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Node df = doc.createDocumentFragment();

    return getDTM(new DOMSource(df), true, null, false, false);
  }
  catch (Exception e)
  {
    throw new DTMException(e);
  }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:DTMManagerDefault.java

示例4: toString

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
/**
 * Creates the XML representation of this get response. The underlying DOM
 * document will transformed to a string.
 * 
 * @throws RuntimeException
 *             if creation failed
 * @return XML representation of this get response
 */
@Override
public String toString() {
	document.getDocumentElement().normalize();
	TransformerFactory factory = TransformerFactory.newInstance();

	StringWriter sw = new StringWriter();

	try {
		Transformer transformer = factory.newTransformer();

		DOMSource source = new DOMSource(document);
		StreamResult result = new StreamResult(sw);

		transformer.transform(source, result);
	} catch (TransformerException e) {
		throw new RuntimeException(e);
	}

	return sw.toString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:GetResponse.java

示例5: getSources

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
@DataProvider(name = "emptySources")
public Object[][] getSources() throws URISyntaxException {

    return new Object[][]{
        {new DOMSource()},
        {new DOMSource(getDocument())},
        {new SAXSource()},
        {new SAXSource(new InputSource(new StringReader("")))},
        {new SAXSource(getXMLReader(), new InputSource(new StringReader("")))},
        {new StreamSource()},
        {new StreamSource(new ByteArrayInputStream("".getBytes()))},
        {new StreamSource(new StringReader(""))},
        {new StreamSource(new StringReader(""), null)},
        {new StreamSource((String) null)}
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Sources.java

示例6: getDataValidator

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
@DataProvider(name = "data_ValidatorA")
public Object[][] getDataValidator() {
    DOMSource ds = getDOMSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);

    SAXSource ss = new SAXSource(new InputSource(xml_val_test));
    ss.setSystemId(xml_val_test_id);

    StAXSource stax = getStaxSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);
    StAXSource stax1 = getStaxSource(xml_val_test, xml_val_test_id, true, true, xml_catalog);

    StreamSource source = new StreamSource(new File(xml_val_test));

    return new Object[][]{
        // use catalog
        {true, false, true, ds, null, null, xml_catalog, null},
        {false, true, true, ds, null, null, null, xml_catalog},
        {true, false, true, ss, null, null, xml_catalog, null},
        {false, true, true, ss, null, null, null, xml_catalog},
        {true, false, true, stax, null, null, xml_catalog, xml_catalog},
        {false, true, true, stax1, null, null, xml_catalog, xml_catalog},
        {true, false, true, source, null, null, xml_catalog, null},
        {false, true, true, source, null, null, null, xml_catalog},
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:CatalogSupport4.java

示例7: doTransform

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
private void doTransform(String sXSL, OutputStream os) throws javax.xml.transform.TransformerConfigurationException, javax.xml.transform.TransformerException {
    // create the transformerfactory & transformer instance
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer t = tf.newTransformer();

    if (null == sXSL) {
        t.transform(new DOMSource(doc), new StreamResult(os));
        return;
    }

    try {
        Transformer finalTransformer = tf.newTransformer(new StreamSource(sXSL));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(baos);
        t.transform(new DOMSource(doc), new StreamResult(bos));
        bos.flush();
        StreamSource xmlSource = new StreamSource(new BufferedInputStream(new ByteArrayInputStream(baos.toByteArray())));
        finalTransformer.transform(xmlSource, new StreamResult(os));
    } catch (IOException ioe) {
        throw new javax.xml.transform.TransformerException(ioe);
    }
}
 
开发者ID:dmitrykolesnikovich,项目名称:featurea,代码行数:23,代码来源:XMLOutputVisitor.java

示例8: formatXml

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
private static String formatXml(Context context, String src) throws TransformerException,
        ParserConfigurationException, IOException, SAXException {
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Document doc = builder.parse(new InputSource(new StringReader(src)));

    AppSetting setting = new AppSetting(context);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", setting.getTab().length() + "");
    transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");

    //initialize StreamResult with File object to save to file
    StreamResult result = new StreamResult(new StringWriter());
    DOMSource source = new DOMSource(doc);
    transformer.transform(source, result);
    return result.getWriter().toString();
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:18,代码来源:FormatFactory.java

示例9: xmlToString

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
public static String xmlToString(Node node)
{
	try
	{
		Source source = new DOMSource(node);
		StringWriter writer = new StringWriter();
		Result result = new StreamResult(writer);
		Transformer transformer = TransformerFactory.newInstance().newTransformer();
		transformer.transform(source, result);
		return writer.toString();
	}
	catch( Exception e )
	{
		throw new RuntimeException(e);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:17,代码来源:XmlDocument.java

示例10: clear09

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
/**
 * Obtains transformer's parameter whose initiated with a dom source with
 * the a name that set before. Value should be same as set one.
 * @throws Exception If any errors occur.
 */
@Test
public void clear09() throws Exception {
    TransformerFactory tfactory = TransformerFactory.newInstance();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document document = db.parse(new File(XSL_FILE));
    DOMSource domSource = new DOMSource((Node)document);

    Transformer transformer = tfactory.newTransformer(domSource);

    transformer.setParameter(LONG_PARAM_NAME, PARAM_VALUE);
    assertEquals(transformer.getParameter(LONG_PARAM_NAME), PARAM_VALUE);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:TfClearParamTest.java

示例11: test1

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
@Test
public void test1() throws Exception {
    String xsd = "<?xml version='1.0'?>\n" + "<schema xmlns='http://www.w3.org/2001/XMLSchema'\n" + "        xmlns:test='jaxp13_test1'\n"
            + "        targetNamespace='jaxp13_test1'\n" + "        elementFormDefault='qualified'>\n" + "    <element name='test'/>\n" + "</schema>\n";

    DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
    docBuilderFactory.setNamespaceAware(true);
    DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

    Node document = docBuilder.parse(new InputSource(new StringReader(xsd)));
    Assert.assertNotNull(document);

    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    Schema schema = schemaFactory.newSchema(new Source[] { new DOMSource(document) });
    Assert.assertNotNull(schema, "Failed: newSchema returned null.");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:Bug4971605.java

示例12: writeXml

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
/**
 * Writes given xmlDocument to xml file.
 *
 * @param xmlDocument
 */
@SuppressWarnings("unused")
private void writeXml(final Document xmlDocument) {
  Transformer transformer;
  try {
    transformer = TransformerFactory.newInstance().newTransformer();
    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "3");
    final DOMSource source = new DOMSource(xmlDocument);
    // final StreamResult console =
    // new StreamResult(new File("C:/Users/emre.kirmizi/Desktop/out.xml"));
    final StreamResult console =
        new StreamResult(new File("C:/Users/anil.ozturk/Desktop/out.xml"));
    transformer.transform(source, console);
  } catch (TransformerFactoryConfigurationError | TransformerException e) {
    e.printStackTrace();
  }
}
 
开发者ID:ModelWriter,项目名称:Tarski,代码行数:23,代码来源:GraphBuilder.java

示例13: unmarshal

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
@Override
public <T> JAXBElement<T> unmarshal( Source source, Class<T> expectedType ) throws JAXBException {
    if (source instanceof SAXSource) {
        SAXSource ss = (SAXSource) source;

        XMLReader locReader = ss.getXMLReader();
        if (locReader == null) {
            locReader = getXMLReader();
        }

        return unmarshal(locReader, ss.getInputSource(), expectedType);
    }
    if (source instanceof StreamSource) {
        return unmarshal(getXMLReader(), streamSourceToInputSource((StreamSource) source), expectedType);
    }
    if (source instanceof DOMSource) {
        return unmarshal(((DOMSource) source).getNode(), expectedType);
    }

    // we don't handle other types of Source
    throw new IllegalArgumentException();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:UnmarshallerImpl.java

示例14: validateXml

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
@SneakyThrows
public void validateXml(String xsdPath, boolean namespaceAware, String schemaLanguage, String pageBody) {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

    factory.setNamespaceAware(namespaceAware);

    DocumentBuilder builder = factory.newDocumentBuilder();
    org.w3c.dom.Document document = builder.parse(new InputSource(new StringReader(pageBody)));

    SchemaFactory schemaFactory = SchemaFactory.newInstance(schemaLanguage);
    Source schemaSource = new StreamSource(getClass().getResourceAsStream(xsdPath));

    Schema schema = schemaFactory.newSchema(schemaSource);
    Validator validator = schema.newValidator();
    Source source = new DOMSource(document);
    validator.setErrorHandler(new XmlErrorHandler());
    validator.validate(source);
}
 
开发者ID:christian-draeger,项目名称:page-content-tester,代码行数:19,代码来源:XmlErrorHandler.java

示例15: nodeToString

import javax.xml.transform.dom.DOMSource; //导入依赖的package包/类
/**
 * Converts the Node/Document/Element instance to XML payload.
 *
 * @param node the node/document/element instance to convert
 * @return the XML payload representing the node/document/element
 * @throws AlipayApiException problem converting XML to string
 */
public static String nodeToString(Node node) throws AlipayApiException {
	String payload = null;

	try {
		Transformer tf = TransformerFactory.newInstance().newTransformer();

		Properties props = tf.getOutputProperties();
		props.setProperty(OutputKeys.INDENT, LOGIC_YES);
		props.setProperty(OutputKeys.ENCODING, DEFAULT_ENCODE);
		tf.setOutputProperties(props);

		StringWriter writer = new StringWriter();
		tf.transform(new DOMSource(node), new StreamResult(writer));
		payload = writer.toString();
		payload = payload.replaceAll(REG_INVALID_CHARS, " ");
	} catch (TransformerException e) {
		throw new AlipayApiException("XML_TRANSFORM_ERROR", e);
	}

	return payload;
}
 
开发者ID:funtl,项目名称:framework,代码行数:29,代码来源:XmlUtils.java


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