当前位置: 首页>>代码示例>>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;未经允许,请勿转载。