當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。