0

我正在尝试编写一个 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());

在这种情况下,变量 line 将是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>

4

1 回答 1

0

我想你想要的是

//Entity[matches(Name,'TciProfile') and .//Operation/Name='create']

在 Oxygen/XML 中测试,这将返回满足两个条件的实体节点

于 2013-01-23T06:48:50.763 回答