当前位置: 首页>>代码示例>>Java>>正文


Java Document.getElementById方法代码示例

本文整理汇总了Java中org.w3c.dom.Document.getElementById方法的典型用法代码示例。如果您正苦于以下问题:Java Document.getElementById方法的具体用法?Java Document.getElementById怎么用?Java Document.getElementById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.w3c.dom.Document的用法示例。


在下文中一共展示了Document.getElementById方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dereference

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Dereference the given uri within the document of the given root element.
 * <p>
 * Currently this method only supports XPointer-ID-references and the special SignatureInfo-URI.
 *
 * @param uri  the uri to dereference
 * @param root the root node whose owner document is searched for dereferenciation
 * @return the dereferenced node
 * @throws RedactableXMLSignatureException if the given URI cannot be resolved or is not supported
 */
public static Node dereference(String uri, Node root) throws RedactableXMLSignatureException {
    if (uri == null || uri.length() == 0) {
        throw new RedactableXMLSignatureException("unsupported URI");
    } else if (isRootNodeXPointer(uri)) {
        return root;
    } else if (isIdXPointer(uri)) {
        Document doc = root.getOwnerDocument();
        String id = extractId(uri);
        Element element = doc.getElementById(id);
        if (element == null) {
            throw new RedactableXMLSignatureException("Cannot resolve element with ID " + id);
        }
        return element;
    } else if (isSignatureInfoURI(uri)) {
        return dereferenceSignatureInfo(root);
    }

    throw new RedactableXMLSignatureException("unsupported URI");
}
 
开发者ID:woefe,项目名称:xmlrss,代码行数:30,代码来源:Dereferencer.java

示例2: test

import org.w3c.dom.Document; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
    SAXParserFactory fac = SAXParserFactory.newInstance();
    fac.setNamespaceAware(true);
    SAXParser saxParser = fac.newSAXParser();

    StreamSource sr = new StreamSource(this.getClass().getResourceAsStream("SAX2DOMTest.xml"));
    InputSource is = SAXSource.sourceToInputSource(sr);
    RejectDoctypeSaxFilter rf = new RejectDoctypeSaxFilter(saxParser);
    SAXSource src = new SAXSource(rf, is);
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    DOMResult result = new DOMResult();
    transformer.transform(src, result);

    Document doc = (Document) result.getNode();
    System.out.println("Name" + doc.getDocumentElement().getLocalName());

    String id = "XWSSGID-11605791027261938254268";
    Element selement = doc.getElementById(id);
    if (selement == null) {
        System.out.println("getElementById returned null");
    }

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:SAX2DOMTest.java

示例3: getPointerByID

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Locates a node by ID.
 * @param context starting context
 * @param id to find
 * @return Pointer
 */
public Pointer getPointerByID(JXPathContext context, String id) {
    Document document = node.getNodeType() == Node.DOCUMENT_NODE ? (Document) node
            : node.getOwnerDocument();
    Element element = document.getElementById(id);
    return element == null ? (Pointer) new NullPointer(getLocale(), id)
            : new DOMNodePointer(element, getLocale(), id);
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:14,代码来源:DOMNodePointer.java

示例4: getElementById

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Returns the <code>Element</code> whose <code>ID</code> is given by
 * <code>elementId</code>. If no such element exists, returns
 * <code>DTM.NULL</code>. Behavior is not defined if more than one element
 * has this <code>ID</code>. Attributes (including those
 * with the name "ID") are not of type ID unless so defined by DTD/Schema
 * information available to the DTM implementation.
 * Implementations that do not know whether attributes are of type ID or
 * not are expected to return <code>DTM.NULL</code>.
 *
 * <p>%REVIEW% Presumably IDs are still scoped to a single document,
 * and this operation searches only within a single document, right?
 * Wouldn't want collisions between DTMs in the same process.</p>
 *
 * @param elementId The unique <code>id</code> value for an element.
 * @return The handle of the matching element.
 */
public int getElementById(String elementId)
{

  Document doc = (m_root.getNodeType() == Node.DOCUMENT_NODE)
      ? (Document) m_root : m_root.getOwnerDocument();

  if(null != doc)
  {
    Node elem = doc.getElementById(elementId);
    if(null != elem)
    {
      int elemHandle = getHandleFromNode(elem);

      if(DTM.NULL == elemHandle)
      {
        int identity = m_nodes.size()-1;
        while (DTM.NULL != (identity = getNextNodeIdentity(identity)))
        {
          Node node = getNode(identity);
          if(node == elem)
          {
            elemHandle = getHandleFromNode(elem);
            break;
          }
         }
      }

      return elemHandle;
    }

  }
  return DTM.NULL;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:51,代码来源:DOM2DTM.java

示例5: walkTree

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 * This method only visits the element which has the specified identifier.
 */
@Override
public void walkTree(Element start, Visitor visitor) {
    Document doc = start.getOwnerDocument();
    Element found = doc.getElementById(this.identifier);
    if (found == null) {
        return;
    }
    if (Elements.isRoot(start) || Elements.hasDescendant(start, found)) {
        visitor.visit(found);
    }
}
 
开发者ID:i49,项目名称:cascade,代码行数:16,代码来源:IdentifierWalker.java

示例6: Fixture

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Constructs this object.
 * 
 * @param doc the XML document.
 * @param startId the starting element to search.
 * @param expression the selector expression.
 * @param teacher the object to supply expected values.
 */
public Fixture(Document doc, String startId, String expression, Function<Element, List<Element>> teacher) {
    if (startId != null) {
        this.startElement = doc.getElementById(startId.substring(1));
    } else {
        this.startElement = doc.getDocumentElement();
    }
    this.expression = expression;
    this.expected = teacher.apply(this.startElement);
}
 
开发者ID:i49,项目名称:cascade,代码行数:18,代码来源:Fixture.java

示例7: getElementById

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Method getElementById
 *
 * @param doc the document
 * @param id the value of the ID
 * @return the element obtained by the id, or null if it is not found.
 */
public static Element getElementById(Document doc, String id) {
    return doc.getElementById(id);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:IdResolver.java

示例8: getElementByID

import org.w3c.dom.Document; //导入方法依赖的package包/类
/**
 * Given an XML ID, return the element. This requires assistance from the
 * DOM and parser, and is meaningful only in the context of a DTD
 * or schema which declares attributes as being of type ID. This
 * information may or may not be available in all parsers, may or
 * may not be available for specific documents, and may or may not
 * be available when validation is not turned on.
 *
 * @param id The ID to search for, as a String.
 * @param doc The document to search within, as a DOM Document node.
 * @return DOM Element node with an attribute of type ID whose value
 * uniquely matches the requested id string, or null if there isn't
 * such an element or if the DOM can't answer the question for other
 * reasons.
 */
public Element getElementByID(String id, Document doc)
{
  return doc.getElementById(id);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:DOM2Helper.java


注:本文中的org.w3c.dom.Document.getElementById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。