VOOZH about

URL: https://qiita.com/KevinFQ/items/c03248ca8338cf6e26f1

⇱ xpathに関するメモ書き #Java - Qiita


👁 Image
2

Go to list of users who liked

2

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@KevinFQ

xpathに関するメモ書き

2
Posted at

xpathに関するメモ書きです。

ローケーションパス

👁 名称未設定.png

👁 名称未設定 2.png

関数

👁 名称未設定 4.png

👁 名称未設定 3.png

サンプル

import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

// 指定ノードの取得(名前空間無視)
Node targetNode = (Node)xpath.evaluate("//*[local-name()='ProductID']", doc, XPathConstants.NODE);
			
// 指定ノードの取得(名前空間有効)
Node targetNodeWithNS = (Node)xpath.evaluate("//*[local-name()='ProductID' and namespace-uri()='nms:xml.go.jp:schema']", doc, XPathConstants.NODE);
			
// 指定ノードの子ノードリスト
NodeList childNodeList = (NodeList)xpath.evaluate("child::node()", targetNode1, XPathConstants.NODESET);

// 指定ノードの子ノードリスト(簡易表記)
NodeList childNodeList_simple = (NodeList)xpath.evaluate("./node()", targetNode1, XPathConstants.NODESET);

// 指定ノードの親ノード
NodeList childNodeList = (NodeList)xpath.evaluate("parent::node()", targetNode1, XPathConstants.NODESET);

// 指定ノードの親ノード(簡易表記)
NodeList simpleChildNodeList = (NodeList)xpath.evaluate("..", targetNode1, XPathConstants.NODESET);
			
// 祖先ノードリストの取得
NodeList ancestorList = (NodeList)xpath.evaluate("ancestor::node()", targetNode1, XPathConstants.NODESET);
2

Go to list of users who liked

2
0

Go to list of comments

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2

Go to list of users who liked

2