本文整理汇总了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);
}
}