org.w3c.dom.Entity类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(15.5k)|赞(0)|评价(0)|浏览(212)

本文整理了Java中org.w3c.dom.Entity类的一些代码示例,展示了Entity类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity类的具体详情如下:
包路径:org.w3c.dom.Entity
类名称:Entity

Entity介绍

[英]This interface represents a known entity, either parsed or unparsed, in an XML document. Note that this models the entity itself not the entity declaration.

The nodeName attribute that is inherited from Node contains the name of the entity.

An XML processor may choose to completely expand entities before the structure model is passed to the DOM; in this case there will be no EntityReference nodes in the document tree.

XML does not mandate that a non-validating XML processor read and process entity declarations made in the external subset or declared in parameter entities. This means that parsed entities declared in the external subset need not be expanded by some classes of applications, and that the replacement text of the entity may not be available. When the replacement text is available, the corresponding Entity node's child list represents the structure of that replacement value. Otherwise, the child list is empty.

DOM Level 3 does not support editing Entity nodes; if a user wants to make changes to the contents of an Entity, every related EntityReference node has to be replaced in the structure model by a clone of the Entity's contents, and then the desired changes must be made to each of those clones instead. Entity nodes and all their descendants are readonly.

An Entity node does not have any parent.

Note: If the entity contains an unbound namespace prefix, the namespaceURI of the corresponding node in the Entity node subtree is null. The same is true for EntityReference nodes that refer to this entity, when they are created using the createEntityReference method of the Document interface.

See also the Document Object Model (DOM) Level 3 Core Specification.
[中]此接口表示XML文档中已解析或未解析的已知实体。请注意,这是对实体本身建模,而不是对实体声明建模。
继承自NodenodeName属性包含实体的名称。
XML处理器可以选择在结构模型传递给DOM之前完全扩展实体;在这种情况下,文档树中将没有EntityReference节点。
XML并不要求非验证性XML处理器读取和处理在外部子集中或在参数实体中声明的实体声明。这意味着在外部子集中声明的已解析实体不需要由某些应用程序类扩展,并且实体的替换文本可能不可用。当replacement text可用时,相应的Entity节点的子列表表示替换值的结构。否则,子列表为空。
DOM级别3不支持编辑Entity节点;如果用户希望更改Entity的内容,则结构模型中的每个相关EntityReference节点都必须替换为Entity内容的克隆,然后必须对每个克隆进行所需的更改。Entity节点及其所有子节点都是只读的。
Entity节点没有任何父节点。
注意:如果实体包含未绑定的命名空间前缀,Entity节点子树中对应节点的namespaceURInull。使用Document接口的createEntityReference方法创建引用此实体的EntityReference节点时,情况也是如此。
另见Document Object Model (DOM) Level 3 Core Specification

代码示例

代码示例来源:origin: plutext/docx4j

