java xml dom getelementbyid_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

​點讚 3

import org.w3c.dom.Document; //導入方法依賴的package包/類

/**

* Dereference the given uri within the document of the given root element.

*

* 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,

示例2: test

​點讚 3

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,

示例3: getPointerByID

​點讚 2

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,

示例4: getElementById

​點讚 2

import org.w3c.dom.Document; //導入方法依賴的package包/類

/**

* Returns the Element whose ID is given by

* elementId. If no such element exists, returns

* DTM.NULL. Behavior is not defined if more than one element

* has this ID. 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 DTM.NULL.

*

*

%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.

*

* @param elementId The unique id 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,

示例5: walkTree

​點讚 2

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,

示例6: Fixture

​點讚 2

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> 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,

示例7: getElementById

​點讚 1

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,

示例8: getElementByID

​點讚 1

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,

注:本文中的org.w3c.dom.Document.getElementById方法示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值