本文整理匯總了Java中org.w3c.dom.Document.createEntityReference方法的典型用法代碼示例。如果您正苦於以下問題:Java Document.createEntityReference方法的具體用法?Java Document.createEntityReference怎麽用?Java Document.createEntityReference使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.Document
的用法示例。
在下文中一共展示了Document.createEntityReference方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testEntityReference
import org.w3c.dom.Document; //導入方法依賴的package包/類
@Test
public void testEntityReference() {
try {
Document xmlDocument = createNewDocument();
EntityReference erefNode = xmlDocument.createEntityReference("entityref");
String outerXML = getOuterXML(erefNode);
System.out.println("OuterXML of Comment Node is:" + outerXML);
} catch (Exception e) {
e.printStackTrace();
Assert.fail("Exception occured: " + e.getMessage());
}
}
示例2: importNode
import org.w3c.dom.Document; //導入方法依賴的package包/類
private Node importNode(final Document doc, final Node n, final boolean bDeep)
{
Node dest;
final int type = n.getNodeType();
switch( type )
{
case Node.ELEMENT_NODE:
dest = doc.createElement(n.getNodeName());
final NamedNodeMap nnm = n.getAttributes();
final int nnmCount = nnm.getLength();
for( int i = 0; i < nnmCount; i++ )
{
final Attr attr = (Attr) nnm.item(i);
((Element) dest).setAttribute(attr.getName(), attr.getValue());
}
break;
case Node.TEXT_NODE:
dest = doc.createTextNode(n.getNodeValue());
break;
case Node.CDATA_SECTION_NODE:
dest = doc.createCDATASection(n.getNodeValue());
break;
case Node.ENTITY_REFERENCE_NODE:
dest = doc.createEntityReference(n.getNodeValue());
break;
// see Jira Defect TLE-1832 :
// http://apps.dytech.com.au/jira/browse/TLE-1832
case Node.COMMENT_NODE:
dest = doc.createComment(n.getNodeValue());
break;
default:
throw new RuntimeException("Unsupported DOM Node: " + type);
}
if( bDeep )
{
for( Node child = n.getFirstChild(); child != null; child = child.getNextSibling() )
{
dest.appendChild(importNode(doc, child, true));
}
}
return dest;
}