我想写一个检查实体是否支持“创建”操作的xpath表达式。 这是我正在使用的代码:xpath表达式来选择具有特定字符串作为文本的父节点的子节点
在这种情况下,字符串行的实体名称不带下划线,如'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>
这不开始由于缺少引号而编译......请发布_real_代码。 –