DocumentType docType = node.getOwnerDocument().getDoctype();
if (docType != null) {
  NamedNodeMap entities = docType.getEntities();
  for (int i = 0; i < entities.getLength(); i++) {
    Entity ent = (Entity) entities.item(i);
        : node.getNamespaceURI();
    String entName =
      ent.getNodeName() == null ? "" : ent.getNodeName();
    String entNamespaceURI =
      ent.getNamespaceURI() == null ? "" : ent.getNamespaceURI();
        && entName.equals(nodeName)) {
        if (ent.getNotationName() != null) {
          String msg =
            Utils.messages.createMessage(
        && entName.equals(nodeName)) {
        if (ent.getPublicId() != null
          || ent.getSystemId() != null
          || ent.getNotationName() != null) {
          String msg =
            Utils.messages.createMessage(

代码示例来源:origin: xalan/xalan

DocumentType doctype = _document.getDoctype();
if (doctype != null) {
  NamedNodeMap entities = doctype.getEntities();
  Entity entity = (Entity) entities.getNamedItem(name);
  String notationName = entity.getNotationName();
  if (notationName != null) {
    uri = entity.getSystemId();
    if (uri == null) {
      uri = entity.getPublicId();

代码示例来源:origin: com.sun.xml.bind/jaxb-extra-osgi

private void _handleEntities(DocumentType documenttype) {
  try {
    NamedNodeMap namednodemap = documenttype.getEntities();
    int i = namednodemap.getLength();
    for(int j = 0; j < i; j++) {
      Entity entity = (Entity)namednodemap.item(j);
      String s = entity.getPublicId();
      String s1 = entity.getSystemId();
      String s2 = entity.getNotationName();
      if(s != null || s1 != null)
        _handleExternalEntity(entity.getNodeName(), s, s1, s2);
      else
        _handleInternalEntity(entity);
    }
    NamedNodeMap namednodemap1 = documenttype.getNotations();
    int k = namednodemap1.getLength();
    for(int l = 0; l < k; l++) {
      Notation notation = (Notation)namednodemap1.item(l);
      String s3 = notation.getPublicId();
      String s4 = notation.getSystemId();
      dtd_.notationDecl(notation.getNodeName(), s3, s4);
    }
  }
  catch(SAXException saxexception) {
    _errorReport(saxexception);
  }
}

代码示例来源:origin: com.rackspace.apache/xerces2-xsd11

public void doctypeDecl(DocumentType node) throws XNIException {
    DocumentType docType = fDocumentImpl.createDocumentType(node.getName(), node.getPublicId(), node.getSystemId());
    final String internalSubset = node.getInternalSubset();
    NamedNodeMap oldMap = node.getEntities();
    NamedNodeMap newMap = docType.getEntities();
    int length = oldMap.getLength();
    for (int i = 0; i < length; ++i) {
      Entity oldEntity = (Entity) oldMap.item(i);
      EntityImpl newEntity = (EntityImpl) fDocumentImpl.createEntity(oldEntity.getNodeName());
      newEntity.setPublicId(oldEntity.getPublicId());
      newEntity.setSystemId(oldEntity.getSystemId());
      newEntity.setNotationName(oldEntity.getNotationName());
      newMap.setNamedItem(newEntity);

代码示例来源:origin: com.rackspace.apache/xerces2-xsd11

case ELEMENT_NODE: {
  Element newElement;
  boolean domLevel20 = source.getOwnerDocument().getImplementation().hasFeature("XML", "2.0");
    int length = sourceAttrs.getLength();
    for (int index = 0; index < length; index++) {
      Attr attr = (Attr)sourceAttrs.item(index);
  if( source.getOwnerDocument().getImplementation().hasFeature("XML", "2.0") ){
    if (source.getLocalName() == null) {
      newnode = createAttribute(source.getNodeName());
  EntityImpl newentity =
  (EntityImpl)createEntity(source.getNodeName());
  newentity.setPublicId(srcentity.getPublicId());
  newentity.setSystemId(srcentity.getSystemId());
  newentity.setNotationName(srcentity.getNotationName());
  createDocumentType(srcdoctype.getNodeName(),
  srcdoctype.getPublicId(),
  srcdoctype.getSystemId());
  newdoctype.setInternalSubset(srcdoctype.getInternalSubset());
  NamedNodeMap tmap = newdoctype.getEntities();
  if(smap != null) {
    for(int i = 0; i < smap.getLength(); i++) {
      tmap.setNamedItem(importNode(smap.item(i), true, true,
      reversedIdentifiers));

代码示例来源:origin: net.sf.saxon/Saxon-HE

Node node = ((DOMNodeWrapper) getRootNode()).node;
if (node instanceof Document) {
  DocumentType docType = ((Document) node).getDoctype();
  if (docType == null) {
    List<String> ls = Collections.emptyList();
    return ls.iterator();
  NamedNodeMap map = docType.getEntities();
  if (map == null) {
    List<String> ls = Collections.emptyList();
    return ls.iterator();
  List<String> names = new ArrayList<>(map.getLength());
  for (int i = 0; i < map.getLength(); i++) {
    Entity e = (Entity) map.item(i);
    if (e.getNotationName() != null) {
      names.add(e.getLocalName());

代码示例来源:origin: com.google.code.maven-play-plugin.org.allcolor.yahp/yahp-internal

DocumentType dc = (DocumentType) node;
if ((dc.getPublicId() != null) && (dc.getSystemId() != null)) {
  out.println(
    "<!DOCTYPE " + dc.getName() + " PUBLIC \""
    + dc.getPublicId() + "\" \"" + dc.getSystemId() + "\">"
  );
  NamedNodeMap nnm = dc.getEntities();
  for (int i = (nnm.getLength() - 1); i >= 0; i--) {
    if (i == (nnm.getLength() - 1))
      out.print(" ");
    Entity ent = (Entity) nnm.item(i);
    if (ent.getNotationName() != null) {
      entityDecl =
        "<!ENTITY " + ent.getNodeName() + " '"
        + ent.getNotationName() + "'>\n";

代码示例来源:origin: org.vx68k.quercus/quercus

sb.append(node.getName());
sb.append(node.getSystemId());
sb.append('"');
NamedNodeMap entities = node.getEntities();
if (entities != null && entities.getLength() > 0) {
 sb.append(' ');
 sb.append('[');
 sb.append('\n');
 for (int i = 0; i < entities.getLength(); i++) {
  Entity entity = (Entity) entities.item(i);
  sb.append(entity.getNodeName());
  sb.append(entity.getTextContent());
  sb.append('"');

代码示例来源:origin: org.icefaces/icefaces

buffer.append("; attributes: ");
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
  Attr attr = (Attr) attributes.item(i);
  buffer.append(attr.getName());
  buffer.append("=");
return "entity[public: " + entity.getPublicId() + "; system: " + entity.getSystemId() + "]";

代码示例来源:origin: com.sun.xml.bind/jaxb-extra-osgi

public boolean isParsedEntity(EntityReference entityreference) {
  String s = entityreference.getNodeName();
  Document document = entityreference.getOwnerDocument();
  DocumentType documenttype = document.getDoctype();
  if(documenttype == null)
    return false;
  NamedNodeMap namednodemap = documenttype.getEntities();
  Entity entity = (Entity)namednodemap.getNamedItem(s);
  if(entity == null)
    return false;
  else
    return entity.getNotationName() == null;
}

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

doc = (Document) load("staffNS", true);
   aNewDoc = (Document) load("staffNS", true);
   docType = aNewDoc.getDoctype();
   entityList = docType.getEntities();
   assertNotNull("entitiesNotNull", entityList);
   entity2 = (Entity) entityList.getNamedItem("ent6");
   entity1 = (Entity) doc.importNode(entity2, false);
   ownerDocument = entity1.getOwnerDocument();
   docType = ownerDocument.getDoctype();
   system = docType.getSystemId();
   assertURIEquals("dtdSystemId", null, null, null, "staffNS.dtd", null, null, null, null, system);
entityName = entity1.getNodeName();
   assertEquals("entityName", "ent6", entityName);
   publicVal = entity1.getPublicId();
   assertEquals("entityPublicId", "uri", publicVal);
   system = entity1.getSystemId();
   assertURIEquals("entitySystemId", null, null, null, "file", null, null, null, null, system);
notationName = entity1.getNotationName();
   assertEquals("notationName", "notation2", notationName);

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

String notationNameImp;
doc = (Document) load("staffNS", true);
domImpl = doc.getImplementation();
docType = doc.getDoctype();
docImp = domImpl.createDocument("http://www.w3.org/DOM/Test", "a:b", docTypeNull);
nodeMap = docType.getEntities();
assertNotNull("entitiesNotNull", nodeMap);
entity2 = (Entity) nodeMap.getNamedItem("ent2");
entity6 = (Entity) nodeMap.getNamedItem("ent6");
entityImp2 = (Entity) docImp.importNode(entity2, false);
entityImp6 = (Entity) docImp.importNode(entity6, true);
nodeName = entity2.getNodeName();
nodeNameImp = entityImp2.getNodeName();
assertEquals("documentimportnode19_Ent2NodeName", nodeName, nodeNameImp);
nodeName = entity6.getNodeName();
nodeNameImp = entityImp6.getNodeName();
assertEquals("documentimportnode19_Ent6NodeName", nodeName, nodeNameImp);
systemId = entity2.getSystemId();
systemIdImp = entityImp2.getSystemId();
assertEquals("documentimportnode19_Ent2SystemId", systemId, systemIdImp);
systemId = entity6.getSystemId();
systemIdImp = entityImp6.getSystemId();
assertEquals("documentimportnode19_Ent6SystemId", systemId, systemIdImp);
notationName = entity2.getNotationName();
notationNameImp = entityImp2.getNotationName();
assertEquals("documentimportnode19_Ent2NotationName", notationName, notationNameImp);
notationName = entity6.getNotationName();
notationNameImp = entityImp6.getNotationName();
assertEquals("documentimportnode19_Ent6NotationName", notationName, notationNameImp);

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

doc = (Document) load("staffNS", true);
   aNewDoc = (Document) load("staffNS", true);
   doc1Type = aNewDoc.getDoctype();
   entityList = doc1Type.getEntities();
   assertNotNull("entitiesNotNull", entityList);
   entity2 = (Entity) entityList.getNamedItem("ent4");
   entity1 = (Entity) doc.importNode(entity2, true);
   ownerDocument = entity1.getOwnerDocument();
   docType = ownerDocument.getDoctype();
   system = docType.getSystemId();
   assertURIEquals("systemId", null, null, null, "staffNS.dtd", null, null, null, null, system);
entityName = entity1.getNodeName();
   assertEquals("entityName", "ent4", entityName);
   child = entity1.getFirstChild();
   assertNotNull("notnull", child);
   childName = child.getNodeName();

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

String piDataVal;
doc = (Document) load("staffNS", true);
domImpl = doc.getImplementation();
docType = doc.getDoctype();
docImp = domImpl.createDocument("http://www.w3.org/DOM/Test", "a:b", docTypeNull);
nodeMap = docType.getEntities();
entity4 = (Entity) nodeMap.getNamedItem("ent4");
entityImp4 = (Entity) docImp.importNode(entity4, true);
childList = entityImp4.getChildNodes();
element = (Element) childList.item(0);
elemchildList = element.getChildNodes();
cdata = (CharacterData) elemchildList.item(0);
pi = (ProcessingInstruction) childList.item(1);
ent4Name = entity4.getNodeName();
ent4ImpName = entityImp4.getNodeName();
cdataVal = cdata.getData();
piTargetVal = pi.getTarget();

代码示例来源:origin: com.sun.xml.parsers/jaxp-ri

public boolean isEntityUnparsed(String name) {
  if (fEntities != null) {
    Entity entity = (Entity) fEntities.getNamedItem(name);
    if (entity != null) {
      return (entity.getNotationName() != null);
    }
  }
  return false;
}

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

/**
* Runs the test case.
* @throws Throwable Any uncaught exception causes test to fail
*/
public void runTest() throws Throwable {
 Document doc;
 DocumentType docType;
 NamedNodeMap entityList;
 Entity entityNode;
 String entityName;
 doc = (Document) load("staff", false);
 docType = doc.getDoctype();
 assertNotNull("docTypeNotNull", docType);
 entityList = docType.getEntities();
 assertNotNull("entitiesNotNull", entityList);
 entityNode = (Entity) entityList.getNamedItem("ent1");
 entityName = entityNode.getNodeName();
 assertEquals("entityGetEntityNameAssert", "ent1", entityName);
 }
/**

代码示例来源:origin: org.apache.ws.commons.axiom/dom-testsuite

/**
* Runs the test case.
* @throws Throwable Any uncaught exception causes test to fail
*/
public void runTest() throws Throwable {
 Document doc;
 DOMConfiguration domConfig;
 DocumentType docType;
 NamedNodeMap entitiesMap;
 String nullNS = null;
 Entity entity;
 String entityName;
 boolean canSet;
 doc = (Document) load("hc_staff", false);
 domConfig = doc.getDomConfig();
 canSet = domConfig.canSetParameter("entities", Boolean.FALSE);
 assertTrue("domconfigurationcansetparameter03_1", canSet);
 doc.normalizeDocument();
 docType = doc.getDoctype();
 entitiesMap = docType.getEntities();
 entity = (Entity) entitiesMap.getNamedItemNS(nullNS, "epsilon");
 entityName = entity.getNodeName();
 assertEquals("domconfigurationcansetparameter03_2", "epsilon", entityName);
 }
/**

代码示例来源:origin: com.helger/ph-isorelax

public boolean enter (final Entity entity)
{
 final String name = entity.getNodeName ();
 final String pid = entity.getPublicId ();
 final String sid = entity.getSystemId ();
 final String notation = entity.getNotationName ();
 buffer_.append ("<!ENTITY ").append (name);
 if (sid != null)
 {
  if (pid != null)
   buffer_.append (" PUBLIC \"").append (pid).append ("\" \"").append (UXML.escapeSystemQuot (sid)).append ("\">");
  else
   buffer_.append (" SYSTEM \"").append (UXML.escapeSystemQuot (sid)).append ("\">");
  if (notation != null)
   buffer_.append (" NDATA ").append (notation).append (">");
 }
 else
 {
  buffer_.append (" \"");
  final XMLMaker entityMaker = new XMLMaker ();
  UDOMVisitor.traverseChildren (entity, entityMaker);
  buffer_.append (UXML.escapeEntityQuot (entityMaker.getText ())).append ("\"").append (">");
 }
 return false;
}

代码示例来源:origin: com.caucho/resin

QEntity newEntity = new QEntity(oldEntity.getNodeName(),
                oldEntity.getNodeValue(),
                oldEntity.getPublicId(),
                oldEntity.getSystemId());
newEntity._owner = this;
return newEntity;

代码示例来源:origin: org.glassfish.external/schema2beans

protected void write(Entity entity) throws java.io.IOException {
  out.write("<!ENTITY "+entity.getNodeName());
  /*
   We don't seem to be able to get any useful info out of the
   Entity object.
 
   out.write(" notation ");
   if (entity.getNotationName() != null)
   out.write(entity.getNotationName());
   out.write(" publicid ");
   if (entity.getPublicId() != null)
   out.write(entity.getPublicId());
   out.write(" systemid ");
   if (entity.getSystemId() != null)
   out.write(entity.getSystemId());
  */
  out.write(" UNKNOWN>");
}

相关文章