本文整理汇总了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);
}