| Explanation | Searches for nodes that match the conditions specified in XPath . |
| Call format | var list = node.SelectNodes( xpath ) |
| Return value | XmlNodeList object containing all the nodes that match the criteria |
| Arguments | String xpath | Specify the search conditions in XPath format. The following elements can be specified for XPath. | // name | Select the name element from the current child and descendant elements . | | ../name | Select the element with name from the children of the current parent element . | | name/* | Selects all child elements of the name element from the current child elements . | | name@id | Select the id attribute of the name element from the current child elements . Not supported in Mobile | | name[.="data"] | Select the name element with the value data from the current child elements . | | name [@id="data"] | Selects the name element with an id attribute of data from the current child elements . | | name [2] | Select the third name element from the current child elements . Index starts from 1 in AI Ver. | Added since Ver.4.1.2 from here--> Added support for searches that specify NodeType such as #text. <--Up to here |
| Exception | None |
| Example of use |
/*
SelectNodes("//CODE");
Finds the CODE element in the entire DOM tree.
SelectNodes("/DATA/USER_REC/USERNAME[.="tanaka"]");
Finds the element with the value tanaka in / DATA / USER_REC / USERNAME.
SelectNodes("//CODE/USER_REC[0]");
Search the entire DOM tree for the CODE element and select the beginning of its child USER_REC.
*/
var domimpl = new XmlDOMImplementation;
var res = session.Get("/test/sample.xml");
var xmldoc = domimpl.Load(res);
var list = xmldoc.DocumentElement.SelectNodes("//CODE");
for (var n in list) {
print(list.Item(n).NodeName, "\n");
}
|
| Related item | XmlNodeList class ,SelectSingleNode method |