本文整理汇总了Java中org.w3c.dom.Document.createDocumentFragment方法的典型用法代码示例。如果您正苦于以下问题:Java Document.createDocumentFragment方法的具体用法?Java Document.createDocumentFragment怎么用?Java Document.createDocumentFragment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.Document
的用法示例。
在下文中一共展示了Document.createDocumentFragment方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseInputStream
import org.w3c.dom.Document; //导入方法依赖的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: createDocumentFragment
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Method createDocumentFragment
*
*
* NEEDSDOC (createDocumentFragment) @return
*/
synchronized public DTM createDocumentFragment()
{
try
{
DocumentBuilderFactory dbf = FactoryImpl.getDOMFactory(super.useServicesMechnism());
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Node df = doc.createDocumentFragment();
return getDTM(new DOMSource(df), true, null, false, false);
}
catch (Exception e)
{
throw new DTMException(e);
}
}
示例3: begin
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Implemented to replace the content handler currently in use by a
* NodeBuilder.
*
* @param namespaceURI the namespace URI of the matching element, or an
* empty string if the parser is not namespace aware or the element has
* no namespace
* @param name the local name if the parser is namespace aware, or just
* the element name otherwise
* @param attributes The attribute list of this element
* @throws Exception indicates a JAXP configuration problem
*/
@Override
public void begin(String namespaceURI, String name, Attributes attributes)
throws Exception {
XMLReader xmlReader = getDigester().getXMLReader();
Document doc = documentBuilder.newDocument();
NodeBuilder builder = null;
if (nodeType == Node.ELEMENT_NODE) {
Element element = null;
if (getDigester().getNamespaceAware()) {
element =
doc.createElementNS(namespaceURI, name);
for (int i = 0; i < attributes.getLength(); i++) {
element.setAttributeNS(attributes.getURI(i),
attributes.getLocalName(i),
attributes.getValue(i));
}
} else {
element = doc.createElement(name);
for (int i = 0; i < attributes.getLength(); i++) {
element.setAttribute(attributes.getQName(i),
attributes.getValue(i));
}
}
builder = new NodeBuilder(doc, element);
} else {
builder = new NodeBuilder(doc, doc.createDocumentFragment());
}
xmlReader.setContentHandler(builder);
}
示例4: convertXML
import org.w3c.dom.Document; //导入方法依赖的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: begin
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Implemented to replace the content handler currently in use by a
* NodeBuilder.
*
* @param namespaceURI the namespace URI of the matching element, or an
* empty string if the parser is not namespace aware or the element has
* no namespace
* @param name the local name if the parser is namespace aware, or just
* the element name otherwise
* @param attributes The attribute list of this element
* @throws Exception indicates a JAXP configuration problem
*/
public void begin(String namespaceURI, String name, Attributes attributes)
throws Exception {
XMLReader xmlReader = getDigester().getXMLReader();
Document doc = documentBuilder.newDocument();
NodeBuilder builder = null;
if (nodeType == Node.ELEMENT_NODE) {
Element element = null;
if (getDigester().getNamespaceAware()) {
element =
doc.createElementNS(namespaceURI, name);
for (int i = 0; i < attributes.getLength(); i++) {
element.setAttributeNS(attributes.getURI(i),
attributes.getLocalName(i),
attributes.getValue(i));
}
} else {
element = doc.createElement(name);
for (int i = 0; i < attributes.getLength(); i++) {
element.setAttribute(attributes.getQName(i),
attributes.getValue(i));
}
}
builder = new NodeBuilder(doc, element);
} else {
builder = new NodeBuilder(doc, doc.createDocumentFragment());
}
xmlReader.setContentHandler(builder);
}
示例6: createTestDocumentFragment
import org.w3c.dom.Document; //导入方法依赖的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;
}
示例7: begin
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Implemented to replace the content handler currently in use by a
* NodeBuilder.
*
* @param namespaceURI
* the namespace URI of the matching element, or an empty string
* if the parser is not namespace aware or the element has no
* namespace
* @param name
* the local name if the parser is namespace aware, or just the
* element name otherwise
* @param attributes
* The attribute list of this element
* @throws Exception
* indicates a JAXP configuration problem
*/
@Override
public void begin(String namespaceURI, String name, Attributes attributes) throws Exception {
XMLReader xmlReader = getDigester().getXMLReader();
Document doc = documentBuilder.newDocument();
NodeBuilder builder = null;
if (nodeType == Node.ELEMENT_NODE) {
Element element = null;
if (getDigester().getNamespaceAware()) {
element = doc.createElementNS(namespaceURI, name);
for (int i = 0; i < attributes.getLength(); i++) {
element.setAttributeNS(attributes.getURI(i), attributes.getLocalName(i), attributes.getValue(i));
}
} else {
element = doc.createElement(name);
for (int i = 0; i < attributes.getLength(); i++) {
element.setAttribute(attributes.getQName(i), attributes.getValue(i));
}
}
builder = new NodeBuilder(doc, element);
} else {
builder = new NodeBuilder(doc, doc.createDocumentFragment());
}
xmlReader.setContentHandler(builder);
}
示例8: _createDocumentFragment
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* Creates a DocumentFragment containing the parsed content
* @param markUp JSP Document markup
* @return DocumentFragment containing the parsed content
*/
private static DocumentFragment _createDocumentFragment(
String markUp)
{
// prepend XML declaration
markUp = "<?xml version = '1.0' encoding = 'ISO-8859-1'?>" + markUp;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(false);
DocumentBuilder builder;
try
{
builder = factory.newDocumentBuilder();
}
catch (ParserConfigurationException pce)
{
_LOG.log(Level.WARNING, "Unable to get XML Parser:", pce);
return null;
}
try
{
// use a version explicitly with ISO-8859-1 instead
byte[] markupBytes = markUp.getBytes();
Document newDoc = builder.parse(new ByteArrayInputStream(markupBytes));
DocumentFragment fragment = newDoc.createDocumentFragment();
// add the document's root element to the fragment
fragment.appendChild(newDoc.getDocumentElement());
return fragment;
}
catch (SAXException se)
{
_LOG.log(Level.WARNING, "Unable to parse markup:" + markUp, se);
return null;
}
catch (IOException ioe)
{
_LOG.log(Level.WARNING, "IO Problem with markup:" + markUp, ioe);
return null;
}
}
示例9: nodeset
import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
* This method is an extension that implements as a Xalan extension
* the node-set function also found in xt and saxon.
* If the argument is a Result Tree Fragment, then <code>nodeset</code>
* returns a node-set consisting of a single root node as described in
* section 11.1 of the XSLT 1.0 Recommendation. If the argument is a
* node-set, <code>nodeset</code> returns a node-set. If the argument
* is a string, number, or boolean, then <code>nodeset</code> returns
* a node-set consisting of a single root node with a single text node
* child that is the result of calling the XPath string() function on the
* passed parameter. If the argument is anything else, then a node-set
* is returned consisting of a single root node with a single text node
* child that is the result of calling the java <code>toString()</code>
* method on the passed argument.
* Most of the
* actual work here is done in <code>MethodResolver</code> and
* <code>XRTreeFrag</code>.
* @param myProcessor Context passed by the extension processor
* @param rtf Argument in the stylesheet to the nodeset extension function
*
* NEEDSDOC ($objectName$) @return
*/
public static NodeSet nodeset(ExpressionContext myProcessor, Object rtf)
{
String textNodeValue;
if (rtf instanceof NodeIterator)
{
return new NodeSet((NodeIterator) rtf);
}
else
{
if (rtf instanceof String)
{
textNodeValue = (String) rtf;
}
else if (rtf instanceof Boolean)
{
textNodeValue = new XBoolean(((Boolean) rtf).booleanValue()).str();
}
else if (rtf instanceof Double)
{
textNodeValue = new XNumber(((Double) rtf).doubleValue()).str();
}
else
{
textNodeValue = rtf.toString();
}
// This no longer will work right since the DTM.
// Document myDoc = myProcessor.getContextNode().getOwnerDocument();
Document myDoc = getDocument();
Text textNode = myDoc.createTextNode(textNodeValue);
DocumentFragment docFrag = myDoc.createDocumentFragment();
docFrag.appendChild(textNode);
return new NodeSet(docFrag);
}
}
示例10: DOMBuilderFragmentTagIterator
import org.w3c.dom.Document; //导入方法依赖的package包/类
public DOMBuilderFragmentTagIterator(ParamMapper<F,Element,Document> elementBuilder, Document document) {
this(elementBuilder, document, document.createDocumentFragment());
}