type、ref、baseのいずれかの属性を含むすべての子ノードを取得したいと思います。各属性の値は重要ではありません。属性が存在するかどうかを確認したいだけです。
これが私が今それをする方法です:
private void addRequiredNodeAndChildren(Node n) {
XPath xpath = XPathFactory.newInstance().newXPath();
String expression = "*//*[@base or @ref or @type]";
XPathExpression expr = xpath.compile(expression);
NodeList referList = (NodeList) expr.evaluate(n, XPathConstants.NODESET);
..
}
この式は正常に機能しますが、ある場合には、期待されるすべてのノードを取得できません。
<xs:complexType name="ListElement">
<xs:annotation>
<xs:documentation>
</xs:documentation>
</xs:annotation>
<xs:attribute name="transferMode" type="myprefix:dataTransferMode"
use="optional">
<xs:annotation>
<xs:documentation>Documentation for attribute
</xs:documentation>
</xs:annotation>
</xs:attribute>
</xs:complexType>
上記の式でノードを取得することを期待していますが、残念ながら取得できません。式をに変更します
//*[@base or @ref or @type]
どちらも役に立ちませんでした。その結果、属性の1つを持つXMLからすべてのノードを取得しましたが、指定されたノードnの子ノードのみを取得したいと思います。私も試しました
*//*[@base] or *//*[@ref] or *//*[@type]
表現としてですが、それもうまくいきませんでした。
誰かが私の問題を解決する方法を考えていますか?