當前位置: 首頁>>代碼示例>>Java>>正文


Java Document.createDocumentFragment方法代碼示例

本文整理匯總了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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:31,代碼來源:Decrypter.java

示例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);
  }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:DTMManagerDefault.java

示例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);

}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:44,代碼來源:NodeCreateRule.java

示例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;
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:11,代碼來源:DOMParamConverter.java

示例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);

}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:43,代碼來源:NodeCreateRule.java

示例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;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:NodeTest.java

示例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);

}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:43,代碼來源:NodeCreateRule.java

示例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;
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:55,代碼來源:ChangeBean.java

示例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);
  }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:63,代碼來源:Extensions.java

示例10: DOMBuilderFragmentTagIterator

import org.w3c.dom.Document; //導入方法依賴的package包/類
public DOMBuilderFragmentTagIterator(ParamMapper<F,Element,Document> elementBuilder, Document document) {
	this(elementBuilder, document, document.createDocumentFragment());
}
 
開發者ID:Bibliome,項目名稱:bibliome-java-utils,代碼行數:4,代碼來源:DOMBuilderFragmentTagIterator.java


注:本文中的org.w3c.dom.Document.createDocumentFragment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。