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


Java DocumentFragment.appendChild方法代码示例

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


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

示例1: parseInputStream

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/**
 * Parse the specified input stream in a DOM DocumentFragment, owned by the specified Document.
 * 
 * @param input the InputStream to parse
 * @param owningDocument the Document which will own the returned DocumentFragment
 * @return a DocumentFragment
 * @throws DecryptionException thrown if there is an error parsing the input stream
 */
private DocumentFragment parseInputStream(InputStream input, Document owningDocument) throws DecryptionException {
    // Since Xerces currently seems not to handle parsing into a DocumentFragment
    // without a bit hackery, use this to simulate, so we can keep the API
    // the way it hopefully will look in the future. Obviously this only works for
    // input streams containing valid XML instances, not fragments.

    Document newDocument = null;
    try {
        newDocument = parserPool.parse(input);
    } catch (XMLParserException e) {
        log.error("Error parsing decrypted input stream", e);
        throw new DecryptionException("Error parsing input stream", e);
    }

    Element element = newDocument.getDocumentElement();
    owningDocument.adoptNode(element);

    DocumentFragment container = owningDocument.createDocumentFragment();
    container.appendChild(element);

    return container;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:Decrypter.java

示例2: getLayoutMasterSetFragment

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public static DocumentFragment getLayoutMasterSetFragment(AbstractWmlConversionContext context) {

		LayoutMasterSet lms = getFoLayoutMasterSet(context);	
		
		// Set suitable extents, for which we need area tree 
		FOSettings foSettings = (FOSettings)context.getConversionSettings();
		if ( !foSettings.lsLayoutMasterSetCalculationInProgress()) // Avoid infinite loop
			// Can't just do it where foSettings.getApacheFopMime() is not MimeConstants.MIME_FOP_AREA_TREE,
			// since TOC functionality uses that.
		{
			fixExtents( lms, context, true);
		}
		
		org.w3c.dom.Document document = XmlUtils.marshaltoW3CDomDocument(lms, Context.getXslFoContext() );
		DocumentFragment docfrag = document.createDocumentFragment();
		docfrag.appendChild(document.getDocumentElement());
		
		
		return docfrag;		
	}
 
开发者ID:plutext,项目名称:docx4j-export-FO,代码行数:21,代码来源:LayoutMasterSetBuilder.java

示例3: appendNormalized

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/**
 * Given one or two nodes, see if the two can be combined.
 * If two are passed in, they might be combined into one and returned, or
 * the first will be appended to parent, and the other returned.
 */
private Node appendNormalized(
    Node pending, Node current, DocumentFragment parent) {
  if (pending == null) { return current; }
  if (pending.getNodeType() != Node.TEXT_NODE
      || current.getNodeType() != Node.TEXT_NODE) {
    parent.appendChild(pending);
    return current;
  }
  Text a = (Text) pending, b = (Text) current;
  Text combined = doc.createTextNode(a.getTextContent() + b.getTextContent());
  if (needsDebugData) {
    Nodes.setFilePositionFor(
        combined,
        FilePosition.span(
            Nodes.getFilePositionFor(a),
            Nodes.getFilePositionFor(b)));
    Nodes.setRawText(combined, Nodes.getRawText(a) + Nodes.getRawText(b));
  }
  return combined;
}
 
开发者ID:google,项目名称:caja,代码行数:26,代码来源:Html5ElementStack.java

示例4: convertXML

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
@Override
protected DocumentFragment convertXML(Element xmlValue) throws ConverterException {
	Document doc = xmlValue.getOwnerDocument();
	DocumentFragment result = doc.createDocumentFragment();
	for (Node child : XMLUtils.childrenNodes(xmlValue)) {
		Node clone = child.cloneNode(true);
		result.appendChild(clone);
	}
	return result;
}
 
开发者ID:Bibliome,项目名称:alvisnlp,代码行数:11,代码来源:DOMParamConverter.java

示例5: createTestDocumentFragment

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
private DocumentFragment createTestDocumentFragment(Document document) {
    DocumentFragment docFragment = document.createDocumentFragment();
    Element elem = document.createElement("dfElement");
    elem.appendChild(document.createTextNode("Text in it"));
    docFragment.appendChild(elem);
    return docFragment;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:NodeTest.java

示例6: deserialize

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/**
 * @param ctx
 * @param inputSource
 * @return the Node resulting from the parse of the source
 * @throws XMLEncryptionException
 */
private Node deserialize(Node ctx, InputSource inputSource) throws XMLEncryptionException {
    try {
        if (dbf == null) {
            dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);
            dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
            dbf.setAttribute("http://xml.org/sax/features/namespaces", Boolean.TRUE);
            dbf.setValidating(false);
        }
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document d = db.parse(inputSource);

        Document contextDocument = null;
        if (Node.DOCUMENT_NODE == ctx.getNodeType()) {
            contextDocument = (Document)ctx;
        } else {
            contextDocument = ctx.getOwnerDocument();
        }

        Element fragElt =
                (Element) contextDocument.importNode(d.getDocumentElement(), true);
        DocumentFragment result = contextDocument.createDocumentFragment();
        Node child = fragElt.getFirstChild();
        while (child != null) {
            fragElt.removeChild(child);
            result.appendChild(child);
            child = fragElt.getFirstChild();
        }
        return result;
    } catch (SAXException se) {
        throw new XMLEncryptionException("empty", se);
    } catch (ParserConfigurationException pce) {
        throw new XMLEncryptionException("empty", pce);
    } catch (IOException ioe) {
        throw new XMLEncryptionException("empty", ioe);
    }
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:44,代码来源:DocumentSerializer.java

示例7: parseFolder

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
private DocumentFragment parseFolder(String path, Document doc, Deque<FolderElement> folderStack) {
    DocumentFragment fragment = doc.createDocumentFragment();
    File[] files = new File(path).listFiles();
    if (files == null) return fragment;
    for (int i = 0; i < files.length; i++) {
        String currentPath = files[i].getPath();
        currentPath = currentPath.replace('\\', '/');
        if (files[i].isDirectory()) {
            FolderElement folderElement = new FolderElement(currentPath);
            folderStack.peekLast().getChildren().add(folderElement);
            folderStack.add(folderElement);
            org.w3c.dom.Element folder = doc.createElement("folder");
            folder.setAttribute("path", currentPath);
            fragment.appendChild(folder);
            folder.appendChild(parseFolder(currentPath, doc, folderStack));
            folderStack.removeLast();
        }
        if (files[i].isFile()) {
            FileElement fileElement = new FileElement(currentPath, files[i].length(), hashFile(currentPath));
            folderStack.peekLast().getChildren().add(fileElement);
            org.w3c.dom.Element file = doc.createElement("file");
            file.setAttribute("path", fileElement.getPath());
            file.setAttribute("size", fileElement.getSize() + "");
            file.setAttribute("hash", fileElement.getHash());
            fragment.appendChild(file);
        }
    }
    return fragment;
}
 
开发者ID:WarpOrganization,项目名称:warp,代码行数:30,代码来源:FileStructureGenerator.java

示例8: deserialize

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/**
 * @param ctx
 * @param inputSource
 * @return the Node resulting from the parse of the source
 * @throws XMLEncryptionException
 */
private Node deserialize(Node ctx, InputSource inputSource)
		throws XMLEncryptionException {
	try {
		DocumentBuilder db = XMLUtils.createDocumentBuilder(false,
				secureValidation);
		Document d = db.parse(inputSource);

		Document contextDocument = null;
		if (Node.DOCUMENT_NODE == ctx.getNodeType()) {
			contextDocument = (Document) ctx;
		} else {
			contextDocument = ctx.getOwnerDocument();
		}

		Element fragElt = (Element) contextDocument.importNode(
				d.getDocumentElement(), true);
		DocumentFragment result = contextDocument.createDocumentFragment();
		Node child = fragElt.getFirstChild();
		while (child != null) {
			fragElt.removeChild(child);
			result.appendChild(child);
			child = fragElt.getFirstChild();
		}
		return result;
	} catch (SAXException se) {
		throw new XMLEncryptionException("empty", se);
	} catch (ParserConfigurationException pce) {
		throw new XMLEncryptionException("empty", pce);
	} catch (IOException ioe) {
		throw new XMLEncryptionException("empty", ioe);
	}
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:39,代码来源:DocumentSerializer.java

示例9: deserialize

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
/**
 * @param ctx
 * @param inputSource
 * @return the Node resulting from the parse of the source
 * @throws XMLEncryptionException
 */
private Node deserialize(Node ctx, InputSource inputSource) throws XMLEncryptionException {
    DocumentBuilder db = null;
    try {
        db = XMLUtils.createDocumentBuilder(false, secureValidation);
        Document d = db.parse(inputSource);

        Document contextDocument = null;
        if (Node.DOCUMENT_NODE == ctx.getNodeType()) {
            contextDocument = (Document)ctx;
        } else {
            contextDocument = ctx.getOwnerDocument();
        }

        Element fragElt =
                (Element) contextDocument.importNode(d.getDocumentElement(), true);
        DocumentFragment result = contextDocument.createDocumentFragment();
        Node child = fragElt.getFirstChild();
        while (child != null) {
            fragElt.removeChild(child);
            result.appendChild(child);
            child = fragElt.getFirstChild();
        }
        return result;
    } catch (SAXException se) {
        throw new XMLEncryptionException(se);
    } catch (ParserConfigurationException pce) {
        throw new XMLEncryptionException(pce);
    } catch (IOException ioe) {
        throw new XMLEncryptionException(ioe);
    } finally {
        if (db != null) {
            XMLUtils.repoolDocumentBuilder(db);
        }
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:42,代码来源:DocumentSerializer.java

示例10: asDocumentFragment

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public DocumentFragment asDocumentFragment() throws OpenRDFException,
		TransformerException, IOException, ParserConfigurationException {
	Document doc = asDocument();
	DocumentFragment frag = doc.createDocumentFragment();
	frag.appendChild(doc.getDocumentElement());
	return frag;
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:8,代码来源:SparqlEvaluator.java

示例11: testAddSingleElement

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public void testAddSingleElement() throws Exception {
	ObjectFactory of = con.getObjectFactory();
	Entity entity = con.addDesignation(of.createObject(), Entity.class);
	Document doc = parse("<element/>");
	DocumentFragment frag = doc.createDocumentFragment();
	frag.appendChild(doc.getDocumentElement());
	entity.setXML(frag);
	RepositoryResult<Statement> results = con.getStatements(entity.getResource(), pred, null);
	String xml = results.next().getObject().stringValue();
	results.close();
	assertEquals("<element/>", xml);
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:13,代码来源:DocumentFragmentTest.java

示例12: testReadSingleElement

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public void testReadSingleElement() throws Exception {
	ObjectFactory of = con.getObjectFactory();
	Entity entity = con.addDesignation(of.createObject(), Entity.class);
	Document doc = parse("<element/>");
	DocumentFragment frag = doc.createDocumentFragment();
	frag.appendChild(doc.getDocumentElement());
	String before = toString(frag);
	entity.setXML(frag);
	entity = (Entity) con.getObject(entity.getResource());
	frag = entity.getXML();
	assertEquals(before, toString(frag));
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:13,代码来源:DocumentFragmentTest.java

示例13: testAddMultipleElements

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public void testAddMultipleElements() throws Exception {
	ObjectFactory of = con.getObjectFactory();
	Entity entity = con.addDesignation(of.createObject(), Entity.class);
	Document doc = parse("<element><first/><second/></element>");
	DocumentFragment frag = doc.createDocumentFragment();
	frag.appendChild(doc.getDocumentElement().getFirstChild());
	frag.appendChild(doc.getDocumentElement().getLastChild());
	entity.setXML(frag);
	RepositoryResult<Statement> results = con.getStatements(entity.getResource(), pred, null);
	String xml = results.next().getObject().stringValue();
	results.close();
	assertEquals("<first/><second/>", xml);
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:14,代码来源:DocumentFragmentTest.java

示例14: testReadMultipleElements

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public void testReadMultipleElements() throws Exception {
	ObjectFactory of = con.getObjectFactory();
	Entity entity = con.addDesignation(of.createObject(), Entity.class);
	Document doc = parse("<element><first/><second/></element>");
	DocumentFragment frag = doc.createDocumentFragment();
	frag.appendChild(doc.getDocumentElement().getFirstChild());
	frag.appendChild(doc.getDocumentElement().getLastChild());
	String before = toString(frag);
	entity.setXML(frag);
	entity = (Entity) con.getObject(entity.getResource());
	DocumentFragment xml = entity.getXML();
	assertEquals(before, toString(xml));
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:14,代码来源:DocumentFragmentTest.java

示例15: testAddNamespaceElement

import org.w3c.dom.DocumentFragment; //导入方法依赖的package包/类
public void testAddNamespaceElement() throws Exception {
	String xml = "<a:Box xmlns:a=\"http://example.org/a#\" required=\"true\"><a:widget size=\"10\"> </a:widget><a:grommit id=\"23\"> text </a:grommit></a:Box>";
	Document doc = parse(xml);
	ObjectFactory of = con.getObjectFactory();
	Entity entity = con.addDesignation(of.createObject(), Entity.class);
	DocumentFragment frag = doc.createDocumentFragment();
	frag.appendChild(doc.getDocumentElement());
	entity.setXML(frag);
	RepositoryResult<Statement> resuts = con.getStatements(entity.getResource(), pred, null);
	String label = resuts.next().getObject().stringValue();
	resuts.close();
	assertEquals(xml, label);
}
 
开发者ID:anno4j,项目名称:anno4j,代码行数:14,代码来源:DocumentFragmentTest.java


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