我正在尝试编写一个xpath表达式,用于检查实体是否支持“create”操作。 这是我正在使用的代码:
在这种情况下,字符串行将具有不带下划线的实体名称,如“TciProfile”。
while ((line = br.readLine()) != null) {
System.out.println("entity name: "+line);
XPathFactory factory = XPathFactory.newInstance();
XPath xpath1 = factory.newXPath();
XPathExpression expr = xpath1.compile("//Entity[matches(Name,'" +line+ "') and .//Operation/Name='create']");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList res = (NodeList) result;
System.out.println("NodeList size: " + res.getLength());
在这种情况下,变量行为TciProfile
。
但是这个表达式在评估时重新运行null
值。
有人能告诉我这里我做错了什么吗?
<Entity>
<Name>TCI_Profile|TciProfile</Name>
<AttributeList>
<Attribute>
<Name>Tci_Profile_Id|tciProfileId</Name>
<Type>string|string</Type>
<Range>0-23</Range>
<Default>null</Default>
</Attribute>
<Attribute>
<Name>Description|description</Name>
<Type>string|string</Type>
<Range>0-199</Range>
<Default>null</Default>
</Attribute>
</AttributeList>
<KeyAttributeNameList>
<Name>Tci_Profile_Id|tciProfileId</Name>
</KeyAttributeNameList>
<OperationList>
<Operation>
<Name>show|retrieve</Name>
<RequestAttributeList>
<RequestAttribute>
<Name>Tci_Profile_Id|tciProfileId</Name>
<Flag>required</Flag>
</RequestAttribute>
</RequestAttributeList>
<ResponseAttributeNameList>
<Name>Tci_Profile_Id|tciProfileId</Name>
<Name>Description|description</Name>
</ResponseAttributeNameList>
</Operation>
<Operation>
<Name>create</Name>
<RequestAttributeList>
<RequestAttribute>
<Name>Tci_Profile_Id|tciProfileId</Name>
<Flag>required</Flag>
</RequestAttribute>
<RequestAttribute>
<Name>Description|description</Name>
<Flag>required</Flag>
</RequestAttribute>
</RequestAttributeList>
<ResponseAttributeNameList>
</ResponseAttributeNameList>
</Operation>
<Operation>
<Name>find|getNextItems</Name>
<RequestAttributeList>
<RequestAttribute>
<Name>Tci_Profile_Id|tciProfileId</Name>
<Flag>optional/searchable</Flag>
</RequestAttribute>
</RequestAttributeList>
<ResponseAttributeNameList>
<Name>Tci_Profile_Id|tciProfileId</Name>
</ResponseAttributeNameList>
</Operation>
<Operation>
<Name>delete</Name>
<RequestAttributeList>
<RequestAttribute>
<Name>Tci_Profile_Id|tciProfileId</Name>
<Flag>required</Flag>
</RequestAttribute>
</RequestAttributeList>
<ResponseAttributeNameList>
</ResponseAttributeNameList>
</Operation>
<Operation>
<Name>put</Name>
<RequestAttributeList>
<RequestAttribute>
<Name>Tci_Profile_Id|tciProfileId</Name>
<Flag>required</Flag>
</RequestAttribute>
<RequestAttribute>
<Name>Description|description</Name>
<Flag>required</Flag>
</RequestAttribute>
</RequestAttributeList>
<ResponseAttributeNameList>
</ResponseAttributeNameList>
</Operation>
<Operation>
<Name>update</Name>
<RequestAttributeList>
<RequestAttribute>
<Name>Tci_Profile_Id|tciProfileId</Name>
<Flag>required</Flag>
</RequestAttribute>
<RequestAttribute>
<Name>Description|description</Name>
<Flag>required</Flag>
</RequestAttribute>
</RequestAttributeList>
<ResponseAttributeNameList>
</ResponseAttributeNameList>
</Operation>
</OperationList>
答案 0 :(得分:0)
我认为你想要的是
//Entity[matches(Name,'TciProfile') and .//Operation/Name='create']
在Oxygen / XML中测试,它返回满足两个条件的实体节点