本文整理匯總了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}
示例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));
}
示例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);
}