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


Java DocumentBuilder.newDocument方法代码示例

本文整理汇总了Java中javax.xml.parsers.DocumentBuilder.newDocument方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentBuilder.newDocument方法的具体用法?Java DocumentBuilder.newDocument怎么用?Java DocumentBuilder.newDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.parsers.DocumentBuilder的用法示例。


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

示例1: testCreateStartDocument_DOMWriter

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:XMLStreamWriterTest.java

示例2: marshalToNode

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
/**
 * Marshals a {@link JAXBElement} to a xml node.
 *
 * @param element The element that should be marshaled
 * @param clazz class of the ObjectFactory
 * @return Node representing the input {@code element}
 * @throws ExportException Exception while exporting
 */
protected static Node marshalToNode(JAXBElement element, Class clazz)
        throws ExportException {
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.newDocument();
        JAXBContext context = JAXBContext.newInstance(clazz);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
        marshaller.marshal(element, document);
        return document.getDocumentElement();
    } catch (ParserConfigurationException | JAXBException e) {
        throw new ExportException(e);
    }
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:24,代码来源:XmlExporter.java

示例3: clear

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
public void clear()
{
	DocumentBuilder builder = null;
	try
	{

		builder = getBuilder();
		Document doc = builder.newDocument();

		// Create the empty Propbag
		final Element root = doc.createElement("xml"); //$NON-NLS-1$
		doc.appendChild(root);

		// Get the root element
		m_elRoot = doc.getDocumentElement();
	}
	finally
	{
		releaseBuilder(builder);
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:22,代码来源:PropBagEx.java

示例4: newDocument

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
/**
* Returns a new empty Document.
* @return A new empty Document.
*/
public static Document newDocument() {
	Document doc;
	String magicValue=System.getProperty("javax.xml.parsers.DocumentBuilderFactory");
   	System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
	DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
	try {
		DocumentBuilder db=dbf.newDocumentBuilder();
		doc=db.newDocument();
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
   	if (magicValue==null)
   		System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");
   	else
   		System.setProperty("javax.xml.parsers.DocumentBuilderFactory",magicValue);
	return doc;
}
 
开发者ID:costea7,项目名称:ChronoBike,代码行数:22,代码来源:XmlHelper.java

示例5: main

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();

    DOMImplementation impl = document.getImplementation();
    DOMImplementationLS implLS = (DOMImplementationLS) impl.getFeature("LS", "3.0");
    LSSerializer dsi = implLS.createLSSerializer();

    /* We should have here incorrect document without getXmlVersion() method:
     * Such Document is generated by replacing the JDK bootclasses with it's
     * own Node,Document and DocumentImpl classes (see run.sh). According to
     * XERCESJ-1007 the AbstractMethodError should be thrown in such case.
     */
    String result = dsi.writeToString(document);
    System.out.println("Result:" + result);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:AbstractMethodErrorTest.java

示例6:

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
/**
 * スキーマありBoxへのインストールでACL_URL中のBoxが不正の場合にバリデートがfalseで返却されること.
 */
@Test
@Ignore
public void スキーマありBoxへのインストールでACL_URL中のBoxが不正の場合にバリデートがfalseで返却されること() {
    // アプリセルではない
    final String baseUrl = "https://targetserver/testcell1/__role/_x_/col1/";
    final String schemaUrl = "https://targetserver/testcell1/";
    try {
        DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docbuilder;
        docbuilder = dbfactory.newDocumentBuilder();
        Document document = docbuilder.newDocument();
        Element element = document.createElement("acl");
        element.setAttribute("xml:base", baseUrl);

        assertFalse(BarFileUtils.aclNameSpaceValidate("90_rootprops.xml", element, schemaUrl));
        return;
    } catch (ParserConfigurationException e) {
        fail("DOM Parsing Error: " + e.getMessage());
    } catch (PersoniumCoreException dce) {
        String code = dce.getCode();
        assertEquals(PersoniumCoreException.BarInstall.JSON_FILE_FORMAT_ERROR.getCode(), code);
        return;
    } catch (Exception ex) {
        fail("Unexpected exception");
    }
    fail("PersoniumCoreExceptionが返却されない");
}
 
开发者ID:personium,项目名称:personium-core,代码行数:31,代码来源:BarFileUtilsTest.java

示例7: createDocument

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
/**
 * @return New XML document from the default document builder factory.
 */
private static Document createDocument()
{
	DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
	DocumentBuilder builder;
	try
	{
		builder = factory.newDocumentBuilder();
	}
	catch (ParserConfigurationException e)
	{
		throw new RuntimeException(e.getMessage(), e);
	}
	return builder.newDocument();
}
 
开发者ID:starn,项目名称:encdroidMC,代码行数:18,代码来源:SardineUtil.java

示例8: SAX2DOMBuilder

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
/**
 * <p>Creates a new instance of SAX2DOMBuilder, which creates
 * a new document. The document is available via
 * {@link #getDocument()}.</p>
 * @throws javax.xml.parsers.ParserConfigurationException
 */
public SAX2DOMBuilder() throws ParserConfigurationException {

    DocumentBuilderFactory documentBuilderFactory;
    DocumentBuilder        documentBuilder;

    documentBuilderFactory = DocumentBuilderFactory.newInstance();

    documentBuilderFactory.setValidating(false);
    documentBuilderFactory.setNamespaceAware(true);

    documentBuilder  = documentBuilderFactory.newDocumentBuilder();
    this.document    = documentBuilder.newDocument();
    this.currentNode = this.document;
}
 
开发者ID:Julien35,项目名称:dev-courses,代码行数:21,代码来源:JDBCSQLXML.java

示例9: saveEmitter

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
/**
 * Save a single emitter to the XML file
 * 
 * @param out
 *            The location to which we should save
 * @param emitter
 *            The emitter to store to the XML file
 * @throws IOException
 *             Indicates a failure to write or encode the XML
 */
public static void saveEmitter(OutputStream out, ConfigurableEmitter emitter)
		throws IOException {
	try {
		DocumentBuilder builder = DocumentBuilderFactory.newInstance()
				.newDocumentBuilder();
		Document document = builder.newDocument();

		document.appendChild(emitterToElement(document, emitter));
		Result result = new StreamResult(new OutputStreamWriter(out,
				"utf-8"));
		DOMSource source = new DOMSource(document);

		TransformerFactory factory = TransformerFactory.newInstance();
		Transformer xformer = factory.newTransformer();
		xformer.setOutputProperty(OutputKeys.INDENT, "yes");

		xformer.transform(source, result);
	} catch (Exception e) {
		Log.error(e);
		throw new IOException("Failed to save emitter");
	}
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-C,代码行数:33,代码来源:ParticleIO.java

示例10: newDocument

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
/** {@inheritDoc} */
public Document newDocument() throws XMLParserException {
    DocumentBuilder builder = getBuilder();
    Document document = builder.newDocument();
    returnBuilder(builder);
    return document;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:StaticBasicParserPool.java

示例11: convertToXml

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
public String convertToXml(Object obj) throws Exception{
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	
	DocumentBuilder db = dbf.newDocumentBuilder();
	
	Document doc = db.newDocument();

	Element ele = doc.createElement(obj.getClass().getSimpleName().toLowerCase());
	
	Field[] fields = obj.getClass().getDeclaredFields();
	
	for (Field field : fields) {
		field.setAccessible(true);
		Node node = doc.createElement(field.getName());
		String value = field.get(obj).toString();
		if(value.startsWith("<?xml")){
			Element xmlEle = stringToElement(value);
			Node xmlNode = doc.importNode(xmlEle, true);
			node.appendChild(xmlNode);
		} else {
			node.setTextContent(value);	
		}
		
		ele.appendChild(node);
	}
	
	doc.appendChild(ele);
	
	return toXmlString(doc);
}
 
开发者ID:manikmagar,项目名称:adobe-air-db-connector,代码行数:31,代码来源:XmlEncoder.java

示例12: Java2DExample

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
public Java2DExample() {
    setCaption("SVG using java.awt.Graphics2D");
    
    addComponent(new Label(
            "This graphic is created with java.awt.Graphics2D API and made to SVG with Batik."));
    
    try {
        
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
                .newInstance();
        DocumentBuilder docBuilder = null;
        docBuilder = docBuilderFactory.newDocumentBuilder();
        Document document = docBuilder.newDocument();
        Element svgelem = document.createElement("svg");
        document.appendChild(svgelem);

        // Create an instance of the SVG Generator
        SVGGraphics2D graphic2d = new SVGGraphics2D(document);
        drawDemo(widht, height, graphic2d);

        // svgweb (IE fallback) needs size somehow defined
        Element el = graphic2d.getRoot();
        el.setAttributeNS(null, "viewBox", "0 0 " + widht
                + " " + height + "");
        el.setAttributeNS(null, "style",
                "width:100%;height:100%;");

        // Finally, stream out SVG to the standard output using
        // UTF-8 encoding.
        boolean useCSS = true; // we want to use CSS style attributes
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        Writer out = new OutputStreamWriter(bout, "UTF-8");
        graphic2d.stream(el, out, useCSS, false);
        
        Embedded svgComponent = new Embedded();
        svgComponent.setWidth(widht, Unit.PIXELS);
        svgComponent.setHeight(height, Unit.PIXELS);
        
        Resource svg = new StreamResource(() -> new ByteArrayInputStream(bout.toByteArray()), "graphics.svg");
        svgComponent.setSource(svg);
        addComponent(svgComponent);
        
    } catch (Exception e1) {
        throw new RuntimeException(e1);
    }
    
}
 
开发者ID:mstahv,项目名称:svgexamples,代码行数:48,代码来源:Java2DExample.java

示例13: newDoc

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
public static Document newDoc() throws ParserConfigurationException {
  DocumentBuilderFactory factory = FortifyUtils.getSecurityXmlDocumentFactory();
  DocumentBuilder builder = factory.newDocumentBuilder();
  return builder.newDocument();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:6,代码来源:XmlLoaderUtils.java

示例14: createXmlDocument

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
protected Document createXmlDocument () throws ParserConfigurationException
{
    final DocumentBuilder db = this.dbf.newDocumentBuilder ();
    final Document doc = db.newDocument ();
    return doc;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:7,代码来源:XMLBase.java

示例15: getDocument

import javax.xml.parsers.DocumentBuilder; //导入方法依赖的package包/类
/**
 * Returns a new Archive XML Document used to store simulation and GUI data
 * @param model data structure
 * @param documentName name of created document (to be setted into root element)
 * @return created Document
 */
public static Document getDocument(CommonModel model, String documentName) {
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	DocumentBuilder docBuilder = null;
	try {
		docBuilder = dbf.newDocumentBuilder();
	} catch (ParserConfigurationException e) {
		e.printStackTrace();
		return null;
	}
	Document archiveDoc = docBuilder.newDocument();
	// Retrives documents from XMLWriter and GuiXMLWriter
	Document sim = XMLWriter.getDocument(model, documentName);
	Document jmodel;
	Document results = null;
	// Stores gui information
	jmodel = GuiXMLWriter.getDocument(model);
	// If results are present, store them. Do not store results if parametric
	// analysis is enabled but results are from normal simulation, or if parametric
	// is not enabled but results come from a parametric simulation
	if (model.containsSimulationResults()) {
		if (model.isParametricAnalysisEnabled() && (model.getSimulationResults() instanceof PAResultsModel)) {
			results = XMLResultsWriter.getDocument(model.getSimulationResults());
		} else if (!model.isParametricAnalysisEnabled() && (!(model.getSimulationResults() instanceof PAResultsModel))) {
			results = XMLResultsWriter.getDocument(model.getSimulationResults());
		}
	}

	Element root = archiveDoc.createElement(XML_ARCHIVE_DOCUMENT_ROOT);
	archiveDoc.appendChild(root);

	// Adds sim and jmodel root elements to Archive root
	root.appendChild(archiveDoc.importNode(sim.getElementsByTagName(XMLConstantNames.XML_DOCUMENT_ROOT).item(0), true));
	if (jmodel != null) {
		root.appendChild(archiveDoc.importNode(jmodel.getElementsByTagName(XML_DOCUMENT_ROOT).item(0), true));
	}
	// Adds simulation results idf present
	if (results != null) {
		root.appendChild(archiveDoc.importNode(results.getElementsByTagName(XMLResultsConstants.XML_DOCUMENT_ROOT).item(0), true));
	}

	// Adds root attributes
	root.setAttribute("xsi:noNamespaceSchemaLocation", XML_ARCHIVE_DOCUMENT_XSD);
	root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
	root.setAttribute(XML_ARCHIVE_A_NAME, documentName);
	root.setAttribute(XML_ARCHIVE_A_TIMESTAMP, new Date().toString());

	return archiveDoc;
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:55,代码来源:XMLArchiver.java


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