本文整理匯總了Java中org.w3c.dom.EntityReference.getFirstChild方法的典型用法代碼示例。如果您正苦於以下問題:Java EntityReference.getFirstChild方法的具體用法?Java EntityReference.getFirstChild怎麽用?Java EntityReference.getFirstChild使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.w3c.dom.EntityReference
的用法示例。
在下文中一共展示了EntityReference.getFirstChild方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: startEntity
import org.w3c.dom.EntityReference; //導入方法依賴的package包/類
public void startEntity(String name)
throws SAXException
{
if (interrupted)
return;
DocumentType doctype = doc.getDoctype();
if (doctype == null)
{
throw new SAXException("SAX parser error: " +
"reference to entity in undeclared doctype");
}
if ("[dtd]".equals(name) || name.charAt(0) == '%')
return;
if (PREDEFINED_ENTITIES.contains(name))
return;
// Get entity
NamedNodeMap entities = doctype.getEntities();
Entity entity = (Entity) entities.getNamedItem(name);
if (entity == null)
{
throw new SAXException("SAX parser error: " +
"reference to undeclared entity: " + name);
}
EntityReference ref = doc.createEntityReference(name);
// DomDocument populates with the entity replacement text, remove this
Node child = ref.getFirstChild();
while (child != null)
{
Node nextChild = child.getNextSibling();
ref.removeChild(child);
child = nextChild;
}
ctx.appendChild(ref);
ctx = ref;
}
示例2: endEntity
import org.w3c.dom.EntityReference; //導入方法依賴的package包/類
public void endEntity(String name)
throws SAXException
{
if (interrupted)
return;
if ("[dtd]".equals(name) || name.charAt(0) == '%')
return;
if (PREDEFINED_ENTITIES.contains(name))
return;
// Get entity reference
EntityReference ref = (EntityReference) ctx;
if (!ref.getNodeName().equals(name))
throw new SAXException("expecting end of "+ref.getNodeName()+" entity");
ctx = ctx.getParentNode();
if (ref instanceof DomNode)
((DomNode) ref).makeReadonly();
if (expandEntityReferences)
{
// Move entity content from reference node onto context
Node child = ref.getFirstChild();
while (child != null)
{
Node nextChild = child.getNextSibling();
ctx.appendChild(child);
child = nextChild;
}
ctx.removeChild(ref);
}
}